本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
/// 一个Wheel(车轮)joints(接头)这个 joints(接头)提供了两个自由度:沿固定在 bodyA上的轴和平面旋转
///cocos2d-x-3.0alpha0/external/Box2D/Dynamics/Joints /// 一个Wheel(车轮)joints(接头)这个 joints(接头)提供了两个自由度:沿固定在 bodyA上的轴和平面旋转 #ifndef B2_WHEEL_JOINT_H #define B2_WHEEL_JOINT_H #include <Box2D/Dynamics/Joints/b2Joint.h> /// Wheel(车轮)joints(接头)定义. 这个定义需要 运动的线使用的轴和锚点 /// 定义使用本地锚点和本地轴,所以初始配置可以稍微违反约束。 /// 当本地锚点和 world 空间里的锚点重合时,joints(接头)换算成 0。 //使用本地锚点和本地轴有助于保存和加载游戏时 struct b2WheelJointDef : public b2JointDef { b2WheelJointDef() { type = e_wheelJoint; localAnchorA.SetZero(); localAnchorB.SetZero(); localAxisA.Set(1.0f, 0.0f); enableMotor = false; maxMotorTorque = 0.0f; motorSpeed = 0.0f; frequencyHz = 2.0f; dampingRatio = 0.7f; } /// Initialize the bodies, anchors, axis, and reference angle using the world /// anchor and world axis. void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis); /// 相对与 bodyA's 原点本地锚点. b2Vec2 localAnchorA; /// 相对与 bodyB's 原点的本地锚点. b2Vec2 localAnchorB; /// bodyA 上面的本地换算轴. b2Vec2 localAxisA; /// Enable/disable the joint motor. bool enableMotor; /// The maximum motor torque(力矩), usually in N-m. //电机 float32 maxMotorTorque; /// The desired(期望的) motor speed in radians per second. //电机 float32 motorSpeed; /// Suspension frequency, zero indicates no suspension //悬浮频率,零表示没有悬浮 float32 frequencyHz; /// Suspension damping ratio, one indicates critical damping //悬浮阻尼比,一表示临界阻尼 float32 dampingRatio; }; /// 一个Wheel(车轮)joints(接头)这个 joints(接头)提供了两个自由度:沿固定在 bodyA上的轴和平面旋转 /// 你可以使用joints(接头)来限制运动的摩擦范围,一个joints(接头)motor 来驱动旋转或者旋转摩擦模型 //电机 /// 这个 joint(接头)是为 Wheel(车轮)的悬浮而设计的 class b2WheelJoint : public b2Joint { public: void GetDefinition(b2WheelJointDef* def) const; b2Vec2 GetAnchorA() const; b2Vec2 GetAnchorB() const; b2Vec2 GetReactionForce(float32 inv_dt) const; float32 GetReactionTorque(float32 inv_dt) const; /// 相对与 bodyA's 的原点本地锚点. const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; } /// 相对与 bodyB's 原点的本地锚点. const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; } /// bodyA 上面的本地换算轴. const b2Vec2& GetLocalAxisA() const { return m_localXAxisA; } /// Get the current joint translation(换算), usually in meters. float32 GetJointTranslation() const; /// Get the current joint translation(换算) speed, usually in meters per second. float32 GetJointSpeed() const; /// Is the joint motor enabled? //电机 bool IsMotorEnabled() const; /// Enable/disable the joint motor. void EnableMotor(bool flag); /// Set the motor speed, usually in radians per second. //电机 void SetMotorSpeed(float32 speed); /// Get the motor speed, usually in radians per second. //电机 float32 GetMotorSpeed() const; /// Set/Get the maximum motor force(力), usually in N-m. //电机 void SetMaxMotorTorque(float32 torque); float32 GetMaxMotorTorque() const; /// Get the current motor torque given the inverse time step, usually in N-m. //逆转时间步获取当前 motor 力 //电机 float32 GetMotorTorque(float32 inv_dt) const; /// Set/Get the spring frequency in hertz. Setting the frequency to zero disables the spring. //弹簧的频率,单位为赫兹。频率设定为零禁用弹性 void SetSpringFrequencyHz(float32 hz); float32 GetSpringFrequencyHz() const; /// Set/Get the spring damping ratio //弹簧阻尼系数 void SetSpringDampingRatio(float32 ratio); float32 GetSpringDampingRatio() const; ///把阻尼输出到 b2Log. void Dump(); protected: friend class b2Joint; b2WheelJoint(const b2WheelJointDef* def); void InitVelocityConstraints(const b2SolverData& data); void SolveVelocityConstraints(const b2SolverData& data); bool SolvePositionConstraints(const b2SolverData& data); float32 m_frequencyHz; float32 m_dampingRatio; // Solver shared b2Vec2 m_localAnchorA; b2Vec2 m_localAnchorB; b2Vec2 m_localXAxisA; b2Vec2 m_localYAxisA; float32 m_impulse; float32 m_motorImpulse; float32 m_springImpulse; float32 m_maxMotorTorque; float32 m_motorSpeed; bool m_enableMotor; // Solver temp int32 m_indexA; int32 m_indexB; b2Vec2 m_localCenterA; b2Vec2 m_localCenterB; float32 m_invMassA; float32 m_invMassB; float32 m_invIA; float32 m_invIB; b2Vec2 m_ax, m_ay; float32 m_sAx, m_sBx; float32 m_sAy, m_sBy; float32 m_mass; float32 m_motorMass; float32 m_springMass; float32 m_bias; float32 m_gamma; }; inline float32 b2WheelJoint::GetMotorSpeed() const { return m_motorSpeed; } inline float32 b2WheelJoint::GetMaxMotorTorque() const { return m_maxMotorTorque; } inline void b2WheelJoint::SetSpringFrequencyHz(float32 hz) { m_frequencyHz = hz; } inline float32 b2WheelJoint::GetSpringFrequencyHz() const { return m_frequencyHz; } inline void b2WheelJoint::SetSpringDampingRatio(float32 ratio) { m_dampingRatio = ratio; } inline float32 b2WheelJoint::GetSpringDampingRatio() const { return m_dampingRatio; } #endif