Box2D  2.2.0
A 2D Physics Engine for Games
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         float32 GetJointAngle() const;
00098 
00100         float32 GetJointSpeed() const;
00101 
00103         bool IsLimitEnabled() const;
00104 
00106         void EnableLimit(bool flag);
00107 
00109         float32 GetLowerLimit() const;
00110 
00112         float32 GetUpperLimit() const;
00113 
00115         void SetLimits(float32 lower, float32 upper);
00116 
00118         bool IsMotorEnabled() const;
00119 
00121         void EnableMotor(bool flag);
00122 
00124         void SetMotorSpeed(float32 speed);
00125 
00127         float32 GetMotorSpeed() const;
00128 
00130         void SetMaxMotorTorque(float32 torque);
00131 
00134         b2Vec2 GetReactionForce(float32 inv_dt) const;
00135 
00138         float32 GetReactionTorque(float32 inv_dt) const;
00139 
00142         float32 GetMotorTorque(float32 inv_dt) const;
00143 
00144 protected:
00145         
00146         friend class b2Joint;
00147         friend class b2GearJoint;
00148 
00149         b2RevoluteJoint(const b2RevoluteJointDef* def);
00150 
00151         void InitVelocityConstraints(const b2SolverData& data);
00152         void SolveVelocityConstraints(const b2SolverData& data);
00153         bool SolvePositionConstraints(const b2SolverData& data);
00154 
00155         // Solver shared
00156         b2Vec2 m_localAnchorA;
00157         b2Vec2 m_localAnchorB;
00158         b2Vec3 m_impulse;
00159         float32 m_motorImpulse;
00160 
00161         bool m_enableMotor;
00162         float32 m_maxMotorTorque;
00163         float32 m_motorSpeed;
00164 
00165         bool m_enableLimit;
00166         float32 m_referenceAngle;
00167         float32 m_lowerAngle;
00168         float32 m_upperAngle;
00169 
00170         // Solver temp
00171         int32 m_indexA;
00172         int32 m_indexB;
00173         b2Vec2 m_rA;
00174         b2Vec2 m_rB;
00175         b2Vec2 m_localCenterA;
00176         b2Vec2 m_localCenterB;
00177         float32 m_invMassA;
00178         float32 m_invMassB;
00179         float32 m_invIA;
00180         float32 m_invIB;
00181         b2Mat33 m_mass;                 // effective mass for point-to-point constraint.
00182         float32 m_motorMass;    // effective mass for motor/limit angular constraint.
00183         b2LimitState m_limitState;
00184 };
00185 
00186 inline float32 b2RevoluteJoint::GetMotorSpeed() const
00187 {
00188         return m_motorSpeed;
00189 }
00190 
00191 #endif
 All Classes Files Functions Variables Enumerations Enumerator Defines