b2_distance_joint.h
Go to the documentation of this file.
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 {
36  {
38  localAnchorA.Set(0.0f, 0.0f);
39  localAnchorB.Set(0.0f, 0.0f);
40  length = 1.0f;
41  minLength = 0.0f;
42  maxLength = FLT_MAX;
43  stiffness = 0.0f;
44  damping = 0.0f;
45  }
46 
49  void Initialize(b2Body* bodyA, b2Body* bodyB,
50  const b2Vec2& anchorA, const b2Vec2& anchorB);
51 
54 
57 
59  float length;
60 
62  float minLength;
63 
65  float maxLength;
66 
68  float stiffness;
69 
71  float damping;
72 };
73 
77 {
78 public:
79 
80  b2Vec2 GetAnchorA() const override;
81  b2Vec2 GetAnchorB() const override;
82 
85  b2Vec2 GetReactionForce(float inv_dt) const override;
86 
89  float GetReactionTorque(float inv_dt) const override;
90 
92  const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
93 
95  const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
96 
98  float GetLength() const { return m_length; }
99 
102  float SetLength(float length);
103 
105  float GetMinLength() const { return m_minLength; }
106 
109  float SetMinLength(float minLength);
110 
112  float GetMaxLength() const { return m_maxLength; }
113 
116  float SetMaxLength(float maxLength);
117 
119  float GetCurrentLength() const;
120 
122  void SetStiffness(float stiffness) { m_stiffness = stiffness; }
123  float GetStiffness() const { return m_stiffness; }
124 
126  void SetDamping(float damping) { m_damping = damping; }
127  float GetDamping() const { return m_damping; }
128 
130  void Dump() override;
131 
133  void Draw(b2Draw* draw) const override;
134 
135 protected:
136 
137  friend class b2Joint;
138  b2DistanceJoint(const b2DistanceJointDef* data);
139 
140  void InitVelocityConstraints(const b2SolverData& data) override;
141  void SolveVelocityConstraints(const b2SolverData& data) override;
142  bool SolvePositionConstraints(const b2SolverData& data) override;
143 
144  float m_stiffness;
145  float m_damping;
146  float m_bias;
147  float m_length;
148  float m_minLength;
149  float m_maxLength;
150 
151  // Solver shared
154  float m_gamma;
155  float m_impulse;
158 
159  // Solver temp
168  float m_invMassA;
169  float m_invMassB;
170  float m_invIA;
171  float m_invIB;
172  float m_softMass;
173  float m_mass;
174 };
175 
176 #endif
b2DistanceJoint::m_localAnchorB
b2Vec2 m_localAnchorB
Definition: b2_distance_joint.h:153
b2DistanceJoint::m_localCenterA
b2Vec2 m_localCenterA
Definition: b2_distance_joint.h:165
b2_api.h
b2DistanceJoint::GetLocalAnchorA
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA's origin.
Definition: b2_distance_joint.h:92
b2Joint::GetReactionTorque
virtual float GetReactionTorque(float inv_dt) const =0
Get the reaction torque on bodyB in N*m.
b2DistanceJoint::m_invMassA
float m_invMassA
Definition: b2_distance_joint.h:168
b2DistanceJoint::GetLocalAnchorB
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB's origin.
Definition: b2_distance_joint.h:95
b2DistanceJoint::m_invIB
float m_invIB
Definition: b2_distance_joint.h:171
b2DistanceJoint::m_mass
float m_mass
Definition: b2_distance_joint.h:173
b2Joint::SolvePositionConstraints
virtual bool SolvePositionConstraints(const b2SolverData &data)=0
b2DistanceJointDef::localAnchorB
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
Definition: b2_distance_joint.h:56
b2SolverData
Solver Data.
Definition: b2_time_step.h:67
b2_joint.h
b2DistanceJointDef::damping
float damping
The linear damping in N*s/m.
Definition: b2_distance_joint.h:71
b2Joint::InitVelocityConstraints
virtual void InitVelocityConstraints(const b2SolverData &data)=0
b2DistanceJointDef::length
float length
The rest length of this joint. Clamped to a stable minimum value.
Definition: b2_distance_joint.h:59
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:128
b2DistanceJoint::m_lowerImpulse
float m_lowerImpulse
Definition: b2_distance_joint.h:156
b2DistanceJoint::GetStiffness
float GetStiffness() const
Definition: b2_distance_joint.h:123
B2_API
#define B2_API
Definition: b2_api.h:49
b2DistanceJoint::m_u
b2Vec2 m_u
Definition: b2_distance_joint.h:162
b2Joint::Draw
virtual void Draw(b2Draw *draw) const
Debug draw this joint.
Definition: b2_joint.cpp:255
b2DistanceJoint::m_length
float m_length
Definition: b2_distance_joint.h:147
e_distanceJoint
@ e_distanceJoint
Definition: b2_joint.h:40
b2Vec2
A 2D column vector.
Definition: b2_math.h:41
b2DistanceJoint::GetMaxLength
float GetMaxLength() const
Get the maximum length.
Definition: b2_distance_joint.h:112
b2Joint::Dump
virtual void Dump()
Dump this joint to the log file.
Definition: b2_joint.h:151
f
f
b2Joint::SolveVelocityConstraints
virtual void SolveVelocityConstraints(const b2SolverData &data)=0
b2DistanceJointDef::maxLength
float maxLength
Maximum length. Must be greater than or equal to the minimum length.
Definition: b2_distance_joint.h:65
b2DistanceJoint::m_rB
b2Vec2 m_rB
Definition: b2_distance_joint.h:164
b2DistanceJoint::GetMinLength
float GetMinLength() const
Get the minimum length.
Definition: b2_distance_joint.h:105
b2Joint::GetAnchorA
virtual b2Vec2 GetAnchorA() const =0
Get the anchor point on bodyA in world coordinates.
b2DistanceJoint::m_softMass
float m_softMass
Definition: b2_distance_joint.h:172
b2DistanceJointDef::stiffness
float stiffness
The linear stiffness in N/m.
Definition: b2_distance_joint.h:68
b2Joint
Definition: b2_joint.h:110
b2Draw
Definition: b2_draw.h:48
b2DistanceJoint::m_maxLength
float m_maxLength
Definition: b2_distance_joint.h:149
b2JointDef
Joint definitions are used to construct joints.
Definition: b2_joint.h:72
b2DistanceJoint::m_invMassB
float m_invMassB
Definition: b2_distance_joint.h:169
length
GLenum GLuint GLenum GLsizei length
Definition: gl.h:1033
b2DistanceJoint::GetDamping
float GetDamping() const
Definition: b2_distance_joint.h:127
b2DistanceJoint::GetLength
float GetLength() const
Get the rest length.
Definition: b2_distance_joint.h:98
b2DistanceJoint::SetDamping
void SetDamping(float damping)
Set/get linear damping in N*s/m.
Definition: b2_distance_joint.h:126
b2DistanceJoint::m_currentLength
float m_currentLength
Definition: b2_distance_joint.h:167
b2DistanceJoint::m_impulse
float m_impulse
Definition: b2_distance_joint.h:155
b2DistanceJoint::m_localAnchorA
b2Vec2 m_localAnchorA
Definition: b2_distance_joint.h:152
b2DistanceJoint::m_localCenterB
b2Vec2 m_localCenterB
Definition: b2_distance_joint.h:166
b2DistanceJoint::SetStiffness
void SetStiffness(float stiffness)
Set/get the linear stiffness in N/m.
Definition: b2_distance_joint.h:122
b2DistanceJoint::m_damping
float m_damping
Definition: b2_distance_joint.h:145
b2DistanceJointDef::minLength
float minLength
Minimum length. Clamped to a stable minimum value.
Definition: b2_distance_joint.h:62
b2DistanceJoint::m_stiffness
float m_stiffness
Definition: b2_distance_joint.h:144
b2DistanceJoint::m_invIA
float m_invIA
Definition: b2_distance_joint.h:170
b2DistanceJointDef::b2DistanceJointDef
b2DistanceJointDef()
Definition: b2_distance_joint.h:35
b2DistanceJoint::m_rA
b2Vec2 m_rA
Definition: b2_distance_joint.h:163
b2DistanceJoint::m_gamma
float m_gamma
Definition: b2_distance_joint.h:154
ImGui::Initialize
IMGUI_API void Initialize(ImGuiContext *context)
Definition: imgui.cpp:3473
b2DistanceJoint::m_minLength
float m_minLength
Definition: b2_distance_joint.h:148
int32
signed int int32
Definition: b2_types.h:28
b2DistanceJoint::m_indexB
int32 m_indexB
Definition: b2_distance_joint.h:161
b2DistanceJoint::m_bias
float m_bias
Definition: b2_distance_joint.h:146
b2DistanceJointDef
Definition: b2_distance_joint.h:33
type
GLenum type
Definition: gl.h:1033
b2DistanceJoint
Definition: b2_distance_joint.h:76
b2Joint::GetAnchorB
virtual b2Vec2 GetAnchorB() const =0
Get the anchor point on bodyB in world coordinates.
b2DistanceJoint::m_indexA
int32 m_indexA
Definition: b2_distance_joint.h:160
b2DistanceJoint::m_upperImpulse
float m_upperImpulse
Definition: b2_distance_joint.h:157
b2DistanceJointDef::localAnchorA
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
Definition: b2_distance_joint.h:53
b2Joint::GetReactionForce
virtual b2Vec2 GetReactionForce(float inv_dt) const =0
Get the reaction force on bodyB at the joint anchor in Newtons.


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:07