Box2D: /build/box2d/src/box2d-adaedf1772ede7420bc9ee569c8cba7952db91a0/include/box2d/b2_rope_joint.h Source File

| 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_api.h"
27 #include "b2_joint.h"
28
33 struct B2_API b2RopeJointDef : public b2JointDef
34 {
35 b2RopeJointDef()
36 {
37 type = e_ropeJoint;
38 localAnchorA.Set(-1.0f, 0.0f);
39 localAnchorB.Set(1.0f, 0.0f);
40 maxLength = 0.0f;
41 }
42
44 b2Vec2 localAnchorA;
45
47 b2Vec2 localAnchorB;
48
52 float maxLength;
53 };
54
63 class B2_API b2RopeJoint : public b2Joint
64 {
65 public:
66 b2Vec2 GetAnchorA() const override;
67 b2Vec2 GetAnchorB() const override;
68
69 b2Vec2 GetReactionForce(float inv_dt) const override;
70 float GetReactionTorque(float inv_dt) const override;
71
73 const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
74
76 const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
77
79 void SetMaxLength(float length) { m_maxLength = length; }
80 float GetMaxLength() const;
81
82 // Get current length
83 float GetLength() const;
84
86 void Dump() override;
87
88 protected:
89
90 friend class b2Joint;
91 b2RopeJoint(const b2RopeJointDef* data);
92
93 void InitVelocityConstraints(const b2SolverData& data) override;
94 void SolveVelocityConstraints(const b2SolverData& data) override;
95 bool SolvePositionConstraints(const b2SolverData& data) override;
96
97 // Solver shared
98 b2Vec2 m_localAnchorA;
99 b2Vec2 m_localAnchorB;
100 float m_maxLength;
101 float m_length;
102 float m_impulse;
103
104 // Solver temp
105 int32 m_indexA;
106 int32 m_indexB;
107 b2Vec2 m_u;
108 b2Vec2 m_rA;
109 b2Vec2 m_rB;
110 b2Vec2 m_localCenterA;
111 b2Vec2 m_localCenterB;
112 float m_invMassA;
113 float m_invMassB;
114 float m_invIA;
115 float m_invIB;
116 float m_mass;
117 };
118
119 #endif
b2Vec2
A 2D column vector.
Definition: b2_math.h:42
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:73
b2RopeJoint::GetLocalAnchorB
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB's origin.
Definition: b2_rope_joint.h:76
b2RopeJoint::GetLocalAnchorA
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA's origin.
Definition: b2_rope_joint.h:73
b2RopeJointDef::localAnchorA
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
Definition: b2_rope_joint.h:44
b2RopeJoint::GetAnchorB
b2Vec2 GetAnchorB() const override
Get the anchor point on bodyB in world coordinates.
b2RopeJointDef
Definition: b2_rope_joint.h:34
b2RopeJoint::SetMaxLength
void SetMaxLength(float length)
Set/Get the maximum length of the rope.
Definition: b2_rope_joint.h:79
b2SolverData
Solver Data.
Definition: b2_time_step.h:68
b2RopeJoint
Definition: b2_rope_joint.h:64
b2RopeJointDef::localAnchorB
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
Definition: b2_rope_joint.h:47
b2RopeJointDef::maxLength
float maxLength
Definition: b2_rope_joint.h:52
b2RopeJoint::GetAnchorA
b2Vec2 GetAnchorA() const override
Get the anchor point on bodyA in world coordinates.
b2Joint
Definition: b2_joint.h:112
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.