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_GEAR_JOINT_H
20 #define B2_GEAR_JOINT_H
24 class b2RevoluteJoint;
25 class b2PrismaticJoint;
27 /// Gear joint definition. This definition requires two existing
28 /// revolute or prismatic joints (any combination will work).
29 /// The provided joints must attach a dynamic body to a static body.
30 struct b2GearJointDef : public b2JointDef
40 /// The first revolute/prismatic joint attached to the gear joint.
43 /// The second revolute/prismatic joint attached to the gear joint.
47 /// @see b2GearJoint for explanation.
51 /// A gear joint is used to connect two joints together. Either joint
52 /// can be a revolute or prismatic joint. You specify a gear ratio
53 /// to bind the motions together:
54 /// coordinate1 + ratio * coordinate2 = constant
55 /// The ratio can be negative or positive. If one joint is a revolute joint
56 /// and the other joint is a prismatic joint, then the ratio will have units
57 /// of length or units of 1/length.
58 /// @warning The revolute and prismatic joints must be attached to
59 /// fixed bodies (which must be body1 on those joints).
60 class b2GearJoint : public b2Joint
63 b2Vec2 GetAnchor1() const;
64 b2Vec2 GetAnchor2() const;
66 b2Vec2 GetReactionForce() const;
67 float32 GetReactionTorque() const;
69 /// Get the gear ratio.
70 float32 GetRatio() const;
72 //--------------- Internals Below -------------------
74 b2GearJoint(const b2GearJointDef* data);
76 void InitVelocityConstraints(const b2TimeStep& step);
77 void SolveVelocityConstraints(const b2TimeStep& step);
78 bool SolvePositionConstraints();
83 // One of these is NULL.
84 b2RevoluteJoint* m_revolute1;
85 b2PrismaticJoint* m_prismatic1;
87 // One of these is NULL.
88 b2RevoluteJoint* m_revolute2;
89 b2PrismaticJoint* m_prismatic2;
91 b2Vec2 m_groundAnchor1;
92 b2Vec2 m_groundAnchor2;
94 b2Vec2 m_localAnchor1;
95 b2Vec2 m_localAnchor2;
105 // Impulse for accumulation/warm starting.