Box2D  2.3.0
A 2D Physics Engine for Games
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