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

| Box2D 2.4.0 A 2D physics engine for games

b2_distance_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_DISTANCE_JOINT_H
24 #define B2_DISTANCE_JOINT_H
25
26 #include "b2_api.h"
27 #include "b2_joint.h"
28
34 struct B2_API b2DistanceJointDef : public b2JointDef
35 {
36 b2DistanceJointDef()
37 {
38 type = e_distanceJoint;
39 localAnchorA.Set(0.0f, 0.0f);
40 localAnchorB.Set(0.0f, 0.0f);
41 length = 1.0f;
42 stiffness = 0.0f;
43 damping = 0.0f;
44 }
45
48 void Initialize(b2Body* bodyA, b2Body* bodyB,
49 const b2Vec2& anchorA, const b2Vec2& anchorB);
50
52 b2Vec2 localAnchorA;
53
55 b2Vec2 localAnchorB;
56
58 float length;
59
61 float stiffness;
62
64 float damping;
65 };
66
69 class B2_API b2DistanceJoint : public b2Joint
70 {
71 public:
72
73 b2Vec2 GetAnchorA() const override;
74 b2Vec2 GetAnchorB() const override;
75
78 b2Vec2 GetReactionForce(float inv_dt) const override;
79
82 float GetReactionTorque(float inv_dt) const override;
83
85 const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
86
88 const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
89
92 void SetLength(float length) { m_length = length; }
93 float GetLength() const { return m_length; }
94
96 void SetStiffness(float stiffness) { m_stiffness = stiffness; }
97 float GetStiffness() const { return m_stiffness; }
98
100 void SetDamping(float damping) { m_damping = damping; }
101 float GetDamping() const { return m_damping; }
102
104 void Dump() override;
105
106 protected:
107
108 friend class b2Joint;
109 b2DistanceJoint(const b2DistanceJointDef* data);
110
111 void InitVelocityConstraints(const b2SolverData& data) override;
112 void SolveVelocityConstraints(const b2SolverData& data) override;
113 bool SolvePositionConstraints(const b2SolverData& data) override;
114
115 float m_stiffness;
116 float m_damping;
117 float m_bias;
118
119 // Solver shared
120 b2Vec2 m_localAnchorA;
121 b2Vec2 m_localAnchorB;
122 float m_gamma;
123 float m_impulse;
124 float m_length;
125
126 // Solver temp
127 int32 m_indexA;
128 int32 m_indexB;
129 b2Vec2 m_u;
130 b2Vec2 m_rA;
131 b2Vec2 m_rB;
132 b2Vec2 m_localCenterA;
133 b2Vec2 m_localCenterB;
134 float m_invMassA;
135 float m_invMassB;
136 float m_invIA;
137 float m_invIB;
138 float m_mass;
139 };
140
141 #endif
b2Vec2
A 2D column vector.
Definition: b2_math.h:42
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:133
b2DistanceJoint::GetAnchorB
b2Vec2 GetAnchorB() const override
Get the anchor point on bodyB in world coordinates.
b2DistanceJoint
Definition: b2_distance_joint.h:70
b2DistanceJoint::GetLocalAnchorA
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA's origin.
Definition: b2_distance_joint.h:85
b2DistanceJoint::SetDamping
void SetDamping(float damping)
Set/get linear damping in N*s/m.
Definition: b2_distance_joint.h:100
b2JointDef
Joint definitions are used to construct joints.
Definition: b2_joint.h:73
b2DistanceJoint::GetLocalAnchorB
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB's origin.
Definition: b2_distance_joint.h:88
b2DistanceJointDef::localAnchorA
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
Definition: b2_distance_joint.h:52
b2DistanceJointDef::damping
float damping
The linear damping in N*s/m.
Definition: b2_distance_joint.h:64
b2DistanceJoint::Dump
void Dump() override
Dump joint to dmLog.
b2DistanceJointDef::length
float length
The natural length between the anchor points.
Definition: b2_distance_joint.h:58
b2DistanceJointDef::stiffness
float stiffness
The linear stiffness in N/m. A value of 0 disables softness.
Definition: b2_distance_joint.h:61
b2DistanceJoint::SetLength
void SetLength(float length)
Definition: b2_distance_joint.h:92
b2DistanceJoint::GetReactionTorque
float GetReactionTorque(float inv_dt) const override
b2DistanceJoint::GetAnchorA
b2Vec2 GetAnchorA() const override
Get the anchor point on bodyA in world coordinates.
b2SolverData
Solver Data.
Definition: b2_time_step.h:68
b2DistanceJoint::GetReactionForce
b2Vec2 GetReactionForce(float inv_dt) const override
b2DistanceJointDef::localAnchorB
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
Definition: b2_distance_joint.h:55
b2DistanceJoint::SetStiffness
void SetStiffness(float stiffness)
Set/get the linear stiffness in N/m.
Definition: b2_distance_joint.h:96
b2Joint
Definition: b2_joint.h:112
b2DistanceJointDef
Definition: b2_distance_joint.h:35
b2DistanceJointDef::Initialize
void Initialize(b2Body *bodyA, b2Body *bodyB, const b2Vec2 &anchorA, const b2Vec2 &anchorB)