Box2D  2.4.0
A 2D physics engine for games
b2_rope_joint.h
1 // MIT License
2 
3 // Copyright (c) 2019 Erin Catto
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #ifndef B2_ROPE_JOINT_H
24 #define B2_ROPE_JOINT_H
25 
26 #include "b2_joint.h"
27 
32 struct b2RopeJointDef : public b2JointDef
33 {
35  {
36  type = e_ropeJoint;
37  localAnchorA.Set(-1.0f, 0.0f);
38  localAnchorB.Set(1.0f, 0.0f);
39  maxLength = 0.0f;
40  }
41 
44 
47 
51  float maxLength;
52 };
53 
62 class b2RopeJoint : public b2Joint
63 {
64 public:
65  b2Vec2 GetAnchorA() const override;
66  b2Vec2 GetAnchorB() const override;
67 
68  b2Vec2 GetReactionForce(float inv_dt) const override;
69  float GetReactionTorque(float inv_dt) const override;
70 
72  const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
73 
75  const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
76 
78  void SetMaxLength(float length) { m_maxLength = length; }
79  float GetMaxLength() const;
80 
81  // Get current length
82  float GetLength() const;
83 
85  void Dump() override;
86 
87 protected:
88 
89  friend class b2Joint;
90  b2RopeJoint(const b2RopeJointDef* data);
91 
92  void InitVelocityConstraints(const b2SolverData& data) override;
93  void SolveVelocityConstraints(const b2SolverData& data) override;
94  bool SolvePositionConstraints(const b2SolverData& data) override;
95 
96  // Solver shared
97  b2Vec2 m_localAnchorA;
98  b2Vec2 m_localAnchorB;
99  float m_maxLength;
100  float m_length;
101  float m_impulse;
102 
103  // Solver temp
104  int32 m_indexA;
105  int32 m_indexB;
106  b2Vec2 m_u;
107  b2Vec2 m_rA;
108  b2Vec2 m_rB;
109  b2Vec2 m_localCenterA;
110  b2Vec2 m_localCenterB;
111  float m_invMassA;
112  float m_invMassB;
113  float m_invIA;
114  float m_invIB;
115  float m_mass;
116 };
117 
118 #endif
b2Vec2
A 2D column vector.
Definition: b2_math.h:39
b2RopeJoint::GetReactionForce
b2Vec2 GetReactionForce(float inv_dt) const override
Get the reaction force on bodyB at the joint anchor in Newtons.
b2JointDef
Joint definitions are used to construct joints.
Definition: b2_joint.h:71
b2RopeJoint::GetLocalAnchorB
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB's origin.
Definition: b2_rope_joint.h:75
b2JointDef::type
b2JointType type
The joint type is set automatically for concrete joint types.
Definition: b2_joint.h:83
b2RopeJoint::GetLocalAnchorA
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA's origin.
Definition: b2_rope_joint.h:72
b2RopeJointDef::localAnchorA
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
Definition: b2_rope_joint.h:43
b2Vec2::Set
void Set(float x_, float y_)
Set this vector to some specified coordinates.
Definition: b2_math.h:51
b2RopeJoint::GetAnchorB
b2Vec2 GetAnchorB() const override
Get the anchor point on bodyB in world coordinates.
b2RopeJointDef
Definition: b2_rope_joint.h:32
b2RopeJoint::SetMaxLength
void SetMaxLength(float length)
Set/Get the maximum length of the rope.
Definition: b2_rope_joint.h:78
b2SolverData
Solver Data.
Definition: b2_time_step.h:66
b2RopeJoint
Definition: b2_rope_joint.h:62
b2RopeJointDef::localAnchorB
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
Definition: b2_rope_joint.h:46
b2RopeJointDef::maxLength
float maxLength
Definition: b2_rope_joint.h:51
b2RopeJoint::GetAnchorA
b2Vec2 GetAnchorA() const override
Get the anchor point on bodyA in world coordinates.
b2Joint
Definition: b2_joint.h:110
b2RopeJoint::GetReactionTorque
float GetReactionTorque(float inv_dt) const override
Get the reaction torque on bodyB in N*m.
b2RopeJoint::Dump
void Dump() override
Dump joint to dmLog.