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
float GetLength() const
Get the rest length.
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA's origin.
virtual void SolveVelocityConstraints(const b2SolverData &data)=0
virtual b2Vec2 GetReactionForce(float inv_dt) const =0
Get the reaction force on bodyB at the joint anchor in Newtons.
f
Joint definitions are used to construct joints.
Definition: b2_joint.h:72
#define B2_API
Definition: b2_api.h:49
float minLength
Minimum length. Clamped to a stable minimum value.
GLenum GLuint GLenum GLsizei length
Definition: gl.h:1033
float stiffness
The linear stiffness in N/m.
Solver Data.
Definition: b2_time_step.h:67
A 2D column vector.
Definition: b2_math.h:41
float GetStiffness() const
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB's origin.
signed int int32
Definition: b2_types.h:28
virtual float GetReactionTorque(float inv_dt) const =0
Get the reaction torque on bodyB in N*m.
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:128
Definition: b2_draw.h:48
virtual b2Vec2 GetAnchorA() const =0
Get the anchor point on bodyA in world coordinates.
virtual void InitVelocityConstraints(const b2SolverData &data)=0
virtual bool SolvePositionConstraints(const b2SolverData &data)=0
IMGUI_API void Initialize(ImGuiContext *context)
Definition: imgui.cpp:3473
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
float length
The rest length of this joint. Clamped to a stable minimum value.
virtual void Dump()
Dump this joint to the log file.
Definition: b2_joint.h:151
float GetMinLength() const
Get the minimum length.
virtual b2Vec2 GetAnchorB() const =0
Get the anchor point on bodyB in world coordinates.
float maxLength
Maximum length. Must be greater than or equal to the minimum length.
virtual void Draw(b2Draw *draw) const
Debug draw this joint.
Definition: b2_joint.cpp:255
float GetMaxLength() const
Get the maximum length.
void SetDamping(float damping)
Set/get linear damping in N*s/m.
float damping
The linear damping in N*s/m.
void SetStiffness(float stiffness)
Set/get the linear stiffness in N/m.
float GetDamping() const
GLenum type
Definition: gl.h:1033


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:19