滑轮关节(b2PulleyJoint)
1 package{ 2 import Box2D.Collision.b2AABB; 3 import Box2D.Collision.b2RayCastInput; 4 import Box2D.Collision.b2RayCastOutput; 5 import Box2D.Collision.Shapes.b2CircleShape; 6 import Box2D.Collision.Shapes.b2PolygonShape; 7 import Box2D.Collision.Shapes.b2Shape; 8 import Box2D.Common.Math.b2Vec2; 9 import Box2D.Dynamics.b2Body; 10 import Box2D.Dynamics.b2BodyDef; 11 import Box2D.Dynamics.b2Fixture; 12 import Box2D.Dynamics.b2FixtureDef; 13 import Box2D.Dynamics.b2World; 14 import flash.display.Sprite; 15 import flash.utils.getTimer; 16 import Box2D.Dynamics.Joints.b2PulleyJoint; 17 import Box2D.Dynamics.Joints.b2PulleyJointDef; 18 19 /** 20 * 21 */ 22 public class Main extends BaseMain{ 23 24 25 public function Main(){ 26 super(new b2Vec2(0,10)); 27 } 28 29 override protected function init():void{ 30 var bodyA:b2Body=this.createBox(50,50,100,400); 31 var bodyB:b2Body=this.createCircle(25,700,400); 32 33 var jointDef:b2PulleyJointDef=new b2PulleyJointDef(); 34 35 //悬挂的两个点 36 var gaA:b2Vec2=new b2Vec2(100/_pixelToMeter,100/_pixelToMeter); 37 var gaB:b2Vec2=new b2Vec2(700/_pixelToMeter,100/_pixelToMeter); 38 39 var anchorA:b2Vec2=bodyA.GetWorldCenter(); 40 var anchorB:b2Vec2=bodyB.GetWorldCenter(); 41 var r:Number=1;//如果系数是2,那么 length1 的变化会是 length2 的两倍。另外连接 body1 的绳子的约束力将会是连接 body2 绳子的一半。 42 jointDef.Initialize(bodyA,bodyB,gaA,gaB,anchorA,anchorB,r); 43 var joint:b2PulleyJoint=_world.CreateJoint(jointDef) as b2PulleyJoint; 44 } 45 46 override protected function stepBefore():void{ 47 48 } 49 50 51 }; 52 }
源码下载:http://yunpan.cn/c3aI3KPrsUSXy 访问密码 64bc