![]() |
Box2D
2.2.0
A 2D Physics Engine for Games
|
00001 /* 00002 * Copyright (c) 2006-2011 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_GEAR_JOINT_H 00020 #define B2_GEAR_JOINT_H 00021 00022 #include <Box2D/Dynamics/Joints/b2Joint.h> 00023 00026 struct b2GearJointDef : public b2JointDef 00027 { 00028 b2GearJointDef() 00029 { 00030 type = e_gearJoint; 00031 joint1 = NULL; 00032 joint2 = NULL; 00033 ratio = 1.0f; 00034 } 00035 00037 b2Joint* joint1; 00038 00040 b2Joint* joint2; 00041 00044 float32 ratio; 00045 }; 00046 00056 class b2GearJoint : public b2Joint 00057 { 00058 public: 00059 b2Vec2 GetAnchorA() const; 00060 b2Vec2 GetAnchorB() const; 00061 00062 b2Vec2 GetReactionForce(float32 inv_dt) const; 00063 float32 GetReactionTorque(float32 inv_dt) const; 00064 00066 void SetRatio(float32 ratio); 00067 float32 GetRatio() const; 00068 00069 protected: 00070 00071 friend class b2Joint; 00072 b2GearJoint(const b2GearJointDef* data); 00073 00074 void InitVelocityConstraints(const b2SolverData& data); 00075 void SolveVelocityConstraints(const b2SolverData& data); 00076 bool SolvePositionConstraints(const b2SolverData& data); 00077 00078 b2JointType m_typeA; 00079 b2JointType m_typeB; 00080 00081 // Body A is connected to body C 00082 // Body B is connected to body D 00083 b2Body* m_bodyC; 00084 b2Body* m_bodyD; 00085 00086 // Solver shared 00087 b2Vec2 m_localAnchorA; 00088 b2Vec2 m_localAnchorB; 00089 b2Vec2 m_localAnchorC; 00090 b2Vec2 m_localAnchorD; 00091 00092 b2Vec2 m_localAxisC; 00093 b2Vec2 m_localAxisD; 00094 00095 float32 m_referenceAngleA; 00096 float32 m_referenceAngleB; 00097 00098 float32 m_constant; 00099 float32 m_ratio; 00100 00101 float32 m_impulse; 00102 00103 // Solver temp 00104 int32 m_indexA, m_indexB, m_indexC, m_indexD; 00105 b2Vec2 m_lcA, m_lcB, m_lcC, m_lcD; 00106 float32 m_mA, m_mB, m_mC, m_mD; 00107 float32 m_iA, m_iB, m_iC, m_iD; 00108 b2Vec2 m_JvAC, m_JvBD; 00109 float32 m_JwA, m_JwB, m_JwC, m_JwD; 00110 float32 m_mass; 00111 }; 00112 00113 #endif