Box2D笔记


所谓质心,可以理解为是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);


和上面的ApplyForce()类似,只是这个函数指定了作用力的位置为刚体的质心。



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轴方向。


























  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值