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_PRISMATIC_JOINT_H 00020 #define B2_PRISMATIC_JOINT_H 00021 00022 #include <Box2D/Dynamics/Joints/b2Joint.h> 00023 00031 struct b2PrismaticJointDef : public b2JointDef 00032 { 00033 b2PrismaticJointDef() 00034 { 00035 type = e_prismaticJoint; 00036 localAnchorA.SetZero(); 00037 localAnchorB.SetZero(); 00038 localAxis1.Set(1.0f, 0.0f); 00039 referenceAngle = 0.0f; 00040 enableLimit = false; 00041 lowerTranslation = 0.0f; 00042 upperTranslation = 0.0f; 00043 enableMotor = false; 00044 maxMotorForce = 0.0f; 00045 motorSpeed = 0.0f; 00046 } 00047 00050 void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis); 00051 00053 b2Vec2 localAnchorA; 00054 00056 b2Vec2 localAnchorB; 00057 00059 b2Vec2 localAxis1; 00060 00062 float32 referenceAngle; 00063 00065 bool enableLimit; 00066 00068 float32 lowerTranslation; 00069 00071 float32 upperTranslation; 00072 00074 bool enableMotor; 00075 00077 float32 maxMotorForce; 00078 00080 float32 motorSpeed; 00081 }; 00082 00087 class b2PrismaticJoint : public b2Joint 00088 { 00089 public: 00090 b2Vec2 GetAnchorA() const; 00091 b2Vec2 GetAnchorB() const; 00092 00093 b2Vec2 GetReactionForce(float32 inv_dt) const; 00094 float32 GetReactionTorque(float32 inv_dt) const; 00095 00097 float32 GetJointTranslation() const; 00098 00100 float32 GetJointSpeed() const; 00101 00103 bool IsLimitEnabled() const; 00104 00106 void EnableLimit(bool flag); 00107 00109 float32 GetLowerLimit() const; 00110 00112 float32 GetUpperLimit() const; 00113 00115 void SetLimits(float32 lower, float32 upper); 00116 00118 bool IsMotorEnabled() const; 00119 00121 void EnableMotor(bool flag); 00122 00124 void SetMotorSpeed(float32 speed); 00125 00127 float32 GetMotorSpeed() const; 00128 00130 void SetMaxMotorForce(float32 force); 00131 00133 float32 GetMotorForce() const; 00134 00135 protected: 00136 friend class b2Joint; 00137 friend class b2GearJoint; 00138 b2PrismaticJoint(const b2PrismaticJointDef* def); 00139 00140 void InitVelocityConstraints(const b2TimeStep& step); 00141 void SolveVelocityConstraints(const b2TimeStep& step); 00142 bool SolvePositionConstraints(float32 baumgarte); 00143 00144 b2Vec2 m_localAnchor1; 00145 b2Vec2 m_localAnchor2; 00146 b2Vec2 m_localXAxis1; 00147 b2Vec2 m_localYAxis1; 00148 float32 m_refAngle; 00149 00150 b2Vec2 m_axis, m_perp; 00151 float32 m_s1, m_s2; 00152 float32 m_a1, m_a2; 00153 00154 b2Mat33 m_K; 00155 b2Vec3 m_impulse; 00156 00157 float32 m_motorMass; // effective mass for motor/limit translational constraint. 00158 float32 m_motorImpulse; 00159 00160 float32 m_lowerTranslation; 00161 float32 m_upperTranslation; 00162 float32 m_maxMotorForce; 00163 float32 m_motorSpeed; 00164 00165 bool m_enableLimit; 00166 bool m_enableMotor; 00167 b2LimitState m_limitState; 00168 }; 00169 00170 inline float32 b2PrismaticJoint::GetMotorSpeed() const 00171 { 00172 return m_motorSpeed; 00173 } 00174 00175 #endif