LiquidFun
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
b2PulleyJoint.h
1 /*
2 * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18 
19 #ifndef B2_PULLEY_JOINT_H
20 #define B2_PULLEY_JOINT_H
21 
22 #include <Box2D/Dynamics/Joints/b2Joint.h>
23 
24 const float32 b2_minPulleyLength = 2.0f;
25 
29 {
31  {
32  type = e_pulleyJoint;
33  groundAnchorA.Set(-1.0f, 1.0f);
34  groundAnchorB.Set(1.0f, 1.0f);
35  localAnchorA.Set(-1.0f, 0.0f);
36  localAnchorB.Set(1.0f, 0.0f);
37  lengthA = 0.0f;
38  lengthB = 0.0f;
39  ratio = 1.0f;
40  collideConnected = true;
41  }
42 
46  const b2Vec2& anchorA, const b2Vec2& anchorB,
47  float32 ratio);
48 
51 
54 
57 
60 
62  float32 lengthA;
63 
65  float32 lengthB;
66 
68  float32 ratio;
69 };
70 
79 class b2PulleyJoint : public b2Joint
80 {
81 public:
82  b2Vec2 GetAnchorA() const;
83  b2Vec2 GetAnchorB() const;
84 
85  b2Vec2 GetReactionForce(float32 inv_dt) const;
86  float32 GetReactionTorque(float32 inv_dt) const;
87 
89  b2Vec2 GetGroundAnchorA() const;
90 
92  b2Vec2 GetGroundAnchorB() const;
93 
95  float32 GetLengthA() const;
96 
98  float32 GetLengthB() const;
99 
101  float32 GetRatio() const;
102 
104  float32 GetCurrentLengthA() const;
105 
107  float32 GetCurrentLengthB() const;
108 
110  void Dump();
111 
113  void ShiftOrigin(const b2Vec2& newOrigin);
114 
115 protected:
116 
117  friend class b2Joint;
118  b2PulleyJoint(const b2PulleyJointDef* data);
119 
120  void InitVelocityConstraints(const b2SolverData& data);
121  void SolveVelocityConstraints(const b2SolverData& data);
122  bool SolvePositionConstraints(const b2SolverData& data);
123 
124  b2Vec2 m_groundAnchorA;
125  b2Vec2 m_groundAnchorB;
126  float32 m_lengthA;
127  float32 m_lengthB;
128 
129  // Solver shared
130  b2Vec2 m_localAnchorA;
131  b2Vec2 m_localAnchorB;
132  float32 m_constant;
133  float32 m_ratio;
134  float32 m_impulse;
135 
136  // Solver temp
137  int32 m_indexA;
138  int32 m_indexB;
139  b2Vec2 m_uA;
140  b2Vec2 m_uB;
141  b2Vec2 m_rA;
142  b2Vec2 m_rB;
143  b2Vec2 m_localCenterA;
144  b2Vec2 m_localCenterB;
145  float32 m_invMassA;
146  float32 m_invMassB;
147  float32 m_invIA;
148  float32 m_invIB;
149  float32 m_mass;
150 };
151 
152 #endif
float32 GetReactionTorque(float32 inv_dt) const
Get the reaction torque on bodyB in N*m.
Definition: b2PulleyJoint.cpp:278
b2Vec2 GetAnchorB() const
Get the anchor point on bodyB in world coordinates.
Definition: b2PulleyJoint.cpp:267
b2Body * bodyA
The first attached body.
Definition: b2Joint.h:92
b2Vec2 GetGroundAnchorA() const
Get the first ground anchor.
Definition: b2PulleyJoint.cpp:284
float32 GetCurrentLengthA() const
Get the current length of the segment attached to bodyA.
Definition: b2PulleyJoint.cpp:309
float32 GetLengthA() const
Get the current length of the segment attached to bodyA.
Definition: b2PulleyJoint.cpp:294
b2Body * bodyB
The second attached body.
Definition: b2Joint.h:95
float32 lengthB
The a reference length for the segment attached to bodyB.
Definition: b2PulleyJoint.h:65
void ShiftOrigin(const b2Vec2 &newOrigin)
Implement b2Joint::ShiftOrigin.
Definition: b2PulleyJoint.cpp:344
Definition: b2Joint.h:103
float32 GetRatio() const
Get the pulley ratio.
Definition: b2PulleyJoint.cpp:304
float32 GetCurrentLengthB() const
Get the current length of the segment attached to bodyB.
Definition: b2PulleyJoint.cpp:317
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates.
Definition: b2Math.h:68
float32 ratio
The pulley ratio, used to simulate a block-and-tackle.
Definition: b2PulleyJoint.h:68
void Dump()
Dump joint to dmLog.
Definition: b2PulleyJoint.cpp:325
b2Vec2 GetGroundAnchorB() const
Get the second ground anchor.
Definition: b2PulleyJoint.cpp:289
b2JointType type
The joint type is set automatically for concrete joint types.
Definition: b2Joint.h:86
bool collideConnected
Set this flag to true if the attached bodies should collide.
Definition: b2Joint.h:98
b2Vec2 GetReactionForce(float32 inv_dt) const
Get the reaction force on bodyB at the joint anchor in Newtons.
Definition: b2PulleyJoint.cpp:272
Solver Data.
Definition: b2TimeStep.h:65
Joint definitions are used to construct joints.
Definition: b2Joint.h:74
Definition: b2PulleyJoint.h:28
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:132
b2Vec2 groundAnchorA
The first ground anchor in world coordinates. This point never moves.
Definition: b2PulleyJoint.h:50
float32 GetLengthB() const
Get the current length of the segment attached to bodyB.
Definition: b2PulleyJoint.cpp:299
float32 lengthA
The a reference length for the segment attached to bodyA.
Definition: b2PulleyJoint.h:62
A 2D column vector.
Definition: b2Math.h:56
b2Vec2 GetAnchorA() const
Get the anchor point on bodyA in world coordinates.
Definition: b2PulleyJoint.cpp:262
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
Definition: b2PulleyJoint.h:59
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
Definition: b2PulleyJoint.h:56
Definition: b2PulleyJoint.h:79
void Initialize(b2Body *bodyA, b2Body *bodyB, const b2Vec2 &groundAnchorA, const b2Vec2 &groundAnchorB, const b2Vec2 &anchorA, const b2Vec2 &anchorB, float32 ratio)
Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors.
Definition: b2PulleyJoint.cpp:35
b2Vec2 groundAnchorB
The second ground anchor in world coordinates. This point never moves.
Definition: b2PulleyJoint.h:53