Box2D  2.3.0
A 2D Physics Engine for Games
b2RopeJoint.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_ROPE_JOINT_H
20 #define B2_ROPE_JOINT_H
21 
22 #include <Box2D/Dynamics/Joints/b2Joint.h>
23 
28 struct b2RopeJointDef : public b2JointDef
29 {
31  {
32  type = e_ropeJoint;
33  localAnchorA.Set(-1.0f, 0.0f);
34  localAnchorB.Set(1.0f, 0.0f);
35  maxLength = 0.0f;
36  }
37 
40 
43 
47  float32 maxLength;
48 };
49 
58 class b2RopeJoint : public b2Joint
59 {
60 public:
61  b2Vec2 GetAnchorA() const;
62  b2Vec2 GetAnchorB() const;
63 
64  b2Vec2 GetReactionForce(float32 inv_dt) const;
65  float32 GetReactionTorque(float32 inv_dt) const;
66 
68  const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
69 
71  const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
72 
74  void SetMaxLength(float32 length) { m_maxLength = length; }
75  float32 GetMaxLength() const;
76 
77  b2LimitState GetLimitState() const;
78 
80  void Dump();
81 
82 protected:
83 
84  friend class b2Joint;
85  b2RopeJoint(const b2RopeJointDef* data);
86 
87  void InitVelocityConstraints(const b2SolverData& data);
88  void SolveVelocityConstraints(const b2SolverData& data);
89  bool SolvePositionConstraints(const b2SolverData& data);
90 
91  // Solver shared
92  b2Vec2 m_localAnchorA;
93  b2Vec2 m_localAnchorB;
94  float32 m_maxLength;
95  float32 m_length;
96  float32 m_impulse;
97 
98  // Solver temp
99  int32 m_indexA;
100  int32 m_indexB;
101  b2Vec2 m_u;
102  b2Vec2 m_rA;
103  b2Vec2 m_rB;
104  b2Vec2 m_localCenterA;
105  b2Vec2 m_localCenterB;
106  float32 m_invMassA;
107  float32 m_invMassB;
108  float32 m_invIA;
109  float32 m_invIB;
110  float32 m_mass;
111  b2LimitState m_state;
112 };
113 
114 #endif