b2DistanceJoint.h
Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
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 
00058         float32 frequencyHz;
00059 
00061         float32 dampingRatio;
00062 };
00063 
00067 class b2DistanceJoint : public b2Joint
00068 {
00069 public:
00070 
00071         b2Vec2 GetAnchorA() const;
00072         b2Vec2 GetAnchorB() const;
00073 
00076         b2Vec2 GetReactionForce(float32 inv_dt) const;
00077 
00080         float32 GetReactionTorque(float32 inv_dt) const;
00081 
00083         const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
00084 
00086         const b2Vec2& GetLocalAnchorB() const  { return m_localAnchorB; }
00087 
00090         void SetLength(float32 length);
00091         float32 GetLength() const;
00092 
00094         void SetFrequency(float32 hz);
00095         float32 GetFrequency() const;
00096 
00098         void SetDampingRatio(float32 ratio);
00099         float32 GetDampingRatio() const;
00100 
00102         void Dump();
00103 
00104 protected:
00105 
00106         friend class b2Joint;
00107         b2DistanceJoint(const b2DistanceJointDef* data);
00108 
00109         void InitVelocityConstraints(const b2SolverData& data);
00110         void SolveVelocityConstraints(const b2SolverData& data);
00111         bool SolvePositionConstraints(const b2SolverData& data);
00112 
00113         float32 m_frequencyHz;
00114         float32 m_dampingRatio;
00115         float32 m_bias;
00116 
00117         // Solver shared
00118         b2Vec2 m_localAnchorA;
00119         b2Vec2 m_localAnchorB;
00120         float32 m_gamma;
00121         float32 m_impulse;
00122         float32 m_length;
00123 
00124         // Solver temp
00125         int32 m_indexA;
00126         int32 m_indexB;
00127         b2Vec2 m_u;
00128         b2Vec2 m_rA;
00129         b2Vec2 m_rB;
00130         b2Vec2 m_localCenterA;
00131         b2Vec2 m_localCenterB;
00132         float32 m_invMassA;
00133         float32 m_invMassB;
00134         float32 m_invIA;
00135         float32 m_invIB;
00136         float32 m_mass;
00137 };
00138 
00139 inline void b2DistanceJoint::SetLength(float32 length)
00140 {
00141         m_length = length;
00142 }
00143 
00144 inline float32 b2DistanceJoint::GetLength() const
00145 {
00146         return m_length;
00147 }
00148 
00149 inline void b2DistanceJoint::SetFrequency(float32 hz)
00150 {
00151         m_frequencyHz = hz;
00152 }
00153 
00154 inline float32 b2DistanceJoint::GetFrequency() const
00155 {
00156         return m_frequencyHz;
00157 }
00158 
00159 inline void b2DistanceJoint::SetDampingRatio(float32 ratio)
00160 {
00161         m_dampingRatio = ratio;
00162 }
00163 
00164 inline float32 b2DistanceJoint::GetDampingRatio() const
00165 {
00166         return m_dampingRatio;
00167 }
00168 
00169 #endif


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 22:08:34