本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
cocos2d-x节点(b2Joint.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
// joints(接头)的基类.joints(接头)用来约束两个不同类型的 body .
///cocos2d-x-3.0alpha0/external/Box2D/Dynamics/Joints
// joints(接头)的基类.joints(接头)用来约束两个不同类型的 body .
#ifndef B2_JOINT_H
#define B2_JOINT_H
#include <Box2D/Common/b2Math.h>
class b2Body;
class b2Joint;
struct b2SolverData;
class b2BlockAllocator;
enum b2JointType
{
e_unknownJoint,
e_revoluteJoint,
e_prismaticJoint,
e_distanceJoint,
e_pulleyJoint,
e_mouseJoint,
e_gearJoint,
e_wheelJoint,
e_weldJoint,
e_frictionJoint,
e_ropeJoint
};
enum b2LimitState
{
e_inactiveLimit,
e_atLowerLimit,
e_atUpperLimit,
e_equalLimits
};
struct b2Jacobian
{
b2Vec2 linear;
float32 angularA;
float32 angularB;
};
// joints(接头)的边缘用于连接 bodies,并添加到 joints(接头)图表,这个表里面有每一个 body 对应的 joints(接头)边缘
//接触范围,属于一个连接到 body 的双向链表
///每一个接触都有两个接触点,一个连接到它们的 body
struct b2JointEdge
{
b2Body* other; ///< 供其它 body 快速访问
b2Joint* joint; ///< the joint
b2JointEdge* prev; ///< body's joints(接头)列表中的上一个 joints(接头)的边缘
b2JointEdge* next; ///< body's joints(接头)列表中的下一个 joints(接头)的边缘
};
/// 定义 Joint 用与构建 joints(接头)
struct b2JointDef
{
b2JointDef()
{
type = e_unknownJoint;
userData = NULL;
bodyA = NULL;
bodyB = NULL;
collideConnected = false;
}
/// 这个 joints(接头)类型是根据确切的 joints(接头)类型自动设置的
b2JointType type;
/// 使用这个关联应用特定的数据到你的 joints(接头)
void* userData;
/// The first attached body. //关联
b2Body* bodyA;
/// The second attached body.
b2Body* bodyB;
/// 如果关联的bodies 应该碰撞,这个标志设置为true
bool collideConnected;
};
/// joints(接头)的基类.joints(接头)用来约束两个不同类型的 body .一些特点受 motors(电力)限制.
class b2Joint
{
public:
/// Get 具体的 joint(接头)类型.
b2JointType GetType() const;
/// 获取第一个 body关联到这个 joints(接头)
b2Body* GetBodyA();
// 获取第二个 body关联到这个 joints(接头)
b2Body* GetBodyB();
/// Get bodyA 的锚点的 world 坐标
virtual b2Vec2 GetAnchorA() const = 0;
/// Get bodyB 的锚点的 world 坐标
virtual b2Vec2 GetAnchorB() const = 0;
// Get bodyB 的反作用力,再joints(接头)的锚点上(以牛顿为单位)
virtual b2Vec2 GetReactionForce(float32 inv_dt) const = 0;
/// Get bodyB上的相反力矩 N*m.
virtual float32 GetReactionTorque(float32 inv_dt) const = 0;
/// Get world joints(接头)列表里面的下一个 joint
b2Joint* GetNext();
const b2Joint* GetNext() const;
/// Get the user data pointer.
void* GetUserData() const;
/// Set the user data pointer.
void SetUserData(void* data);
/// 判断 Short-cut 功能 (body 是无效的)
bool IsActive() const;
/// 获得碰撞连接。
/// Note: 修改碰撞连接标志将无法正常工作,应为当 fixture(定制器)AABBs 开始重叠时,只有这个标识才能被检测
bool GetCollideConnected() const;
/// 把joints(接头)的阻尼输出到 log file.
virtual void Dump() { b2Log("// Dump is not supported for this joint type.\n"); }
protected:
friend class b2World;
friend class b2Body;
friend class b2Island;
friend class b2GearJoint;
static b2Joint* Create(const b2JointDef* def, b2BlockAllocator* allocator);
static void Destroy(b2Joint* joint, b2BlockAllocator* allocator);
b2Joint(const b2JointDef* def);
virtual ~b2Joint() {}
virtual void InitVelocityConstraints(const b2SolverData& data) = 0;
virtual void SolveVelocityConstraints(const b2SolverData& data) = 0;
// This returns true 如果位置误差在容差范围内.
virtual bool SolvePositionConstraints(const b2SolverData& data) = 0;
b2JointType m_type;
b2Joint* m_prev;
b2Joint* m_next;
b2JointEdge m_edgeA;
b2JointEdge m_edgeB;
b2Body* m_bodyA;
b2Body* m_bodyB;
int32 m_index;
bool m_islandFlag;
bool m_collideConnected;
void* m_userData;
};
inline b2JointType b2Joint::GetType() const
{
return m_type;
}
inline b2Body* b2Joint::GetBodyA()
{
return m_bodyA;
}
inline b2Body* b2Joint::GetBodyB()
{
return m_bodyB;
}
inline b2Joint* b2Joint::GetNext()
{
return m_next;
}
inline const b2Joint* b2Joint::GetNext() const
{
return m_next;
}
inline void* b2Joint::GetUserData() const
{
return m_userData;
}
inline void b2Joint::SetUserData(void* data)
{
m_userData = data;
}
inline bool b2Joint::GetCollideConnected() const
{
return m_collideConnected;
}
#endif