b2WheelJoint.h
Go to the documentation of this file.
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_WHEEL_JOINT_H
00020 #define B2_WHEEL_JOINT_H
00021 
00022 #include <Box2D/Dynamics/Joints/b2Joint.h>
00023 
00030 struct b2WheelJointDef : public b2JointDef
00031 {
00032         b2WheelJointDef()
00033         {
00034                 type = e_wheelJoint;
00035                 localAnchorA.SetZero();
00036                 localAnchorB.SetZero();
00037                 localAxisA.Set(1.0f, 0.0f);
00038                 enableMotor = false;
00039                 maxMotorTorque = 0.0f;
00040                 motorSpeed = 0.0f;
00041                 frequencyHz = 2.0f;
00042                 dampingRatio = 0.7f;
00043         }
00044 
00047         void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis);
00048 
00050         b2Vec2 localAnchorA;
00051 
00053         b2Vec2 localAnchorB;
00054 
00056         b2Vec2 localAxisA;
00057 
00059         bool enableMotor;
00060 
00062         float32 maxMotorTorque;
00063 
00065         float32 motorSpeed;
00066 
00068         float32 frequencyHz;
00069 
00071         float32 dampingRatio;
00072 };
00073 
00078 class b2WheelJoint : public b2Joint
00079 {
00080 public:
00081         b2Vec2 GetAnchorA() const;
00082         b2Vec2 GetAnchorB() const;
00083 
00084         b2Vec2 GetReactionForce(float32 inv_dt) const;
00085         float32 GetReactionTorque(float32 inv_dt) const;
00086 
00088         const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
00089 
00091         const b2Vec2& GetLocalAnchorB() const  { return m_localAnchorB; }
00092 
00094         const b2Vec2& GetLocalAxisA() const { return m_localXAxisA; }
00095 
00097         float32 GetJointTranslation() const;
00098 
00100         float32 GetJointSpeed() const;
00101 
00103         bool IsMotorEnabled() const;
00104 
00106         void EnableMotor(bool flag);
00107 
00109         void SetMotorSpeed(float32 speed);
00110 
00112         float32 GetMotorSpeed() const;
00113 
00115         void SetMaxMotorTorque(float32 torque);
00116         float32 GetMaxMotorTorque() const;
00117 
00119         float32 GetMotorTorque(float32 inv_dt) const;
00120 
00122         void SetSpringFrequencyHz(float32 hz);
00123         float32 GetSpringFrequencyHz() const;
00124 
00126         void SetSpringDampingRatio(float32 ratio);
00127         float32 GetSpringDampingRatio() const;
00128 
00130         void Dump();
00131 
00132 protected:
00133 
00134         friend class b2Joint;
00135         b2WheelJoint(const b2WheelJointDef* def);
00136 
00137         void InitVelocityConstraints(const b2SolverData& data);
00138         void SolveVelocityConstraints(const b2SolverData& data);
00139         bool SolvePositionConstraints(const b2SolverData& data);
00140 
00141         float32 m_frequencyHz;
00142         float32 m_dampingRatio;
00143 
00144         // Solver shared
00145         b2Vec2 m_localAnchorA;
00146         b2Vec2 m_localAnchorB;
00147         b2Vec2 m_localXAxisA;
00148         b2Vec2 m_localYAxisA;
00149 
00150         float32 m_impulse;
00151         float32 m_motorImpulse;
00152         float32 m_springImpulse;
00153 
00154         float32 m_maxMotorTorque;
00155         float32 m_motorSpeed;
00156         bool m_enableMotor;
00157 
00158         // Solver temp
00159         int32 m_indexA;
00160         int32 m_indexB;
00161         b2Vec2 m_localCenterA;
00162         b2Vec2 m_localCenterB;
00163         float32 m_invMassA;
00164         float32 m_invMassB;
00165         float32 m_invIA;
00166         float32 m_invIB;
00167 
00168         b2Vec2 m_ax, m_ay;
00169         float32 m_sAx, m_sBx;
00170         float32 m_sAy, m_sBy;
00171 
00172         float32 m_mass;
00173         float32 m_motorMass;
00174         float32 m_springMass;
00175 
00176         float32 m_bias;
00177         float32 m_gamma;
00178 };
00179 
00180 inline float32 b2WheelJoint::GetMotorSpeed() const
00181 {
00182         return m_motorSpeed;
00183 }
00184 
00185 inline float32 b2WheelJoint::GetMaxMotorTorque() const
00186 {
00187         return m_maxMotorTorque;
00188 }
00189 
00190 inline void b2WheelJoint::SetSpringFrequencyHz(float32 hz)
00191 {
00192         m_frequencyHz = hz;
00193 }
00194 
00195 inline float32 b2WheelJoint::GetSpringFrequencyHz() const
00196 {
00197         return m_frequencyHz;
00198 }
00199 
00200 inline void b2WheelJoint::SetSpringDampingRatio(float32 ratio)
00201 {
00202         m_dampingRatio = ratio;
00203 }
00204 
00205 inline float32 b2WheelJoint::GetSpringDampingRatio() const
00206 {
00207         return m_dampingRatio;
00208 }
00209 
00210 #endif


mvsim
Author(s):
autogenerated on Thu Sep 7 2017 09:27:48