2 * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
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.
19 #ifndef B2_DISTANCE_JOINT_H
20 #define B2_DISTANCE_JOINT_H
24 /// Distance joint definition. This requires defining an
25 /// anchor point on both bodies and the non-zero length of the
26 /// distance joint. The definition uses local anchor points
27 /// so that the initial configuration can violate the constraint
28 /// slightly. This helps when saving and loading a game.
29 /// @warning Do not use a zero or short length.
30 struct b2DistanceJointDef : public b2JointDef
34 type = e_distanceJoint;
35 localAnchor1.Set(0.0f, 0.0f);
36 localAnchor2.Set(0.0f, 0.0f);
42 /// Initialize the bodies, anchors, and length using the world
44 void Initialize(b2Body* body1, b2Body* body2,
45 const b2Vec2& anchor1, const b2Vec2& anchor2);
47 /// The local anchor point relative to body1's origin.
50 /// The local anchor point relative to body2's origin.
53 /// The equilibrium length between the anchor points.
56 /// The response speed.
59 /// The damping ratio. 0 = no damping, 1 = critical damping.
63 /// A distance joint constrains two points on two bodies
64 /// to remain at a fixed distance from each other. You can view
65 /// this as a massless, rigid rod.
66 class b2DistanceJoint : public b2Joint
70 b2Vec2 GetAnchor1() const;
71 b2Vec2 GetAnchor2() const;
73 b2Vec2 GetReactionForce() const;
74 float32 GetReactionTorque() const;
76 //--------------- Internals Below -------------------
78 b2DistanceJoint(const b2DistanceJointDef* data);
80 void InitVelocityConstraints(const b2TimeStep& step);
81 void SolveVelocityConstraints(const b2TimeStep& step);
82 bool SolvePositionConstraints();
84 b2Vec2 m_localAnchor1;
85 b2Vec2 m_localAnchor2;
87 float32 m_frequencyHz;
88 float32 m_dampingRatio;
92 float32 m_mass; // effective mass for the constraint.