cocos2dx 3.6 CCPhysicsBody.h 翻译

/****************************************************************************
 Copyright (c) 2013 Chukong Technologies Inc.
 
 http://www.cocos2d-x.org
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

#ifndef __CCPHYSICS_BODY_H__
#define __CCPHYSICS_BODY_H__

#include "base/ccConfig.h"
#if CC_USE_PHYSICS

#include "base/CCRef.h"
#include "math/CCGeometry.h"
#include "physics/CCPhysicsShape.h"
#include "base/CCVector.h"

struct cpBody;

NS_CC_BEGIN

class Node;
class Sprite;
class PhysicsWorld;
class PhysicsJoint;

typedef Vec2 Vect;
/*
mass 质量
moment 力矩
dynamic 动态
default 默认
contains 包含
offset 偏移/位置
force 力
angular 角速度

*/

const PhysicsMaterial PHYSICSBODY_MATERIAL_DEFAULT(0.1f, 0.5f, 0.5f);

/**
 * @addtogroup core
 * @{
 */

/**
 * A body affect by physics.
	一个受物理影响的body
 *
 * It can attach one or more shapes.
	可以附加更多的形状
 * If you create body with createXXX, it will automatically compute mass and moment with density your specified(which is PHYSICSBODY_MATERIAL_DEFAULT by default, and the density value is 0.1f), and it based on the formular: mass = density * area.
	如果你创建一个 body ,会自动 根据设定的值 来 分配 质量,力矩 , 没有设定时,会 设定初始值 密度为 0.1 质量等于 力矩乘以体积
 * If you create body with createEdgeXXX, the mass and moment will be PHYSICS_INFINITY by default. And it's a static body.
 如果你创建 一个Edgebody  质量和力矩 将PHYSICS_INFINITY默认 和这是一个静态的 body
 * You can change mass and moment with setMass() and setMoment(). And you can change the body to be dynamic or static by use function setDynamic().
	你可以通过函数 来 改变 mass 和 moment 的值  也可以通过 setDynamic() 方法来 改变 body 的静态 或者 动态
 */
class CC_DLL PhysicsBody : public Ref
{
public:
    /** 
     Create a body with default mass and moment.
	 创建一个默认的质量和力矩值
     
     This default mass value is 1.0.
	 默认质量为 1.0
     This default moment value is 200.
	 默认密度为200
     @return  An autoreleased PhysicsBody object pointer.
	 返回一个 autoreleased PhysicsBody 的对象指针
     */
    static PhysicsBody* create();
   
    /** 
     Create a body with mass and default moment.
     可设置 力矩 
     @param mass This body's mass.
     @return  An autoreleased PhysicsBody object pointer.
     */
    static PhysicsBody* create(float mass);
    
    /** 
     Create a body with mass and moment.
     
     @param mass This body's mass.
     @param moment This body's moment.
	 可以设置质量 和力矩
     @return  An autoreleased PhysicsBody object pointer.
     */
    static PhysicsBody* create(float mass, float moment);
    
    /** 
     Create a body contains a circle.
	 创建一个 body 包含一个圆
     
     @param   radius A float number, it is the circle's radius.
				半径为 float 类型 ,这是一个圆的半径
     @param   material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
				默认是 PHYSICSSHAPE_MATERIAL_DEFAULT 材质
     @param   offset A Vec2 object, it is the offset from the body’s center of gravity in body local coordinates.
				设定重心的锚点(一个vec2 的位置对象, 它是身体的重心的位置身体局部坐标)
     @return  An autoreleased PhysicsBody object pointer.
				返回一个 自动释放 的物理body 指针
     */
    static PhysicsBody* createCircle(float radius, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, const Vec2& offset = Vec2::ZERO);
    /** 
     * Create a body contains a box shape.
	 创建一个 包含盒子形状 body 
     *
     * @param   size Size contains this box's width and height.
					尺寸包含 盒子的 宽度和高度
     * @param   material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
				默认材质 为PHYSICSSHAPE_MATERIAL_DEFAULT
     * @param   offset A Vec2 object, it is the offset from the body’s center of gravity in body local coordinates.
				设定重心的锚点(一个vec2 的位置对象, 它是身体的重心的位置身体局部坐标)
     * @return  An autoreleased PhysicsBody object pointer.
				返回一个 自动释放 的物理body 指针
     */
    static PhysicsBody* createBox(const Size& size, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, const Vec2& offset = Vec2::ZERO);
    
    /**
     * @brief Create a body contains a polygon shape.
				创建一个多边行 对象的body
     *
     * @param   points Points is an array of Vec2 structs defining a convex hull with a clockwise winding.
				点的点是一个数组Vec2结构定义一个顺时针绕组的多边形
     * @param   count An interger number, contains the count of the points array.
				参数为整形,包含点阵列的计数(共有多少个顶点)
     * @param   material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
				默认为PHYSICSSHAPE_MATERIAL_DEFAULT的材质
     * @param   offset A Vec2 object, it is the offset from the body’s center of gravity in body local coordinates.
				body 中心的局部坐标
     * @return  An autoreleased PhysicsBody object pointer.
				自动释放的物理body 指针
     */
    static PhysicsBody* createPolygon(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, const Vec2& offset = Vec2::ZERO);
    
    /** 
     Create a body contains a EdgeSegment shape. 
	 创建一个body 包含 边缘线段的shape
     
     * @param   a It's the edge's begin position.
				边开始的坐标
     * @param   b It's the edge's end position.
				边结束的坐标
     * @param   material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
				默认材质为PHYSICSSHAPE_MATERIAL_DEFAULT 
     * @param   border It's a edge's border width.
				这是一个边的的线宽
     * @return  An autoreleased PhysicsBody object pointer.
				一个自动释放的 PhysicsBody 对象指针
				
     */
    static PhysicsBody* createEdgeSegment(const Vec2& a, const Vec2& b, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, float border = 1);
    
    /** 
     Create a body contains a EdgeBox shape. 
	 创建一个包含 盒子形状的边界

     * @param   size Size contains this box's width and height.
				size 包含的是盒子的宽度和高度
     * @param   material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
				默认为 PHYSICSSHAPE_MATERIAL_DEFAULT材质的 body
     * @param   border It's a edge's border width.
				线宽
     * @param   offset A Vec2 object, it is the offset from the body’s center of gravity in body local coordinates.
				
     * @return  An autoreleased PhysicsBody object pointer.
     */
    static PhysicsBody* createEdgeBox(const Size& size, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, float border = 1, const Vec2& offset = Vec2::ZERO);
    
    /** 
     Create a body contains a EdgePolygon shape. 
	 创建一个多边形的盒子
     
     * @param   points Points is an array of Vec2 structs defining a convex hull with a clockwise winding.
	 一个数组Vec2结构定义一个顺时针绕组的多边形
     * @param   count An interger number, contains the count of the points array.
		多边形的个数
     * @param   material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
	 默认为 PHYSICSSHAPE_MATERIAL_DEFAULT材质的 物理对象
     * @param   border It's a edge's border width.
	 线宽
     * @return  An autoreleased PhysicsBody object pointer.
	 
     */
    static PhysicsBody* createEdgePolygon(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, float border = 1);
    
    /** 
     Create a body contains a EdgeChain shape.
     创建一个链条状刚体 
     * @param   points A Vec2 object pointer, it contains an array of points.
				 一个数组Vec2结构定义一个顺时针绕组的多边形
     * @param   count An interger number, contains the count of the points array.
				数组个数
     * @param   material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
				默认 为 PHYSICSSHAPE_MATERIAL_DEFAULT 的材质
     * @param   border It's a edge's border width.
				线宽
     * @return  An autoreleased PhysicsBody object pointer.   
				物理刚体指针
     */
    static PhysicsBody* createEdgeChain(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, float border = 1);
    
    /**
     * @brief Add a shape to body.
				添加一个形状的到刚体 
     * @param shape The shape to be added.
				要添加的形状		
     * @param addMassAndMoment If this is true, the shape's mass and moment will be added to body. The default is true.
				默认会添加 质量和密度进去
     * @return This shape's pointer if added success or nullptr if failed.
     */
    virtual PhysicsShape* addShape(PhysicsShape* shape, bool addMassAndMoment = true);

    /**
     * @brief Remove a shape from body.
	   从刚体中移除形状
     * @param shape Shape the shape to be removed.
	   默认 质量和密度 ,
     * @param reduceMassAndMoment If this is true, the body mass and moment will be reduced by shape. The default is true.
     */
    void removeShape(PhysicsShape* shape, bool reduceMassAndMoment = true);

    /**
     * @brief Remove a shape from body.
		移除 shape
     * @param tag The tag of the shape to be removed.
		通过 tag 移除 shap
     * @param reduceMassAndMoment If this is true, the body mass and moment will be reduced by shape. The default is true.
     */
    void removeShape(int tag, bool reduceMassAndMoment = true);
    
    /** 
     Remove all shapes.
      移除所有的 shape
     * @param reduceMassAndMoment If this is true, the body mass and moment will be reduced by shape. The default is true.
		默认降低 密度和质量
     */
    void removeAllShapes(bool reduceMassAndMoment = true);

    /**
     Get the body shapes.
		获得刚体中 shapes
     * @return A Vector object contains PhysicsShape pointer.
	 返回一个 vector 的 PhysicsShape 对象
     */
    inline const Vector& getShapes() const { return _shapes; }
    
    /** 
     Get the first shape of the body shapes.
     返回的刚体中 第一个 shape
     @return The first shape in this body.
     */
    inline PhysicsShape* getFirstShape() const { return _shapes.size() >= 1 ? _shapes.at(0) : nullptr; }

    /** 
     get the shape of the body. 
     获得一个 shape 来自 body
     @param   tag   An interger number that identifies a PhysicsShape object.
	 通过tag 来获得 shape
     @return A PhysicsShape object pointer or nullptr if no shapes were found.
	 返回空值或者 我们找到的对象
     */
    PhysicsShape* getShape(int tag) const;
    
    /** 
     Applies a continuous force to body.
     施加 一个持续的力 到body上 
     @param force The force is applies to this body.
	 适用用这个body 的力量
	 
     */
    virtual void applyForce(const Vect& force);
    
    /** 
     Applies a continuous force to body.
	 施加 一个持续的力 到body上 
     
     @param force The force is applies to this body.
	 适用用这个body 的力量
     @param offset A Vec2 object, it is the offset from the body’s center of gravity in world coordinates.
	 所施加的力相对于刚体的重心在世界坐标的偏移量
     */
    virtual void applyForce(const Vect& force, const Vec2& offset);

    /** 
     reset all the force applied to body. 
	 重置所有施加于刚体的力。
     */
    virtual void resetForces();

    /**
     Applies a immediate force to body.
     给刚体施加一个立即起效的冲量
     @param impulse The impulse is applies to this body.
	 impulse	应用于刚体的脉冲。

     */
    virtual void applyImpulse(const Vect& impulse);

    /**
     Applies a immediate force to body.
     给刚体施加一个立即起效的冲量
     @param impulse The impulse is applies to this body.
	 
	 impulse	应用于刚体的脉冲。
     @param offset A Vec2 object, it is the offset from the body’s center of gravity in world coordinates.
     offset	所施加的力相对于刚体的重心在世界坐标的偏移量,它是一个Vec2对象。
	 */
	 
    virtual void applyImpulse(const Vect& impulse, const Vec2& offset);
    
    /** 
     Applies a torque force to body. 
     给刚体施加一个扭力。
     @param torque The torque is applies to this body. 
	torque	应用于刚体的扭力。
     */
    virtual void applyTorque(float torque);
    
    /** 
     Set the velocity of a body.
	 设置刚体的速度
     @param velocity The velocity is set to this body.
	 velocity	要设置的刚体速度。
     */
    virtual void setVelocity(const Vect& velocity);
    
    /** Get the velocity of a body. */
	//获得刚体速度
    virtual Vec2 getVelocity();
    
    /** 
     Set the angular velocity of a body.
	 设置刚体的角速度
     
     @param velocity The angular velocity is set to this body.
	 velocity 要设置的角速度
     */
    virtual void setAngularVelocity(float velocity);
    
    /** Get the angular velocity of a body at a local point.*/
	//获取刚体在局部点上的角速度。 
    virtual Vec2 getVelocityAtLocalPoint(const Vec2& point);
    
    /** get the angular velocity of a body at a world point */
	//获取刚体在世界点上的角速度
    virtual Vec2 getVelocityAtWorldPoint(const Vec2& point);
    
    /** get the angular velocity of a body */
	//获取刚体的角速度。
    virtual float getAngularVelocity();
    
    /** set the max of velocity */
	//设置最大的速度
    virtual void setVelocityLimit(float limit);
    
    /** get the max of velocity */
	//获得最大的速度
    virtual float getVelocityLimit();
    
    /** set the max of angular velocity */
	//设置最大的角速度
    virtual void setAngularVelocityLimit(float limit);
    
    /** get the max of angular velocity */
	//获得最大的角速度
    virtual float getAngularVelocityLimit();
    
    /** remove the body from the world it added to */
	//将刚体从他添加的世界中移除
    void removeFromWorld();
    
    /** get the world body added to. */
	//获得刚体添加到世界
    inline PhysicsWorld* getWorld() const { return _world; }
    /** get all joints the body have */
	//获取刚体的所有关节
    inline const std::vector& getJoints() const { return _joints; }
    
    /** get the sprite the body set to. */
	//获得刚体关联的node对象
    inline Node* getNode() const { return _node; }
    
    /**
     * A mask that defines which categories this physics body belongs to.
     * 设置刚体所属种类的掩码值
     * Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions.
	 每一个场景中的物理刚体被会分配32个种类,每一个对应一个掩码值。你可以在游戏中自定义掩码值。与collisionBitMask和contactTestBitMask属性结合,你可以定义哪些物理刚体以及什么时候会互相影响
     * @param bitmask An interger number, the default value is 0xFFFFFFFF (all bits set).
     bitmask	整型值,默认是0xffffffff(所有位都为1)
	 */
    void setCategoryBitmask(int bitmask);
    
    /** 
     * A mask that defines which categories of bodies cause intersection notifications with this physics body.
     *设置这个物理刚体的接触分组掩码,它决定有哪些物理刚体与它产生接触的时候代理会响应。
     * When two bodies share the same space, each body’s category mask is tested against the other body’s contact mask by performing a logical AND operation. If either comparison results in a non-zero value, an PhysicsContact object is created and passed to the physics world’s delegate. For best performance, only set bits in the contacts mask for interactions you are interested in.
     当两个刚体在同一个空间中接触时,一个刚体的分组掩码会与另一个的分组掩码做逻辑与操作,如果结果非0,一个PhysicsContact接触对象会被创建并传递給物理世界的代理。为了优化性能,可以只为那些你需要处理接触的刚体之间设置不同的分组掩码。
	 * @param bitmask An interger number, the default value is 0x00000000 (all bits cleared).
	bitmask	整型值,默认值是0x00000000(所有位都是0)。
	 */
    void setContactTestBitmask(int bitmask);
    
    /**
     * A mask that defines which categories of physics bodies can collide with this physics body.
		设置这个物理刚体的碰撞分组掩码,它决定有哪些物理刚体会与它产生碰撞
     * When two physics bodies contact each other, a collision may occur. This body’s collision mask is compared to the other body’s category mask by performing a logical AND operation. If the result is a non-zero value, then this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example, you might use this to avoid collision calculations that would make negligible changes to a body’s velocity.
		当两个刚体在同一个空间中接触时,一个需要处理的碰撞就有可能产生,一个刚体的分组掩码会与另一个的分组掩码做逻辑与操作,如果结果非0,那么刚体就会受碰撞所影响。刚体分别选择是否对碰撞做出响应并影响自己的运动。打个比方,你可以避免碰撞计算所引起的对刚体速度的微小影响。
	* @param bitmask An interger number, the default value is 0xFFFFFFFF (all bits set).
	// 整形 默认值为 0xFFFFFFFF 都是一
     */
    void setCollisionBitmask(int bitmask);
    
    /** 
     Return bitmask of first shape.
     返回第一个形状的掩码值
     * @return If there is no shape in body, return default value.(0xFFFFFFFF)
	 //如果刚体中没有形状,返回默认值(0xFFFFFFFF)
     */
    int getCategoryBitmask() const;
    
    /** 
     Return bitmask of first shape.
     //返回一个 形状掩码
     * @return If there is no shape in body, return default value.(0x00000000)
	 没有的时候返回默认值 0x00000000
     */
    int getContactTestBitmask() const;
    
    /** 
     Return bitmask of first shape.
     返回第一个 形状的掩码值
     @return If there is no shape in body, return default value.(0xFFFFFFFF)
	 没有的话 返回 默认值为  0xFFFFFFFF
     */
    int getCollisionBitmask() const;
    
    /** 
     * Set the group of body.
     *设置刚体组
     * Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collide (positive index) or never collide (negative index).
		碰撞组让你可以指定一个整型索引,你可以让具有同样组索引的形状总是碰撞(正索引)或总不碰撞(负值)。 它比掩码值有更高的优先级
	* It have high priority than bit masks.
     */
    void setGroup(int group);
    
    /** 
     Return group of first shape.
     返回第一个形状的组
     @return If there is no shape in body, return default value.(0) 
	 如果刚体中没有形状,返回默认值(0)
     */
    int getGroup() const;
    
    /** get the body position. */
	//获得刚体的位置
    const Vec2& getPosition();
    
    /** get the body rotation. */
	//获得刚体的角度
    float getRotation();
    
    /** set body position offset, it's the position witch relative to node */
	//设置刚体的偏移量,它是相对node的位置
    void setPositionOffset(const Vec2& position);
    
    /** get body position offset. */
	//获取刚体位置的偏移量。 
    const Vec2& getPositionOffset() const { return _positionOffset; }
    
    /** set body rotation offset, it's the rotation witch relative to node */
	//设置刚体的旋转偏移量,它是相对于node的旋转 
    void setRotationOffset(float rotation);
    
    /** set the body rotation offset */
	//设置刚体的旋转偏移量
    float getRotationOffset() const { return _rotationOffset; }
    
    /**
     * @brief Test the body is dynamic or not.
	 
     *
     * A dynamic body will effect with gravity.
     */
    inline bool isDynamic() const { return _dynamic; }
    /**检查刚体是否是动态地。
     * @brief Set dynamic to body.
     * 
     * A dynamic body will effect with gravity.
	 //一个动态的刚体会受到重力的影响
     */
    void setDynamic(bool dynamic);
    
    /**
     * @brief Set the body mass.
     *刚体质量
     * @attention If you need add/subtract mass to body, don't use setMass(getMass() +/- mass), because the mass of body may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMass() instead.
     如果你需要+/-刚体的质量,不要使用setMass(getMass() +/- mass),因为刚体的质量可能等于PHYSICS_INFINITY,它会导致一些意想不到的结果。所以,请使用addMass()。
	 */
    void setMass(float mass);
    
    /** Get the body mass. */
    inline float getMass() const { return _mass; }
    /**
     * @brief Add mass to body.
     *增加刚体的质量。
     * @param mass If _mass(mass of the body) == PHYSICS_INFINITY, it remains.
	 mass	如果 mass == PHYSICS_INFINITY, _mass还是PHYSICS_INFINITY。
	 如果 mass == -PHYSICS_INFINITY _mass将不会改变。
	 如果 mass + _mass <= 0, _mass将等于MASS_DEFAULT(1.0) 
	 否则, mass = mass + _mass;
     * if mass == PHYSICS_INFINITY, _mass will be PHYSICS_INFINITY.
     * if mass == -PHYSICS_INFINITY, _mass will not change.
     * if mass + _mass <= 0, _mass will equal to MASS_DEFAULT(1.0)
     * other wise, mass = mass + _mass;
     */
    void addMass(float mass);
    
    /**
     * @brief Set the body moment of inertia.
     * 设置刚体的惯性力矩
     * @note If you need add/subtract moment to body, don't use setMoment(getMoment() +/- moment), because the moment of body may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMoment() instead.
     如果你需要 +/- 刚体的力矩, 不要使用setMoment(getMoment() +/- moment),因为刚体的力矩可能等于PHYSICS_INFINITY,它会导致一些意想不到的结果。所以,请使用addMoment()。
	 */
    void setMoment(float moment);
    
    /** Get the body moment of inertia. */
	//获取刚体的惯性力矩
    inline float getMoment() const { return _moment; }
    
    /**
     * @brief Add moment of inertia to body.
     * //增加 惯性力矩 到刚体
	 如果 moment == PHYSICS_INFINITY,_moment为PHYSICS_INFINITY。 
	 如果 moment == -PHYSICS_INFINITY,_moment不会改变 
	 如果 moment + _moment <= 0,_moment将等于MASS_DEFAULT(1.0)
	 否则,moment = moment + _moment;
     * @param moment If _moment(moment of the body) == PHYSICS_INFINITY, it remains.
     * if moment == PHYSICS_INFINITY, _moment will be PHYSICS_INFINITY.
     * if moment == -PHYSICS_INFINITY, _moment will not change.
     * if moment + _moment <= 0, _moment will equal to MASS_DEFAULT(1.0)
     * other wise, moment = moment + _moment;
     */
    void addMoment(float moment);
    
    /** get linear damping. */
	//得到线性阻尼
    inline float getLinearDamping() const { return _linearDamping; }
    
    /** 
     * Set linear damping.
     *设置线性阻尼
     * it is used to simulate fluid or air friction forces on the body.
	 它是用来模拟液体或空气摩擦力对刚体的影响
     * @param damping The value is 0.0f to 1.0f.
	 //damping	f取值的范围是0.0f到1.0f
     */
    inline void setLinearDamping(float damping) { _linearDamping = damping; updateDamping(); }
    
    /** Get angular damping. */
	//获取角阴尼 
    inline float getAngularDamping() const { return _angularDamping; }
    /**
     * Set angular damping.
     *设置角阻尼
     * It is used to simulate fluid or air friction forces on the body.
	 //它是用来模拟液体或空气摩擦力对刚体的影响
     * @param damping The value is 0.0f to 1.0f.
	 值是 0.0 到 1.0之间
     */
    inline void setAngularDamping(float damping) { _angularDamping = damping; updateDamping(); }
    
    /** Whether the body is at rest. */
	//刚体是否 静止
    bool isResting() const;
    
    /** set body to rest */
	//设置刚体静止
    void setResting(bool rest) const;

    /**
     * Whether the body is enabled.
     *刚体是否被精活
     * If the body it isn't enabled, it will not has simulation by world.
     //果刚体无效,它不会有模拟世界
	 */
    inline bool isEnabled() const { return _enabled; }
    
    /**
     * Set the enable value.
     *设置 是否有效
     * If the body it isn't enabled, it will not has simulation by world.
	 //如果刚体无效,它不会有模拟世界
     */
    void setEnable(bool enable);
    
    /** Whether the body can rotation. */
	//刚体是否可以旋转
    inline bool isRotationEnabled() const { return _rotationEnabled; }
    
    /** Set the body is allow rotation or not */
	//设置刚体是否旋转
    void setRotationEnable(bool enable);
    
    /** Whether this physics body is affected by the physics world’s gravitational force. */
	//刚体是否受物理世界重力的影响
    inline bool isGravityEnabled() const { return _gravityEnabled; }
    
    /** Set the body is affected by the physics world's gravitational force or not. */
	//设置刚体是否受物理世界重力的影响 
    void setGravityEnable(bool enable);
    
    /** Get the body's tag. */
	//获取刚体的tag值
    inline int getTag() const { return _tag; }
    
    /** set the body's tag. */
	//设置刚体的tag值
    inline void setTag(int tag) { _tag = tag; }
    
    /** Convert the world point to local. */
	//将世界坐标转换成本地坐标
    Vec2 world2Local(const Vec2& point);
    
    /** Convert the local point to world. */
	//将本地坐标转换成世界坐标
    Vec2 local2World(const Vec2& point);

    /** Get the rigid body of chipmunk. */
	//获取chipmunk中的刚体
    cpBody* getCPBody() { return _cpBody; }
    
protected:
    
    bool init();
    
    virtual void setPosition(const Vec2& position);
    virtual void setRotation(float rotation);
    virtual void setScale(float scaleX, float scaleY);
    
    void update(float delta);
    
    void removeJoint(PhysicsJoint* joint);
    inline void updateDamping() { _isDamping = _linearDamping != 0.0f ||  _angularDamping != 0.0f; }
    
protected:
    PhysicsBody();
    virtual ~PhysicsBody();
    
protected:
    Node* _node;
    std::vector _joints;
    Vector _shapes;
    PhysicsWorld* _world;
    cpBody* _cpBody;
    bool _dynamic;
    bool _enabled;
    bool _rotationEnabled;
    bool _gravityEnabled;
    bool _massDefault;
    bool _momentDefault;
    float _mass;
    float _area;
    float _density;
    float _moment;
    bool _isDamping;
    float _linearDamping;
    float _angularDamping;
    int _tag;
    
    bool _positionInitDirty;
    Vec2 _recordedPosition;
    Vec2 _latestPosition;
    Vec2 _positionOffset;
    float _rotationOffset;
    float _recordedRotation;
    double _recordedAngle;
    
    friend class PhysicsWorld;
    friend class PhysicsShape;
    friend class PhysicsJoint;
    friend class Node;
    friend class Layer;
    friend class ProtectedNode;
};

/** @} */

NS_CC_END

#endif // CC_USE_PHYSICS
#endif // __CCPHYSICS_BODY_H__

你可能感兴趣的:(cocos2d-x)