00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef B2_PULLEY_JOINT_H
00020 #define B2_PULLEY_JOINT_H
00021
00022 #include <Box2D/Dynamics/Joints/b2Joint.h>
00023
00024 const float32 b2_minPulleyLength = 2.0f;
00025
00029 struct b2PulleyJointDef : public b2JointDef
00030 {
00031 b2PulleyJointDef()
00032 {
00033 type = e_pulleyJoint;
00034 groundAnchorA.Set(-1.0f, 1.0f);
00035 groundAnchorB.Set(1.0f, 1.0f);
00036 localAnchorA.Set(-1.0f, 0.0f);
00037 localAnchorB.Set(1.0f, 0.0f);
00038 lengthA = 0.0f;
00039 maxLengthA = 0.0f;
00040 lengthB = 0.0f;
00041 maxLengthB = 0.0f;
00042 ratio = 1.0f;
00043 collideConnected = true;
00044 }
00045
00047 void Initialize(b2Body* bodyA, b2Body* bodyB,
00048 const b2Vec2& groundAnchorA, const b2Vec2& groundAnchorB,
00049 const b2Vec2& anchorA, const b2Vec2& anchorB,
00050 float32 ratio);
00051
00053 b2Vec2 groundAnchorA;
00054
00056 b2Vec2 groundAnchorB;
00057
00059 b2Vec2 localAnchorA;
00060
00062 b2Vec2 localAnchorB;
00063
00065 float32 lengthA;
00066
00068 float32 maxLengthA;
00069
00071 float32 lengthB;
00072
00074 float32 maxLengthB;
00075
00077 float32 ratio;
00078 };
00079
00086 class b2PulleyJoint : public b2Joint
00087 {
00088 public:
00089 b2Vec2 GetAnchorA() const;
00090 b2Vec2 GetAnchorB() const;
00091
00092 b2Vec2 GetReactionForce(float32 inv_dt) const;
00093 float32 GetReactionTorque(float32 inv_dt) const;
00094
00096 b2Vec2 GetGroundAnchorA() const;
00097
00099 b2Vec2 GetGroundAnchorB() const;
00100
00102 float32 GetLength1() const;
00103
00105 float32 GetLength2() const;
00106
00108 float32 GetRatio() const;
00109
00110 protected:
00111
00112 friend class b2Joint;
00113 b2PulleyJoint(const b2PulleyJointDef* data);
00114
00115 void InitVelocityConstraints(const b2TimeStep& step);
00116 void SolveVelocityConstraints(const b2TimeStep& step);
00117 bool SolvePositionConstraints(float32 baumgarte);
00118
00119 b2Vec2 m_groundAnchor1;
00120 b2Vec2 m_groundAnchor2;
00121 b2Vec2 m_localAnchor1;
00122 b2Vec2 m_localAnchor2;
00123
00124 b2Vec2 m_u1;
00125 b2Vec2 m_u2;
00126
00127 float32 m_constant;
00128 float32 m_ratio;
00129
00130 float32 m_maxLength1;
00131 float32 m_maxLength2;
00132
00133
00134 float32 m_pulleyMass;
00135 float32 m_limitMass1;
00136 float32 m_limitMass2;
00137
00138
00139 float32 m_impulse;
00140 float32 m_limitImpulse1;
00141 float32 m_limitImpulse2;
00142
00143 b2LimitState m_state;
00144 b2LimitState m_limitState1;
00145 b2LimitState m_limitState2;
00146 };
00147
00148 #endif