| Box2D 2.2.1 A 2D Physics Engine for Games

- Main Page
- Classes
- Files

- File List
- File Members

b2RevoluteJoint.h

    00001 /*
    00002 * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
    00003 *
    00004 * This software is provided 'as-is', without any express or implied
    00005 * warranty.  In no event will the authors be held liable for any damages
    00006 * arising from the use of this software.
    00007 * Permission is granted to anyone to use this software for any purpose,
    00008 * including commercial applications, and to alter it and redistribute it
    00009 * freely, subject to the following restrictions:
    00010 * 1. The origin of this software must not be misrepresented; you must not
    00011 * claim that you wrote the original software. If you use this software
    00012 * in a product, an acknowledgment in the product documentation would be
    00013 * appreciated but is not required.
    00014 * 2. Altered source versions must be plainly marked as such, and must not be
    00015 * misrepresented as being the original software.
    00016 * 3. This notice may not be removed or altered from any source distribution.
    00017 */
    00018
    00019 #ifndef B2_REVOLUTE_JOINT_H
    00020 #define B2_REVOLUTE_JOINT_H
    00021
    00022 #include <Box2D/Dynamics/Joints/b2Joint.h>
    00023
    00035 struct b2RevoluteJointDef : public b2JointDef
    00036 {
    00037         b2RevoluteJointDef()
    00038         {
    00039                 type = e_revoluteJoint;
    00040                 localAnchorA.Set(0.0f, 0.0f);
    00041                 localAnchorB.Set(0.0f, 0.0f);
    00042                 referenceAngle = 0.0f;
    00043                 lowerAngle = 0.0f;
    00044                 upperAngle = 0.0f;
    00045                 maxMotorTorque = 0.0f;
    00046                 motorSpeed = 0.0f;
    00047                 enableLimit = false;
    00048                 enableMotor = false;
    00049         }
    00050
    00053         void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor);
    00054
    00056         b2Vec2 localAnchorA;
    00057
    00059         b2Vec2 localAnchorB;
    00060
    00062         float32 referenceAngle;
    00063
    00065         bool enableLimit;
    00066
    00068         float32 lowerAngle;
    00069
    00071         float32 upperAngle;
    00072
    00074         bool enableMotor;
    00075
    00077         float32 motorSpeed;
    00078
    00081         float32 maxMotorTorque;
    00082 };
    00083
    00090 class b2RevoluteJoint : public b2Joint
    00091 {
    00092 public:
    00093         b2Vec2 GetAnchorA() const;
    00094         b2Vec2 GetAnchorB() const;
    00095
    00097         const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
    00098
    00100         const b2Vec2& GetLocalAnchorB() const  { return m_localAnchorB; }
    00101
    00103         float32 GetReferenceAngle() const { return m_referenceAngle; }
    00104
    00106         float32 GetJointAngle() const;
    00107
    00109         float32 GetJointSpeed() const;
    00110
    00112         bool IsLimitEnabled() const;
    00113
    00115         void EnableLimit(bool flag);
    00116
    00118         float32 GetLowerLimit() const;
    00119
    00121         float32 GetUpperLimit() const;
    00122
    00124         void SetLimits(float32 lower, float32 upper);
    00125
    00127         bool IsMotorEnabled() const;
    00128
    00130         void EnableMotor(bool flag);
    00131
    00133         void SetMotorSpeed(float32 speed);
    00134
    00136         float32 GetMotorSpeed() const;
    00137
    00139         void SetMaxMotorTorque(float32 torque);
    00140         float32 GetMaxMotorTorque() const { return m_maxMotorTorque; }
    00141
    00144         b2Vec2 GetReactionForce(float32 inv_dt) const;
    00145
    00148         float32 GetReactionTorque(float32 inv_dt) const;
    00149
    00152         float32 GetMotorTorque(float32 inv_dt) const;
    00153
    00155         void Dump();
    00156
    00157 protected:
    00158
    00159         friend class b2Joint;
    00160         friend class b2GearJoint;
    00161
    00162         b2RevoluteJoint(const b2RevoluteJointDef* def);
    00163
    00164         void InitVelocityConstraints(const b2SolverData& data);
    00165         void SolveVelocityConstraints(const b2SolverData& data);
    00166         bool SolvePositionConstraints(const b2SolverData& data);
    00167
    00168         // Solver shared
    00169         b2Vec2 m_localAnchorA;
    00170         b2Vec2 m_localAnchorB;
    00171         b2Vec3 m_impulse;
    00172         float32 m_motorImpulse;
    00173
    00174         bool m_enableMotor;
    00175         float32 m_maxMotorTorque;
    00176         float32 m_motorSpeed;
    00177
    00178         bool m_enableLimit;
    00179         float32 m_referenceAngle;
    00180         float32 m_lowerAngle;
    00181         float32 m_upperAngle;
    00182
    00183         // Solver temp
    00184         int32 m_indexA;
    00185         int32 m_indexB;
    00186         b2Vec2 m_rA;
    00187         b2Vec2 m_rB;
    00188         b2Vec2 m_localCenterA;
    00189         b2Vec2 m_localCenterB;
    00190         float32 m_invMassA;
    00191         float32 m_invMassB;
    00192         float32 m_invIA;
    00193         float32 m_invIB;
    00194         b2Mat33 m_mass;                 // effective mass for point-to-point constraint.
    00195         float32 m_motorMass;    // effective mass for motor/limit angular constraint.
    00196         b2LimitState m_limitState;
    00197 };
    00198
    00199 inline float32 b2RevoluteJoint::GetMotorSpeed() const
    00200 {
    00201         return m_motorSpeed;
    00202 }
    00203
    00204 #endif

All Classes Files Functions Variables Enumerations Enumerator Defines