Box2D  2.3.0
A 2D Physics Engine for Games
b2WeldJoint.h
1 /*
2 * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18 
19 #ifndef B2_WELD_JOINT_H
20 #define B2_WELD_JOINT_H
21 
22 #include <Box2D/Dynamics/Joints/b2Joint.h>
23 
27 struct b2WeldJointDef : public b2JointDef
28 {
30  {
31  type = e_weldJoint;
32  localAnchorA.Set(0.0f, 0.0f);
33  localAnchorB.Set(0.0f, 0.0f);
34  referenceAngle = 0.0f;
35  frequencyHz = 0.0f;
36  dampingRatio = 0.0f;
37  }
38 
41  void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor);
42 
45 
48 
50  float32 referenceAngle;
51 
54  float32 frequencyHz;
55 
57  float32 dampingRatio;
58 };
59 
62 class b2WeldJoint : public b2Joint
63 {
64 public:
65  b2Vec2 GetAnchorA() const;
66  b2Vec2 GetAnchorB() const;
67 
68  b2Vec2 GetReactionForce(float32 inv_dt) const;
69  float32 GetReactionTorque(float32 inv_dt) const;
70 
72  const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
73 
75  const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
76 
78  float32 GetReferenceAngle() const { return m_referenceAngle; }
79 
81  void SetFrequency(float32 hz) { m_frequencyHz = hz; }
82  float32 GetFrequency() const { return m_frequencyHz; }
83 
85  void SetDampingRatio(float32 ratio) { m_dampingRatio = ratio; }
86  float32 GetDampingRatio() const { return m_dampingRatio; }
87 
89  void Dump();
90 
91 protected:
92 
93  friend class b2Joint;
94 
95  b2WeldJoint(const b2WeldJointDef* def);
96 
97  void InitVelocityConstraints(const b2SolverData& data);
98  void SolveVelocityConstraints(const b2SolverData& data);
99  bool SolvePositionConstraints(const b2SolverData& data);
100 
101  float32 m_frequencyHz;
102  float32 m_dampingRatio;
103  float32 m_bias;
104 
105  // Solver shared
106  b2Vec2 m_localAnchorA;
107  b2Vec2 m_localAnchorB;
108  float32 m_referenceAngle;
109  float32 m_gamma;
110  b2Vec3 m_impulse;
111 
112  // Solver temp
113  int32 m_indexA;
114  int32 m_indexB;
115  b2Vec2 m_rA;
116  b2Vec2 m_rB;
117  b2Vec2 m_localCenterA;
118  b2Vec2 m_localCenterB;
119  float32 m_invMassA;
120  float32 m_invMassB;
121  float32 m_invIA;
122  float32 m_invIB;
123  b2Mat33 m_mass;
124 };
125 
126 #endif
A 2D column vector with 3 elements.
Definition: b2Math.h:144
b2Body * bodyA
The first attached body.
Definition: b2Joint.h:92
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
Definition: b2WeldJoint.h:47
A 3-by-3 matrix. Stored in column-major order.
Definition: b2Math.h:257
void SetFrequency(float32 hz)
Set/get frequency in Hz.
Definition: b2WeldJoint.h:81
b2Body * bodyB
The second attached body.
Definition: b2Joint.h:95
Definition: b2Joint.h:103
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB's origin.
Definition: b2WeldJoint.h:75
Definition: b2WeldJoint.h:62
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates.
Definition: b2Math.h:65
b2Vec2 GetReactionForce(float32 inv_dt) const
Get the reaction force on bodyB at the joint anchor in Newtons.
Definition: b2WeldJoint.cpp:302
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA's origin.
Definition: b2WeldJoint.h:72
Definition: b2WeldJoint.h:27
float32 GetReactionTorque(float32 inv_dt) const
Get the reaction torque on bodyB in N*m.
Definition: b2WeldJoint.cpp:308
b2JointType type
The joint type is set automatically for concrete joint types.
Definition: b2Joint.h:86
Solver Data.
Definition: b2TimeStep.h:63
float32 frequencyHz
Definition: b2WeldJoint.h:54
Joint definitions are used to construct joints.
Definition: b2Joint.h:74
void Dump()
Dump to b2Log.
Definition: b2WeldJoint.cpp:313
void SetDampingRatio(float32 ratio)
Set/get damping ratio.
Definition: b2WeldJoint.h:85
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
Definition: b2WeldJoint.h:44
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:126
b2Vec2 GetAnchorB() const
Get the anchor point on bodyB in world coordinates.
Definition: b2WeldJoint.cpp:297
float32 GetReferenceAngle() const
Get the reference angle.
Definition: b2WeldJoint.h:78
A 2D column vector.
Definition: b2Math.h:53
float32 referenceAngle
The bodyB angle minus bodyA angle in the reference state (radians).
Definition: b2WeldJoint.h:50
b2Vec2 GetAnchorA() const
Get the anchor point on bodyA in world coordinates.
Definition: b2WeldJoint.cpp:292
float32 dampingRatio
The damping ratio. 0 = no damping, 1 = critical damping.
Definition: b2WeldJoint.h:57
void Initialize(b2Body *bodyA, b2Body *bodyB, const b2Vec2 &anchor)
Definition: b2WeldJoint.cpp:37