Box2D: Box2D/Box2D/Dynamics/Joints/b2GearJoint.h Source File

- Main Page
- Classes
- Files

- File List
- File Members

# Box2D/Box2D/Dynamics/Joints/b2GearJoint.h

Go to the documentation of this file.

    00001 /*
    00002 * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
    00003 *
    00004 * This software is provided 'as-is', without any express or implied
    00005 * warranty.  In no event will the authors be held liable for any damages
    00006 * arising from the use of this software.
    00007 * Permission is granted to anyone to use this software for any purpose,
    00008 * including commercial applications, and to alter it and redistribute it
    00009 * freely, subject to the following restrictions:
    00010 * 1. The origin of this software must not be misrepresented; you must not
    00011 * claim that you wrote the original software. If you use this software
    00012 * in a product, an acknowledgment in the product documentation would be
    00013 * appreciated but is not required.
    00014 * 2. Altered source versions must be plainly marked as such, and must not be
    00015 * misrepresented as being the original software.
    00016 * 3. This notice may not be removed or altered from any source distribution.
    00017 */
    00018
    00019 #ifndef B2_GEAR_JOINT_H
    00020 #define B2_GEAR_JOINT_H
    00021
    00022 #include <Box2D/Dynamics/Joints/b2Joint.h>
    00023
    00024 class b2RevoluteJoint;
    00025 class b2PrismaticJoint;
    00026
    00030 struct b2GearJointDef : public b2JointDef
    00031 {
    00032         b2GearJointDef()
    00033         {
    00034                 type = e_gearJoint;
    00035                 joint1 = NULL;
    00036                 joint2 = NULL;
    00037                 ratio = 1.0f;
    00038         }
    00039
    00041         b2Joint* joint1;
    00042
    00044         b2Joint* joint2;
    00045
    00048         float32 ratio;
    00049 };
    00050
    00060 class b2GearJoint : public b2Joint
    00061 {
    00062 public:
    00063         b2Vec2 GetAnchorA() const;
    00064         b2Vec2 GetAnchorB() const;
    00065
    00066         b2Vec2 GetReactionForce(float32 inv_dt) const;
    00067         float32 GetReactionTorque(float32 inv_dt) const;
    00068
    00070         void SetRatio(float32 ratio);
    00071         float32 GetRatio() const;
    00072
    00073 protected:
    00074
    00075         friend class b2Joint;
    00076         b2GearJoint(const b2GearJointDef* data);
    00077
    00078         void InitVelocityConstraints(const b2TimeStep& step);
    00079         void SolveVelocityConstraints(const b2TimeStep& step);
    00080         bool SolvePositionConstraints(float32 baumgarte);
    00081
    00082         b2Body* m_ground1;
    00083         b2Body* m_ground2;
    00084
    00085         // One of these is NULL.
    00086         b2RevoluteJoint* m_revolute1;
    00087         b2PrismaticJoint* m_prismatic1;
    00088
    00089         // One of these is NULL.
    00090         b2RevoluteJoint* m_revolute2;
    00091         b2PrismaticJoint* m_prismatic2;
    00092
    00093         b2Vec2 m_groundAnchor1;
    00094         b2Vec2 m_groundAnchor2;
    00095
    00096         b2Vec2 m_localAnchor1;
    00097         b2Vec2 m_localAnchor2;
    00098
    00099         b2Jacobian m_J;
    00100
    00101         float32 m_constant;
    00102         float32 m_ratio;
    00103
    00104         // Effective mass
    00105         float32 m_mass;
    00106
    00107         // Impulse for accumulation/warm starting.
    00108         float32 m_impulse;
    00109 };
    00110
    00111 #endif