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

cocos2d-x节点(CCPhysicsShape.h)API

2013-12-02 15:59 471 查看
本文来自http://blog.csdn.net/runaying ,引用必须注明出处!


cocos2d-x节点(CCPhysicsShape.h)API

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

///cocos2d-x-3.0alpha0/cocos2dx/physics
//模拟现实世界的形状,圆形,链形,段状,对变形.....

#include "CCPhysicsSetting.h"
#ifdef CC_USE_PHYSICS

#ifndef __CCPHYSICS_SHAPE_H__
#define __CCPHYSICS_SHAPE_H__

#include "cocoa/CCObject.h"
#include "cocoa/CCGeometry.h"

NS_CC_BEGIN

class PhysicsShapeInfo;
class PhysicsBody;
class PhysicsBodyInfo;

/**
* @brief body 的形状. 你不应该直接创建 PhysicsWorld 对象; 相反,你可以从一个 Scene 对象里面得到它.
*/
class PhysicsShape : public Object
{
public:
enum class Type
{
UNKNOWN,
CIRCLE,
BOX,
POLYGEN,
EDGESEGMENT,
EDGEBOX,
EDGEPOLYGEN,
EDGECHAIN,
};

public:
inline PhysicsBody* getBody(){ return _body; }
inline Type getType() { return _type; }

protected:
bool init(PhysicsBody* body, Type type);

/**
* @brief PhysicsShape 是 PhysicsBody's 的朋友类 class, 但是所有的子类不是.所以这种方法用于子类从 PhysicsBody 获取 bodyInfo..
*/
PhysicsBodyInfo* bodyInfo() const;

void addToBody();

protected:
PhysicsShape();
virtual ~PhysicsShape() = 0;

protected:
PhysicsBody* _body;
PhysicsShapeInfo* _info;
Type _type;

friend class PhysicsWorld;
friend class PhysicsBody;
};

/** A circle shape */           //一个圆形状
class PhysicsShapeCircle : public PhysicsShape
{
protected:
static PhysicsShapeCircle* create(PhysicsBody* body, float radius, Point offset = Point(0, 0));
bool init(PhysicsBody* body, float radius, Point offset = Point(0, 0));

protected:
PhysicsShapeCircle();
virtual ~PhysicsShapeCircle();

friend class PhysicsBody;
};

/** A box shape */      //一个盒子形状
class PhysicsShapeBox : public PhysicsShape
{
protected:
static PhysicsShapeBox* create(PhysicsBody* body, Size size, Point offset = Point(0, 0));
bool init(PhysicsBody* body, Size size, Point offset = Point(0, 0));

protected:
PhysicsShapeBox();
virtual ~PhysicsShapeBox();

friend class PhysicsBody;
};

/** A polygon shape */      //多边形的形状
class PhysicsShapePolygon : public PhysicsShape
{
protected:
static PhysicsShapePolygon* create(PhysicsBody* body, Point* points, int count, Point offset = Point(0, 0));
bool init(PhysicsBody* body, Point* points, int count, Point offset = Point(0, 0));

protected:
PhysicsShapePolygon();
virtual ~PhysicsShapePolygon();

friend class PhysicsBody;
};

/** A segment shape */      //一个段的形状
class PhysicsShapeEdgeSegment : public PhysicsShape
{
protected:
static PhysicsShapeEdgeSegment* create(PhysicsBody* body, Point a, Point b, float border = 1);
bool init(PhysicsBody* body, Point a, Point b, float border = 1);

protected:
PhysicsShapeEdgeSegment();
virtual ~PhysicsShapeEdgeSegment();

friend class PhysicsBody;
};

/** An edge box shape */        //一个边缘是框形状
class PhysicsShapeEdgeBox : public PhysicsShape
{
public:
static PhysicsShapeEdgeBox* create(PhysicsBody* body, Size size, float border = 0, Point offset = Point(0, 0));

protected:
bool init(PhysicsBody* body, Size size, float border = 1, Point offset = Point(0, 0));

protected:
PhysicsShapeEdgeBox();
virtual ~PhysicsShapeEdgeBox();

friend class PhysicsBody;
};

/** An edge polygon shape */        //一个边缘是多边形形状
class PhysicsShapeEdgePolygon : public PhysicsShape
{
public:
static PhysicsShapeEdgePolygon* create(PhysicsBody* body, Point* points, int count, float border = 1);

protected:
bool init(PhysicsBody* body, Point* points, int count, float border = 1);

protected:
PhysicsShapeEdgePolygon();
virtual ~PhysicsShapeEdgePolygon();

friend class PhysicsBody;
};

/** a chain shape */        //链形
class PhysicsShapeEdgeChain : public PhysicsShape
{
public:
static PhysicsShapeEdgeChain* create(PhysicsBody* body, Point* points, int count, float border = 1);

protected:
bool init(PhysicsBody* body, Point* points, int count, float border = 1);

protected:
PhysicsShapeEdgeChain();
virtual ~PhysicsShapeEdgeChain();

friend class PhysicsBody;
};

NS_CC_END
#endif // __CCPHYSICS_FIXTURE_H__

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