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

学习 Box2D 个人笔记(三)ApplyForce

2012-12-28 18:29 197 查看
上一章我们说道了创建一个世界 和一物体,但是却不能动,不能动多难受啊 。

所以这张我们要让物体动起来,根据牛顿第一定律:一切物体在没有受到力的作用时,总保持匀速直线运动状态或静止状态,除非作用在它上面的力迫使它改变这种运动状态。

同样,我们的世界也遵循牛顿定律,如果我们要改变一个物体的运动状态,那么我们就得需要为他施加一个力(Force)。

所以很简单 。我们知道一个物体,然后对它用力,就ok了。

fkBody->ApplyForce(b2Vec2::b2Vec2(20/PTM_RATIO,20/PTM_RATIO), b2Vec2::b2Vec2(20/PTM_RATIO,20/PTM_RATIO));


的括号内的参数1表示,力的大小,往往用N(牛顿)表示。(说实话我也没弄明白这个向量跟N是如何装换的,希望指教)
  括号内的参数2表示,作用力应该作用的位置,位置是一个坐标。

/// 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.
/// @param force the world force vector, usually in Newtons (N).
/// @param point the world position of the point of application.
void ApplyForce(const b2Vec2& force, const b2Vec2& point);

/// Apply a torque. This affects the angular velocity
/// without affecting the linear velocity of the center of mass.
/// This wakes up the body.
/// @param torque about the z-axis (out of the screen), usually in N-m.
void ApplyTorque(float32 torque);

/// 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.
/// @param impulse the world impulse vector, usually in N-seconds or kg-m/s.
/// @param point the world position of the point of application.
void ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point);

/// Apply an angular impulse.
/// @param impulse the angular impulse in units of kg*m*m/s
void ApplyAngularImpulse(float32 impulse);


这几种方法我没大用过,但是为了不落下他们所以我写上了,因为牵扯到力矩问题,现在我还没弄懂是怎么回事,但是为了记笔记就先记下了,千万不要误人子弟了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: