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

- Main Page
- Classes
- Files

- File List
- File Members

# Box2D/Box2D/Dynamics/Joints/b2LineJoint.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_LINE_JOINT_H
    00020 #define B2_LINE_JOINT_H
    00021
    00022 #include <Box2D/Dynamics/Joints/b2Joint.h>
    00023
    00030 struct b2LineJointDef : public b2JointDef
    00031 {
    00032         b2LineJointDef()
    00033         {
    00034                 type = e_lineJoint;
    00035                 localAnchorA.SetZero();
    00036                 localAnchorB.SetZero();
    00037                 localAxisA.Set(1.0f, 0.0f);
    00038                 enableLimit = false;
    00039                 lowerTranslation = 0.0f;
    00040                 upperTranslation = 0.0f;
    00041                 enableMotor = false;
    00042                 maxMotorForce = 0.0f;
    00043                 motorSpeed = 0.0f;
    00044         }
    00045
    00048         void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis);
    00049
    00051         b2Vec2 localAnchorA;
    00052
    00054         b2Vec2 localAnchorB;
    00055
    00057         b2Vec2 localAxisA;
    00058
    00060         bool enableLimit;
    00061
    00063         float32 lowerTranslation;
    00064
    00066         float32 upperTranslation;
    00067
    00069         bool enableMotor;
    00070
    00072         float32 maxMotorForce;
    00073
    00075         float32 motorSpeed;
    00076 };
    00077
    00082 class b2LineJoint : public b2Joint
    00083 {
    00084 public:
    00085         b2Vec2 GetAnchorA() const;
    00086         b2Vec2 GetAnchorB() const;
    00087
    00088         b2Vec2 GetReactionForce(float32 inv_dt) const;
    00089         float32 GetReactionTorque(float32 inv_dt) const;
    00090
    00092         float32 GetJointTranslation() const;
    00093
    00095         float32 GetJointSpeed() const;
    00096
    00098         bool IsLimitEnabled() const;
    00099
    00101         void EnableLimit(bool flag);
    00102
    00104         float32 GetLowerLimit() const;
    00105
    00107         float32 GetUpperLimit() const;
    00108
    00110         void SetLimits(float32 lower, float32 upper);
    00111
    00113         bool IsMotorEnabled() const;
    00114
    00116         void EnableMotor(bool flag);
    00117
    00119         void SetMotorSpeed(float32 speed);
    00120
    00122         float32 GetMotorSpeed() const;
    00123
    00125         void SetMaxMotorForce(float32 force);
    00126         float32 GetMaxMotorForce() const;
    00127
    00129         float32 GetMotorForce() const;
    00130
    00131 protected:
    00132
    00133         friend class b2Joint;
    00134         b2LineJoint(const b2LineJointDef* def);
    00135
    00136         void InitVelocityConstraints(const b2TimeStep& step);
    00137         void SolveVelocityConstraints(const b2TimeStep& step);
    00138         bool SolvePositionConstraints(float32 baumgarte);
    00139
    00140         b2Vec2 m_localAnchor1;
    00141         b2Vec2 m_localAnchor2;
    00142         b2Vec2 m_localXAxis1;
    00143         b2Vec2 m_localYAxis1;
    00144
    00145         b2Vec2 m_axis, m_perp;
    00146         float32 m_s1, m_s2;
    00147         float32 m_a1, m_a2;
    00148
    00149         b2Mat22 m_K;
    00150         b2Vec2 m_impulse;
    00151
    00152         float32 m_motorMass;                    // effective mass for motor/limit translational constraint.
    00153         float32 m_motorImpulse;
    00154
    00155         float32 m_lowerTranslation;
    00156         float32 m_upperTranslation;
    00157         float32 m_maxMotorForce;
    00158         float32 m_motorSpeed;
    00159
    00160         bool m_enableLimit;
    00161         bool m_enableMotor;
    00162         b2LimitState m_limitState;
    00163 };
    00164
    00165 inline float32 b2LineJoint::GetMotorSpeed() const
    00166 {
    00167         return m_motorSpeed;
    00168 }
    00169
    00170 #endif