本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
各种无力物理联合,别针、限制、联动、弹簧....等联合
///cocos2d-x-3.0alpha0/cocos2dx/physics //各种无力物理联合,别针、限制、联动、弹簧....等联合 #include "CCPhysicsSetting.h" #ifdef CC_USE_PHYSICS #ifndef __CCPHYSICS_JOINT_H__ #define __CCPHYSICS_JOINT_H__ #include "cocoa/CCObject.h" #include "cocoa/CCGeometry.h" NS_CC_BEGIN class PhysicsBody; class PhysicsJointInfo; class PhysicsBodyInfo; /* * @brief 一个PhysicsJoint对象连接两个物理机构. */ class PhysicsJoint : public Object { protected: PhysicsJoint(); virtual ~PhysicsJoint() = 0; public: PhysicsBody* getBodyA() { return _bodyA; } PhysicsBody* getBodyB() { return _bodyB; } protected: bool init(PhysicsBody* a, PhysicsBody* b); /** * PhysicsShape 是 PhysicsBody's 的朋友类, 但是所有的子类不是.所以这种方法用于子类从 PhysicsBody 获取 bodyInfo. */ PhysicsBodyInfo* bodyInfo(PhysicsBody* body) const; protected: PhysicsBody* _bodyA; PhysicsBody* _bodyB; PhysicsJointInfo* _info; friend class PhysicsBody; }; /* * @brief 将两个机构在一个固定的融合点. 固定接头是非常有用的,它可以用于创建复杂的图形,他也可以被打散 */ class PhysicsJointFixed : public PhysicsJoint { public: PhysicsJointFixed* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr); protected: bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr); protected: PhysicsJointFixed(); virtual ~PhysicsJointFixed(); }; /* * @brief 滑动联合,允许两个机构沿选定的轴滑动 */ class PhysicsJointSliding : public PhysicsJoint { public: PhysicsJointSliding* create(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr); protected: bool init(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr); protected: PhysicsJointSliding(); virtual ~PhysicsJointSliding(); }; /* * @brief 弹簧节点,连接两个机构,弹簧的长度是这两个机构之间的初始距离. */ class PhysicsJointSpring : public PhysicsJoint { public: PhysicsJointSpring* create(); protected: bool init(); protected: PhysicsJointSpring(); virtual ~PhysicsJointSpring(); }; /* * @brief 限制联合,如果它们是用绳子连接,限制这两个机构之间的最大距离. */ class PhysicsJointLimit : public PhysicsJoint { public: PhysicsJointLimit* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2, float min, float max); protected: bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2, float min, float max); protected: PhysicsJointLimit(); virtual ~PhysicsJointLimit(); }; /* * @brief 别针联合,如果两个机构固定在一起它们可以独立绕锚点运动. */ class PhysicsJointPin : public PhysicsJoint { public: static PhysicsJointPin* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2); protected: bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2); protected: PhysicsJointPin(); virtual ~PhysicsJointPin(); }; NS_CC_END #endif // __CCPHYSICS_JOINT_H__ #endif // CC_USE_PHYSICS