Prismatic Joint(移动关节)

Prismatic Joint的作用是在一个方向上移动某一个刚体,移动的最大距离和最小距离可以定义,移动过程中刚体不能转动。一般可以用着活塞运动。

下面的是创建移动关节的主要代码:

var pristmaticRect:Rect = new Rect(40, 40, new Point(275, 200), new Point(), new MyRect(), _container);
var prismaticJointDef:b2PrismaticJointDef = new b2PrismaticJointDef();
prismaticJointDef.Initialize(_world.GetGroundBody(), pristmaticRect.body, pristmaticRect.body.GetPosition(), new b2Vec2(1, 0));
prismaticJointDef.enableMotor = true;
prismaticJointDef.enableLimit = true;
prismaticJointDef.motorSpeed = Math.PI / 5;
prismaticJointDef.maxMotorForce = 300;
prismaticJointDef.upperTranslation = 150 / PhyOption.PHYSCALE;
prismaticJointDef.lowerTranslation = -150 / PhyOption.PHYSCALE;
_prismaticJoint = _world.CreateJoint(prismaticJointDef) as b2PrismaticJoint;

4-7行的属性跟Revolute Joint中一样,具体说明上一篇有详细介绍。

8-9行分别是刚体沿某个方向移动的最大最小距离,以米为单位。

3行Initialize方法的第四个参数设定的是刚体移动的方向,如x轴方向或者y轴方向。此参数是一个b2Vec2对象,且其x,y属性都不能超过1,否则会有意想不到结果。当要沿x轴移动时,设置为x=1,y=0;要沿y轴移动时,设置为y=1,x=0;

posted @ 2010-05-17 23:29  ywxgod  阅读(4212)  评论(0编辑  收藏  举报