所谓质心,可以理解为是Cocos2d-x里面的锚点。
b2Body里面的一些函数试验:
void b2Body::ApplyAngularImpulse ( float32 impulse ) [inline]
Apply an angular impulse.
Parameters:
impulse the angular impulse in units of kg*m*m/s
给刚体一个旋转的作用力(围着质心旋转,如果刚体是一个圆那么就是围着圆心转的效果),数字越大转速越快。注意:必须是动态刚体才会有作用,即将刚体定义的type设置为 b2_dynamicBody。例子: ballDef. type = b2_dynamicBody ;
void b2Body::ApplyForce ( const b2Vec2 & force,
const b2Vec2 & point
) [inline]
Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body.
Parameters:
force the world force vector, usually in Newtons (N).
point the world position of the point of application.
给予刚体一个力:
参数1:b2Vec2结构体,指示力在x和y轴上的大小。数值越大,动态刚体的移动速度越快(有点类似于每帧在不断更新x和y轴上给予的力的数值的位置信息,匀速的)。
参数2:b2Vec2结构体,作用力的位置(通常是刚体的质心)。
/// Apply a force to the center of mass. This wakes up the body.
/// @param force the world force vector, usually in Newtons (N).
void ApplyForceToCenter(const b2Vec2& force);
void b2Body::ApplyLinearImpulse ( const b2Vec2 & impulse,
const b2Vec2 & point
) [inline]
Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body.
Parameters:
impulse the world impulse vector, usually in N-seconds or kg-m/s.
point the world position of the point of application.
给予刚体一个线性冲力:
参数1:b2Vec2结构体,指示力在x和y轴上的大小。数值越大,动态刚体的移动速度越快(会看到有个线性加速度的效果)。
参数2:b2Vec2结构体,作用力的位置(通常是刚体的质心)。
void b2Body::ApplyTorque ( float32 torque ) [inline]
Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body.
Parameters:
torque about the z-axis (out of the screen), usually in N-m.
给予刚体一个扭矩,不会改变质心的线性速度(即只会围着质心旋转,也可以理解为改变刚体的角度):
参数1:扭矩,z轴方向。