Box2D: /build/box2d/src/box2d-2.4.1/include/box2d/b2_weld_joint.h Source File

| Box2D 2.4.1 A 2D physics engine for games

b2_weld_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_WELD_JOINT_H
24 #define B2_WELD_JOINT_H
25
26 #include "b2_api.h"
27 #include "b2_joint.h"
28
32 struct B2_API b2WeldJointDef : public b2JointDef
33 {
34 b2WeldJointDef()
35 {
36 type = e_weldJoint;
37 localAnchorA.Set(0.0f, 0.0f);
38 localAnchorB.Set(0.0f, 0.0f);
39 referenceAngle = 0.0f;
40 stiffness = 0.0f;
41 damping = 0.0f;
42 }
43
48 void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor);
49
51 b2Vec2 localAnchorA;
52
54 b2Vec2 localAnchorB;
55
57 float referenceAngle;
58
61 float stiffness;
62
64 float damping;
65 };
66
69 class B2_API b2WeldJoint : public b2Joint
70 {
71 public:
72 b2Vec2 GetAnchorA() const override;
73 b2Vec2 GetAnchorB() const override;
74
75 b2Vec2 GetReactionForce(float inv_dt) const override;
76 float GetReactionTorque(float inv_dt) const override;
77
79 const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
80
82 const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
83
85 float GetReferenceAngle() const { return m_referenceAngle; }
86
88 void SetStiffness(float hz) { m_stiffness = hz; }
89 float GetStiffness() const { return m_stiffness; }
90
92 void SetDamping(float damping) { m_damping = damping; }
93 float GetDamping() const { return m_damping; }
94
96 void Dump() override;
97
98 protected:
99
100 friend class b2Joint;
101
102 b2WeldJoint(const b2WeldJointDef* def);
103
104 void InitVelocityConstraints(const b2SolverData& data) override;
105 void SolveVelocityConstraints(const b2SolverData& data) override;
106 bool SolvePositionConstraints(const b2SolverData& data) override;
107
108 float m_stiffness;
109 float m_damping;
110 float m_bias;
111
112 // Solver shared
113 b2Vec2 m_localAnchorA;
114 b2Vec2 m_localAnchorB;
115 float m_referenceAngle;
116 float m_gamma;
117 b2Vec3 m_impulse;
118
119 // Solver temp
120 int32 m_indexA;
121 int32 m_indexB;
122 b2Vec2 m_rA;
123 b2Vec2 m_rB;
124 b2Vec2 m_localCenterA;
125 b2Vec2 m_localCenterB;
126 float m_invMassA;
127 float m_invMassB;
128 float m_invIA;
129 float m_invIB;
130 b2Mat33 m_mass;
131 };
132
133 #endif
b2Vec2
A 2D column vector.
Definition: b2_math.h:42
b2WeldJoint::GetAnchorA
b2Vec2 GetAnchorA() const override
Get the anchor point on bodyA in world coordinates.
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:129
b2WeldJointDef::Initialize
void Initialize(b2Body *bodyA, b2Body *bodyB, const b2Vec2 &anchor)
b2WeldJointDef::stiffness
float stiffness
Definition: b2_weld_joint.h:61
b2WeldJoint::GetReferenceAngle
float GetReferenceAngle() const
Get the reference angle.
Definition: b2_weld_joint.h:85
b2WeldJointDef::damping
float damping
The rotational damping in N*m*s.
Definition: b2_weld_joint.h:64
b2WeldJoint::GetLocalAnchorA
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA's origin.
Definition: b2_weld_joint.h:79
b2JointDef
Joint definitions are used to construct joints.
Definition: b2_joint.h:73
b2Vec3
A 2D column vector with 3 elements.
Definition: b2_math.h:133
b2WeldJoint::SetStiffness
void SetStiffness(float hz)
Set/get stiffness in N*m.
Definition: b2_weld_joint.h:88
b2WeldJoint::SetDamping
void SetDamping(float damping)
Set/get damping in N*m*s.
Definition: b2_weld_joint.h:92
b2Mat33
A 3-by-3 matrix. Stored in column-major order.
Definition: b2_math.h:246
b2WeldJoint::GetReactionTorque
float GetReactionTorque(float inv_dt) const override
Get the reaction torque on bodyB in N*m.
b2WeldJoint::Dump
void Dump() override
Dump to b2Log.
b2WeldJoint
Definition: b2_weld_joint.h:70
b2WeldJointDef::localAnchorB
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
Definition: b2_weld_joint.h:54
b2WeldJointDef::referenceAngle
float referenceAngle
The bodyB angle minus bodyA angle in the reference state (radians).
Definition: b2_weld_joint.h:57
b2WeldJointDef
Definition: b2_weld_joint.h:33
b2WeldJoint::GetReactionForce
b2Vec2 GetReactionForce(float inv_dt) const override
Get the reaction force on bodyB at the joint anchor in Newtons.
b2SolverData
Solver Data.
Definition: b2_time_step.h:68
b2WeldJointDef::localAnchorA
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
Definition: b2_weld_joint.h:51
b2Joint
Definition: b2_joint.h:111
b2WeldJoint::GetLocalAnchorB
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB's origin.
Definition: b2_weld_joint.h:82
b2WeldJoint::GetAnchorB
b2Vec2 GetAnchorB() const override
Get the anchor point on bodyB in world coordinates.