- Main Page
- Classes
- Files

- File List
- File Members

# Box2D/Box2D/Dynamics/Joints/b2DistanceJoint.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_DISTANCE_JOINT_H
    00020 #define B2_DISTANCE_JOINT_H
    00021
    00022 #include <Box2D/Dynamics/Joints/b2Joint.h>
    00023
    00030 struct b2DistanceJointDef : public b2JointDef
    00031 {
    00032         b2DistanceJointDef()
    00033         {
    00034                 type = e_distanceJoint;
    00035                 localAnchorA.Set(0.0f, 0.0f);
    00036                 localAnchorB.Set(0.0f, 0.0f);
    00037                 length = 1.0f;
    00038                 frequencyHz = 0.0f;
    00039                 dampingRatio = 0.0f;
    00040         }
    00041
    00044         void Initialize(b2Body* bodyA, b2Body* bodyB,
    00045                                         const b2Vec2& anchorA, const b2Vec2& anchorB);
    00046
    00048         b2Vec2 localAnchorA;
    00049
    00051         b2Vec2 localAnchorB;
    00052
    00054         float32 length;
    00055
    00057         float32 frequencyHz;
    00058
    00060         float32 dampingRatio;
    00061 };
    00062
    00066 class b2DistanceJoint : public b2Joint
    00067 {
    00068 public:
    00069
    00070         b2Vec2 GetAnchorA() const;
    00071         b2Vec2 GetAnchorB() const;
    00072
    00073         b2Vec2 GetReactionForce(float32 inv_dt) const;
    00074         float32 GetReactionTorque(float32 inv_dt) const;
    00075
    00078         void SetLength(float32 length);
    00079         float32 GetLength() const;
    00080
    00081         // Set/get frequency in Hz.
    00082         void SetFrequency(float32 hz);
    00083         float32 GetFrequency() const;
    00084
    00085         // Set/get damping ratio.
    00086         void SetDampingRatio(float32 ratio);
    00087         float32 GetDampingRatio() const;
    00088
    00089 protected:
    00090
    00091         friend class b2Joint;
    00092         b2DistanceJoint(const b2DistanceJointDef* data);
    00093
    00094         void InitVelocityConstraints(const b2TimeStep& step);
    00095         void SolveVelocityConstraints(const b2TimeStep& step);
    00096         bool SolvePositionConstraints(float32 baumgarte);
    00097
    00098         b2Vec2 m_localAnchor1;
    00099         b2Vec2 m_localAnchor2;
    00100         b2Vec2 m_u;
    00101         float32 m_frequencyHz;
    00102         float32 m_dampingRatio;
    00103         float32 m_gamma;
    00104         float32 m_bias;
    00105         float32 m_impulse;
    00106         float32 m_mass;
    00107         float32 m_length;
    00108 };
    00109
    00110 inline void b2DistanceJoint::SetLength(float32 length)
    00111 {
    00112         m_length = length;
    00113 }
    00114
    00115 inline float32 b2DistanceJoint::GetLength() const
    00116 {
    00117         return m_length;
    00118 }
    00119
    00120 inline void b2DistanceJoint::SetFrequency(float32 hz)
    00121 {
    00122         m_frequencyHz = hz;
    00123 }
    00124
    00125 inline float32 b2DistanceJoint::GetFrequency() const
    00126 {
    00127         return m_frequencyHz;
    00128 }
    00129
    00130 inline void b2DistanceJoint::SetDampingRatio(float32 ratio)
    00131 {
    00132         m_dampingRatio = ratio;
    00133 }
    00134
    00135 inline float32 b2DistanceJoint::GetDampingRatio() const
    00136 {
    00137         return m_dampingRatio;
    00138 }
    00139
    00140 #endif