By
被删
更新日期:
本节主要介绍齿轮关节(gear-joint)。
齿轮关节(gear-joint)
说明
齿轮关节需要两个被旋转关节或移动关节接地(ground)的物体,可以任意组合这些关节类型。
b2PulleyJointDef
另外,创建旋转或移动关节时,Box2D需要地(ground)作为 body1。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| var Shape1 = new b2BoxDef(); Shape1.extents.Set(10, 10); Shape1.density = 1; Shape1.restitution = .3; Shape1.friction = 1;
var BodyDef1 = new b2BodyDef(); BodyDef1.position.Set(950, 450); BodyDef1.AddShape(Shape1); Body1 = world.CreateBody(BodyDef1);
var jointDefRevolute = new b2RevoluteJointDef(); jointDefRevolute.anchorPoint.Set(950, 450); jointDefRevolute.body1 =world.GetGroundBody(); jointDefRevolute.body2 = Body1; var jointRevolute= world.CreateJoint(jointDefRevolute);
var Shape2 = new b2BoxDef(); Shape2.extents.Set(100, 10); Shape2.density = 1; Shape2.restitution = .3; Shape2.friction = 1;
var BodyDef2 = new b2BodyDef(); BodyDef2.position.Set(950, 530); BodyDef2.AddShape(Shape2); Body2 = world.CreateBody(BodyDef2);
var jointDefPrismatic = new b2PrismaticJointDef(); jointDefPrismatic.anchorPoint.Set(950, 565); jointDefPrismatic.axis.Set(1,0); jointDefPrismatic.body1 =world.GetGroundBody(); jointDefPrismatic.body2 =Body2; var jointPrismatic= world.CreateJoint(jointDefPrismatic);
var jointDefGear = new b2GearJointDef(); jointDefGear.body1=Body1; jointDefGear.body2=Body2; jointDefGear.joint1=jointRevolute; jointDefGear.joint2=jointPrismatic; var jointGear=world.CreateJoint(jointDefGear); jointGear.m_ratio=1;
|
查看Github有更多内容噢:https://github.com/godbasin
更欢迎来被删的前端游乐场边撸猫边学前端噢
如果你想要关注日常生活中的我,欢迎关注“牧羊的猪”公众号噢