b2_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_JOINT_H
24 #define B2_JOINT_H
25 
26 #include "b2_api.h"
27 #include "b2_math.h"
28 
29 class b2Body;
30 class b2Draw;
31 class b2Joint;
32 struct b2SolverData;
33 class b2BlockAllocator;
34 
36 {
49 };
50 
52 {
54  float angularA;
55  float angularB;
56 };
57 
64 {
69 };
70 
73 {
75  {
77  bodyA = nullptr;
78  bodyB = nullptr;
79  collideConnected = false;
80  }
81 
84 
87 
90 
93 
96 };
97 
99 B2_API void b2LinearStiffness(float& stiffness, float& damping,
100  float frequencyHertz, float dampingRatio,
101  const b2Body* bodyA, const b2Body* bodyB);
102 
104 B2_API void b2AngularStiffness(float& stiffness, float& damping,
105  float frequencyHertz, float dampingRatio,
106  const b2Body* bodyA, const b2Body* bodyB);
107 
111 {
112 public:
113 
115  b2JointType GetType() const;
116 
118  b2Body* GetBodyA();
119 
121  b2Body* GetBodyB();
122 
124  virtual b2Vec2 GetAnchorA() const = 0;
125 
127  virtual b2Vec2 GetAnchorB() const = 0;
128 
130  virtual b2Vec2 GetReactionForce(float inv_dt) const = 0;
131 
133  virtual float GetReactionTorque(float inv_dt) const = 0;
134 
136  b2Joint* GetNext();
137  const b2Joint* GetNext() const;
138 
140  b2JointUserData& GetUserData();
141 
143  bool IsEnabled() const;
144 
148  bool GetCollideConnected() const;
149 
151  virtual void Dump() { b2Dump("// Dump is not supported for this joint type.\n"); }
152 
154  virtual void ShiftOrigin(const b2Vec2& newOrigin) { B2_NOT_USED(newOrigin); }
155 
157  virtual void Draw(b2Draw* draw) const;
158 
159 protected:
160  friend class b2World;
161  friend class b2Body;
162  friend class b2Island;
163  friend class b2GearJoint;
164 
165  static b2Joint* Create(const b2JointDef* def, b2BlockAllocator* allocator);
166  static void Destroy(b2Joint* joint, b2BlockAllocator* allocator);
167 
168  b2Joint(const b2JointDef* def);
169  virtual ~b2Joint() {}
170 
171  virtual void InitVelocityConstraints(const b2SolverData& data) = 0;
172  virtual void SolveVelocityConstraints(const b2SolverData& data) = 0;
173 
174  // This returns true if the position errors are within tolerance.
175  virtual bool SolvePositionConstraints(const b2SolverData& data) = 0;
176 
184 
186 
189 
191 };
192 
194 {
195  return m_type;
196 }
197 
199 {
200  return m_bodyA;
201 }
202 
204 {
205  return m_bodyB;
206 }
207 
209 {
210  return m_next;
211 }
212 
213 inline const b2Joint* b2Joint::GetNext() const
214 {
215  return m_next;
216 }
217 
219 {
220  return m_userData;
221 }
222 
223 inline bool b2Joint::GetCollideConnected() const
224 {
225  return m_collideConnected;
226 }
227 
228 #endif
b2Joint::m_index
int32 m_index
Definition: b2_joint.h:185
b2Joint::m_prev
b2Joint * m_prev
Definition: b2_joint.h:178
b2Joint::GetNext
b2Joint * GetNext()
Get the next joint the world joint list.
Definition: b2_joint.h:208
e_frictionJoint
@ e_frictionJoint
Definition: b2_joint.h:46
b2Jacobian::angularB
float angularB
Definition: b2_joint.h:55
b2_api.h
B2_NOT_USED
#define B2_NOT_USED(x)
Definition: b2_common.h:36
b2JointType
b2JointType
Definition: b2_joint.h:35
b2LinearStiffness
B2_API void b2LinearStiffness(float &stiffness, float &damping, float frequencyHertz, float dampingRatio, const b2Body *bodyA, const b2Body *bodyB)
Utility to compute linear stiffness values from frequency and damping ratio.
Definition: b2_joint.cpp:40
b2Joint::GetType
b2JointType GetType() const
Get the type of the concrete joint.
Definition: b2_joint.h:193
b2Joint::GetBodyB
b2Body * GetBodyB()
Get the second body attached to this joint.
Definition: b2_joint.h:203
b2JointEdge::other
b2Body * other
provides quick access to the other body attached.
Definition: b2_joint.h:65
b2JointEdge
Definition: b2_joint.h:63
b2JointDef::b2JointDef
b2JointDef()
Definition: b2_joint.h:74
b2SolverData
Solver Data.
Definition: b2_time_step.h:67
b2GearJoint::InitVelocityConstraints
void InitVelocityConstraints(const b2SolverData &data) override
Definition: b2_gear_joint.cpp:141
b2Joint::Destroy
static void Destroy(b2Joint *joint, b2BlockAllocator *allocator)
Definition: b2_joint.cpp:174
b2BlockAllocator
Definition: b2_block_allocator.h:37
b2GearJoint::b2Joint
friend class b2Joint
Definition: b2_gear_joint.h:85
b2Joint::m_edgeB
b2JointEdge m_edgeB
Definition: b2_joint.h:181
b2Joint::m_type
b2JointType m_type
Definition: b2_joint.h:177
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:128
b2Joint::m_edgeA
b2JointEdge m_edgeA
Definition: b2_joint.h:180
b2_math.h
b2Dump
void b2Dump(const char *string,...)
Definition: b2_settings.cpp:57
b2Jacobian
Definition: b2_joint.h:51
B2_API
#define B2_API
Definition: b2_api.h:49
b2Jacobian::angularA
float angularA
Definition: b2_joint.h:54
e_distanceJoint
@ e_distanceJoint
Definition: b2_joint.h:40
b2Vec2
A 2D column vector.
Definition: b2_math.h:41
b2Joint::Dump
virtual void Dump()
Dump this joint to the log file.
Definition: b2_joint.h:151
e_motorJoint
@ e_motorJoint
Definition: b2_joint.h:48
b2AngularStiffness
B2_API void b2AngularStiffness(float &stiffness, float &damping, float frequencyHertz, float dampingRatio, const b2Body *bodyA, const b2Body *bodyB)
Utility to compute rotational stiffness values frequency and damping ratio.
Definition: b2_joint.cpp:65
b2Joint::GetBodyA
b2Body * GetBodyA()
Get the first body attached to this joint.
Definition: b2_joint.h:198
b2Joint::GetCollideConnected
bool GetCollideConnected() const
Definition: b2_joint.h:223
b2Joint::m_next
b2Joint * m_next
Definition: b2_joint.h:179
b2Joint
Definition: b2_joint.h:110
b2Draw
Definition: b2_draw.h:48
b2JointDef
Joint definitions are used to construct joints.
Definition: b2_joint.h:72
e_unknownJoint
@ e_unknownJoint
Definition: b2_joint.h:37
b2Island
This is an internal class.
Definition: b2_island.h:38
b2JointUserData
You can define this to inject whatever data you want in b2Joint.
Definition: b2_settings.h:82
b2Joint::m_islandFlag
bool m_islandFlag
Definition: b2_joint.h:187
b2JointDef::collideConnected
bool collideConnected
Set this flag to true if the attached bodies should collide.
Definition: b2_joint.h:95
b2GearJoint::SolveVelocityConstraints
void SolveVelocityConstraints(const b2SolverData &data) override
Definition: b2_gear_joint.cpp:245
b2Joint::m_collideConnected
bool m_collideConnected
Definition: b2_joint.h:188
b2JointDef::userData
b2JointUserData userData
Use this to attach application specific data to your joints.
Definition: b2_joint.h:86
e_wheelJoint
@ e_wheelJoint
Definition: b2_joint.h:44
b2GearJoint::SolvePositionConstraints
bool SolvePositionConstraints(const b2SolverData &data) override
Definition: b2_gear_joint.cpp:281
e_mouseJoint
@ e_mouseJoint
Definition: b2_joint.h:42
e_weldJoint
@ e_weldJoint
Definition: b2_joint.h:45
b2JointEdge::prev
b2JointEdge * prev
the previous joint edge in the body's joint list
Definition: b2_joint.h:67
b2Jacobian::linear
b2Vec2 linear
Definition: b2_joint.h:53
b2Joint::m_bodyA
b2Body * m_bodyA
Definition: b2_joint.h:182
b2JointEdge::next
b2JointEdge * next
the next joint edge in the body's joint list
Definition: b2_joint.h:68
b2Joint::m_userData
b2JointUserData m_userData
Definition: b2_joint.h:190
e_ropeJoint
@ e_ropeJoint
Definition: b2_joint.h:47
b2JointDef::type
b2JointType type
The joint type is set automatically for concrete joint types.
Definition: b2_joint.h:83
int32
signed int int32
Definition: b2_types.h:28
b2Joint::~b2Joint
virtual ~b2Joint()
Definition: b2_joint.h:169
b2Joint::ShiftOrigin
virtual void ShiftOrigin(const b2Vec2 &newOrigin)
Shift the origin for any points stored in world coordinates.
Definition: b2_joint.h:154
type
GLenum type
Definition: gl.h:1033
b2World
Definition: b2_world.h:46
e_pulleyJoint
@ e_pulleyJoint
Definition: b2_joint.h:41
e_gearJoint
@ e_gearJoint
Definition: b2_joint.h:43
b2Joint::m_bodyB
b2Body * m_bodyB
Definition: b2_joint.h:183
e_prismaticJoint
@ e_prismaticJoint
Definition: b2_joint.h:39
b2Joint::Create
static b2Joint * Create(const b2JointDef *def, b2BlockAllocator *allocator)
Definition: b2_joint.cpp:90
b2JointEdge::joint
b2Joint * joint
the joint
Definition: b2_joint.h:66
e_revoluteJoint
@ e_revoluteJoint
Definition: b2_joint.h:38
b2GearJoint
Definition: b2_gear_joint.h:61
b2Joint::GetUserData
b2JointUserData & GetUserData()
Get the user data pointer.
Definition: b2_joint.h:218
b2JointDef::bodyA
b2Body * bodyA
The first attached body.
Definition: b2_joint.h:89
b2JointDef::bodyB
b2Body * bodyB
The second attached body.
Definition: b2_joint.h:92


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