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_REVOLUTE_JOINT_H 00020 #define B2_REVOLUTE_JOINT_H 00021 00022 #include <Box2D/Dynamics/Joints/b2Joint.h> 00023 00035 struct b2RevoluteJointDef : public b2JointDef 00036 { 00037 b2RevoluteJointDef() 00038 { 00039 type = e_revoluteJoint; 00040 localAnchorA.Set(0.0f, 0.0f); 00041 localAnchorB.Set(0.0f, 0.0f); 00042 referenceAngle = 0.0f; 00043 lowerAngle = 0.0f; 00044 upperAngle = 0.0f; 00045 maxMotorTorque = 0.0f; 00046 motorSpeed = 0.0f; 00047 enableLimit = false; 00048 enableMotor = false; 00049 } 00050 00053 void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor); 00054 00056 b2Vec2 localAnchorA; 00057 00059 b2Vec2 localAnchorB; 00060 00062 float32 referenceAngle; 00063 00065 bool enableLimit; 00066 00068 float32 lowerAngle; 00069 00071 float32 upperAngle; 00072 00074 bool enableMotor; 00075 00077 float32 motorSpeed; 00078 00081 float32 maxMotorTorque; 00082 }; 00083 00090 class b2RevoluteJoint : public b2Joint 00091 { 00092 public: 00093 b2Vec2 GetAnchorA() const; 00094 b2Vec2 GetAnchorB() const; 00095 00096 b2Vec2 GetReactionForce(float32 inv_dt) const; 00097 float32 GetReactionTorque(float32 inv_dt) const; 00098 00100 float32 GetJointAngle() const; 00101 00103 float32 GetJointSpeed() const; 00104 00106 bool IsLimitEnabled() const; 00107 00109 void EnableLimit(bool flag); 00110 00112 float32 GetLowerLimit() const; 00113 00115 float32 GetUpperLimit() const; 00116 00118 void SetLimits(float32 lower, float32 upper); 00119 00121 bool IsMotorEnabled() const; 00122 00124 void EnableMotor(bool flag); 00125 00127 void SetMotorSpeed(float32 speed); 00128 00130 float32 GetMotorSpeed() const; 00131 00133 void SetMaxMotorTorque(float32 torque); 00134 00136 float32 GetMotorTorque() const; 00137 00138 protected: 00139 00140 friend class b2Joint; 00141 friend class b2GearJoint; 00142 00143 b2RevoluteJoint(const b2RevoluteJointDef* def); 00144 00145 void InitVelocityConstraints(const b2TimeStep& step); 00146 void SolveVelocityConstraints(const b2TimeStep& step); 00147 00148 bool SolvePositionConstraints(float32 baumgarte); 00149 00150 b2Vec2 m_localAnchor1; // relative 00151 b2Vec2 m_localAnchor2; 00152 b2Vec3 m_impulse; 00153 float32 m_motorImpulse; 00154 00155 b2Mat33 m_mass; // effective mass for point-to-point constraint. 00156 float32 m_motorMass; // effective mass for motor/limit angular constraint. 00157 00158 bool m_enableMotor; 00159 float32 m_maxMotorTorque; 00160 float32 m_motorSpeed; 00161 00162 bool m_enableLimit; 00163 float32 m_referenceAngle; 00164 float32 m_lowerAngle; 00165 float32 m_upperAngle; 00166 b2LimitState m_limitState; 00167 }; 00168 00169 inline float32 b2RevoluteJoint::GetMotorSpeed() const 00170 { 00171 return m_motorSpeed; 00172 } 00173 00174 #endif