cocos creator阻尼减速_cocos2d-x节点(CCPhysicsBody.h)API | 学步园

cocos2d-x节点(CCPhysicsBody.h)API

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

物体之间的作用力,把shape链接到body

///cocos2d-x-3.0alpha0/cocos2dx/physics

//物体之间的作用力,把 shape 链接到 body

#include "CCPhysicsSetting.h"

#ifdef CC_USE_PHYSICS

#ifndef __CCPHYSICS_BODY_H__

#define __CCPHYSICS_BODY_H__

#include "cocoa/CCObject.h"

#include "cocoa/CCGeometry.h"

#include

NS_CC_BEGIN

class Sprite;

class PhysicsWorld;

class PhysicsJoint;

class PhysicsShape;

class PhysicsShapeCircle;

class PhysicsShapeBox;

class PhysicsShapePolygon;

class PhysicsShapeEdgeSegment;

class PhysicsShapeEdgeBox;

class PhysicsShapeEdgePolygon;

class PhysicsShapeEdgeChain;

class PhysicsBodyInfo;

/**

* physics 影响 body.

* 它可以和一个或多个形状产生联系.

*/

class PhysicsBody : public Object//, public Clonable(可克隆的)

{

public:

/**

* @brief 创建一个包含 圆形的 body

*/

static PhysicsBody* createCircle(float radius);

/**

* @brief 创建一个包含 box形状的 body

*/

static PhysicsBody* createBox(Size size);

/**

* @brief 创建一个包含 polygon(多变形)的 body

* points 是定义的点结构数组,沿顺时针缠绕的凸球面

*/

static PhysicsBody* createPolygon(Point* points, int count);

/**

* @brief 创建一个包含 EdgeSegment(边缘片段)形状的 body

*/

static PhysicsBody* createEdgeSegment(Point a, Point b, float border = 1);

/**

* @brief 创建一个包含 EdgeBox(边缘方块)形状的 body

*/

static PhysicsBody* createEdgeBox(Size size, float border = 1);

/**

* @brief 创建一个包含 EdgePolygon(边缘多边形)形状的 body .

*/

static PhysicsBody* createEdgePolygon(Point* points, int count, float border = 1);

/**

* @brief 创建一个包含 EdgeChain(边链)形状的 body.

*/

static PhysicsBody* createEdgeChain(Point* points, int count, float border = 1);

/**

* @brief 把一个圆的形状连接到 body

*/

virtual PhysicsShapeCircle* addCircle(float radius, Point offset = Point(0, 0));

/**

* @brief 把一个box的形状连接到 body

*/

virtual PhysicsShapeBox* addBox(Size size, Point offset = Point(0, 0));

/**

* @brief 把一个多边形的形状连接到 body

*/

virtual PhysicsShapePolygon* addPolygon(Point* points, int count, Point offset = Point(0, 0));

/**

* @brief 把一个边缘部分的形状连接到 body

*/

virtual PhysicsShapeEdgeSegment* addEdgeSegment(Point a, Point b, float border = 1);

/**

* @brief 把一个边缘框形状连接到 body

*/

virtual PhysicsShapeEdgeBox* addEdgeBox(Size size, float border = 1, Point offset = Point(0, 0));

/**

* @brief 把一个边缘多边形的形状连接到 body

* points 是定义的点结构数组,沿顺时针缠绕的凸球面.

*/

virtual PhysicsShapeEdgePolygon* addEdgePolygon(Point* points, int count, float border = 1);

/**

* @brief 附加一个边缘链形状到 body

* points 是定义的点结构数组,沿顺时针缠绕的凸球面.

*/

virtual PhysicsShapeEdgeChain* addEdgeChain(Point* points, int count, float border = 1);

/**

* @brief 应用一个直接的力到 body.

*/

virtual void applyForce(Point force);

/**

* @brief 应用一个直接的力到 body.

*/

virtual void applyForce(Point force, Point offset);

/**

* @brief 应用一个连续的力到 body.

*/

virtual void applyImpulse(Point impulse);

/**

* @brief 应用一个连续的力到 body.

*/

virtual void applyImpulse(Point impulse, Point offset);

/**

* @brief 把一个力矩应用到 body.

*/

virtual void applyTorque(float torque);

/*

* @brief get the body shapes.

*/

inline std::vector& getShapes() { return _shapes; }

/*

* @brief get the first body shapes.

*/

inline PhysicsShape* getShape() { return _shapes.size() >= 1 ? _shapes.front() : nullptr; }

/*

* @brief remove a shape from body

*/

void removeShape(PhysicsShape* shape);

/*

* @brief remove all shapes

*/

void removeAllShapes();

/*

* @brief get 添加 body 的 world.

*/

inline PhysicsWorld* getWorld() const { return _world; }

/*

* @brief 获取 body 的所有joints(接触点)

*/

inline const std::vector* getJoints() const { return &_joints; }

/*

* @brief get sprite 为 aprite 设置的 body.

*/

inline Sprite* getOwner() const { return _owner; }

void setCategoryBitmask(int bitmask);

inline int getCategoryBitmask() const { return _categoryBitmask; }

void setContactTestBitmask(int bitmask);

inline int getContactTestBitmask() const { return _contactTestBitmask; }

void setCollisionBitmask(int bitmask);

inline int getCollisionBitmask() const { return _collisionBitmask; }

/*

* @brief get the body position. //位置

*/

Point getPosition() const;

/*

* @brief get the body rotation. //旋转

*/

float getRotation() const;

/*

* @brief 测试 body 是不是动态的 //body 是不是正在运动

* 动态会影响 body 重力.

*/

inline bool isDynamic() { return _dynamic; }

/*

* @brief set body 的动态.

* 动态会影响 body 重力.

*/

void setDynamic(bool dynamic);

/*

* @brief set the body mass(质量).

*/

void setMass(float mass);

/*

* @brief get the body mass(质量).

*/

inline float getMass() { return _mass; }

/*

* @brief 角速度 damping(阻尼系数)

*/

void setAngularDamping(float angularDamping);

/*

* @brief get 角速度 damping(阻尼系数).

*/

inline float getAngularDamping() { return _angularDamping; }

//virtual Clonable* clone() const override;

protected:

bool init();

bool initStatic();

virtual void setPosition(Point position);

virtual void setRotation(float rotation);

virtual void addShape(PhysicsShape* shape);

protected:

PhysicsBody();

virtual ~PhysicsBody();

protected:

Sprite* _owner;

std::vector _joints;

std::vector _shapes;

PhysicsWorld* _world;

PhysicsBodyInfo* _info;

bool _dynamic;

bool _massDefault;

bool _angularDampingDefault;

float _mass;

float _area;

float _density;

float _angularDamping;

int _categoryBitmask;

int _contactTestBitmask;

int _collisionBitmask;

friend class PhysicsWorld;

friend class PhysicsShape;

friend class PhysicsJoint;

friend class Sprite;

};

NS_CC_END

#endif // __CCPHYSICS_BODY_H__

#endif // CC_USE_PHYSICS

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值