您的位置:首页 > 移动开发 > Cocos引擎

cocos2d-x节点(b2PrismaticJoint.h)API

2013-11-28 21:20 423 查看
本文来自http://blog.csdn.net/runaying ,引用必须注明出处!


cocos2d-x节点(b2PrismaticJoint.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

//一个移动的joints(接头).这个 joints(接头)沿 body上面的一个轴运动

///cocos2d-x-3.0alpha0/external/Box2D/Dynamics/Joints
//一个移动的joints(接头). 这个 joints(接头)沿 body 上面的一个轴运动

#ifndef B2_PRISMATIC_JOINT_H
#define B2_PRISMATIC_JOINT_H

#include <Box2D/Dynamics/Joints/b2Joint.h>
/// Prismatic joints(接头)定义. 需要使用使用 一个轴和一个锚点 定义线的运动
//定义使用本地锚点和本地的轴,所以初始配置可以稍微违反约束
/// 当本地锚点和 world 空间里的锚点重合时,joints(接头)换算成 0。
//使用本地锚点和本地轴有助于保存和加载游戏时
struct b2PrismaticJointDef : public b2JointDef
{
b2PrismaticJointDef()
{
type = e_prismaticJoint;
localAnchorA.SetZero();
localAnchorB.SetZero();
localAxisA.Set(1.0f, 0.0f);
referenceAngle = 0.0f;
enableLimit = false;
lowerTranslation = 0.0f;
upperTranslation = 0.0f;
enableMotor = false;
maxMotorForce = 0.0f;
motorSpeed = 0.0f;
}

/// 初始化 bodies, anchors(锚点), axis(轴), and reference angle using the world
/// anchor(锚点 and unit 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;

/// 两个 bodies 之间的约束角度: bodyB_angle - bodyA_angle.
float32 referenceAngle;

/// Enable/disable the joint limit.
bool enableLimit;

/// The lower(底部) translation limit, usually in meters.      //通常以米为单位
float32 lowerTranslation;

/// The upper(上部) translation limit, usually in meters.
float32 upperTranslation;

/// Enable/disable the joints(接头) motor.        //电力
bool enableMotor;

/// motor 的最大扭矩 通常时 N-m
float32 maxMotorForce;

//    需要的motor 速度以 弧度/每秒 为单位
/// 期望的 motor 速度是 弧度每秒      //电机
float32 motorSpeed;
};

/// 一个移动的joints(接头). 这个 joints(接头)提供了一个自由度:沿固定在 bodyA 上面的轴换算. 防止相对转动 。你可以使用 joints(接头)限制,来约束运动范围。
// joints(接头)motor 来驱动运动,或模拟 joints(接头)摩擦       //电机
class b2PrismaticJoint : public b2Joint
{
public:
b2Vec2 GetAnchorA() const;
b2Vec2 GetAnchorB() const;

b2Vec2 GetReactionForce(float32 inv_dt) const;
float32 GetReactionTorque(float32 inv_dt) const;

/// 相对bodyB 原点的本地锚点
const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }

/// 相对bodyB 原点的本地锚点
const b2Vec2& GetLocalAnchorB() const  { return m_localAnchorB; }

/// 相对于 bodyA 的局部joints(接头)轴.
const b2Vec2& GetLocalAxisA() const { return m_localXAxisA; }

/// Get 参考角度.
float32 GetReferenceAngle() const { return m_referenceAngle; }

/// Get 当前 joints(接头) 换算, usually in meters.        //通常以米为单位
float32 GetJointTranslation() const;

/// Get 当前 joints(接头)换算速度d,通常 米每秒.
float32 GetJointSpeed() const;

/// joints(接头)限制是否启用?
bool IsLimitEnabled() const;

/// Enable/disable the joints(接头) limit.
void EnableLimit(bool flag);

/// Get the lower(底部) joint limit, usually in meters.       //通常以米为单位
float32 GetLowerLimit() const;

/// Get the upper(上部) joint limit, usually in meters.
float32 GetUpperLimit() const;

/// Set the joints(接头)限制, usually in meters.
void SetLimits(float32 lower, float32 upper);

///  joints(接头) motor 是否启用         //电机
bool IsMotorEnabled() const;

/// Enable/disable the joints(接头) motor.    //电机
void EnableMotor(bool flag);

/// Set motor 速度,通常单位为米每秒       //电机
void SetMotorSpeed(float32 speed);

/// Get motor 速度,通常单位为米每秒       //电机
float32 GetMotorSpeed() const;

/// Set 获取最大的 motor 力, 通常以牛顿为单位.
void SetMaxMotorForce(float32 force);
float32 GetMaxMotorForce() const { return m_maxMotorForce; }

/// 逆转时间步获取当前 motor 力 ,通常以牛顿为单位        //电机
float32 GetMotorForce(float32 inv_dt) const;

/// 把阻尼输出到 b2Log
void Dump();

protected:
friend class b2Joint;
friend class b2GearJoint;
b2PrismaticJoint(const b2PrismaticJointDef* def);

void InitVelocityConstraints(const b2SolverData& data);
void SolveVelocityConstraints(const b2SolverData& data);
bool SolvePositionConstraints(const b2SolverData& data);

// Solver shared
b2Vec2 m_localAnchorA;
b2Vec2 m_localAnchorB;
b2Vec2 m_localXAxisA;
b2Vec2 m_localYAxisA;
float32 m_referenceAngle;
b2Vec3 m_impulse;
float32 m_motorImpulse;
float32 m_lowerTranslation;
float32 m_upperTranslation;
float32 m_maxMotorForce;
float32 m_motorSpeed;
bool m_enableLimit;
bool m_enableMotor;
b2LimitState m_limitState;

// 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_axis, m_perp;
float32 m_s1, m_s2;
float32 m_a1, m_a2;
b2Mat33 m_K;
float32 m_motorMass;
};

inline float32 b2PrismaticJoint::GetMotorSpeed() const
{
return m_motorSpeed;
}

#endif
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: