- Main Page
- Classes
- Files

- File List
- File Members

# Box2D/Box2D/Dynamics/Joints/b2PulleyJoint.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_PULLEY_JOINT_H
    00020 #define B2_PULLEY_JOINT_H
    00021
    00022 #include <Box2D/Dynamics/Joints/b2Joint.h>
    00023
    00024 const float32 b2_minPulleyLength = 2.0f;
    00025
    00029 struct b2PulleyJointDef : public b2JointDef
    00030 {
    00031         b2PulleyJointDef()
    00032         {
    00033                 type = e_pulleyJoint;
    00034                 groundAnchorA.Set(-1.0f, 1.0f);
    00035                 groundAnchorB.Set(1.0f, 1.0f);
    00036                 localAnchorA.Set(-1.0f, 0.0f);
    00037                 localAnchorB.Set(1.0f, 0.0f);
    00038                 lengthA = 0.0f;
    00039                 maxLengthA = 0.0f;
    00040                 lengthB = 0.0f;
    00041                 maxLengthB = 0.0f;
    00042                 ratio = 1.0f;
    00043                 collideConnected = true;
    00044         }
    00045
    00047         void Initialize(b2Body* bodyA, b2Body* bodyB,
    00048                                         const b2Vec2& groundAnchorA, const b2Vec2& groundAnchorB,
    00049                                         const b2Vec2& anchorA, const b2Vec2& anchorB,
    00050                                         float32 ratio);
    00051
    00053         b2Vec2 groundAnchorA;
    00054
    00056         b2Vec2 groundAnchorB;
    00057
    00059         b2Vec2 localAnchorA;
    00060
    00062         b2Vec2 localAnchorB;
    00063
    00065         float32 lengthA;
    00066
    00068         float32 maxLengthA;
    00069
    00071         float32 lengthB;
    00072
    00074         float32 maxLengthB;
    00075
    00077         float32 ratio;
    00078 };
    00079
    00086 class b2PulleyJoint : public b2Joint
    00087 {
    00088 public:
    00089         b2Vec2 GetAnchorA() const;
    00090         b2Vec2 GetAnchorB() const;
    00091
    00092         b2Vec2 GetReactionForce(float32 inv_dt) const;
    00093         float32 GetReactionTorque(float32 inv_dt) const;
    00094
    00096         b2Vec2 GetGroundAnchorA() const;
    00097
    00099         b2Vec2 GetGroundAnchorB() const;
    00100
    00102         float32 GetLength1() const;
    00103
    00105         float32 GetLength2() const;
    00106
    00108         float32 GetRatio() const;
    00109
    00110 protected:
    00111
    00112         friend class b2Joint;
    00113         b2PulleyJoint(const b2PulleyJointDef* data);
    00114
    00115         void InitVelocityConstraints(const b2TimeStep& step);
    00116         void SolveVelocityConstraints(const b2TimeStep& step);
    00117         bool SolvePositionConstraints(float32 baumgarte);
    00118
    00119         b2Vec2 m_groundAnchor1;
    00120         b2Vec2 m_groundAnchor2;
    00121         b2Vec2 m_localAnchor1;
    00122         b2Vec2 m_localAnchor2;
    00123
    00124         b2Vec2 m_u1;
    00125         b2Vec2 m_u2;
    00126
    00127         float32 m_constant;
    00128         float32 m_ratio;
    00129
    00130         float32 m_maxLength1;
    00131         float32 m_maxLength2;
    00132
    00133         // Effective masses
    00134         float32 m_pulleyMass;
    00135         float32 m_limitMass1;
    00136         float32 m_limitMass2;
    00137
    00138         // Impulses for accumulation/warm starting.
    00139         float32 m_impulse;
    00140         float32 m_limitImpulse1;
    00141         float32 m_limitImpulse2;
    00142
    00143         b2LimitState m_state;
    00144         b2LimitState m_limitState1;
    00145         b2LimitState m_limitState2;
    00146 };
    00147
    00148 #endif