Monday 15 April 2013

javascript - Why are objects not anchoring to prismatic joint(s) -


I am creating a bunch of random objects and fixed them with a fixed body (circle) with a prismatic joint Have to draw on the circle.

There is a problem - objects have to fall from the edges of joints because they do not seem anticipated.

What am I doing wrong

js bella:

js: (by going physics.prototype.connectToCenterWithJoint for joint code) < Pre> physics = (function () {physics physics} {this.bodies = []; this.testObjectCount = 30; this.w = new Box2D.Dynamics.b2World (New Box2D.Common.Math.b2Vec2 (0, 10), true); Stability = New Box2D.Dynamics.b2FixtureDef (); this.bodyDef = New Box2D.Dynamics.b2BodyDef (); this.bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody; this. BodyDef.position.x = 9; this.bodyDef.position.y = 13; fixture.shape = Box2D.Collision.Shapes.b2PolygonShape.AsBox (10, .5); this.w.CreateBody (this.bodyDef) .CreateFixture (Stability); this.bodyDef.Type = Box2D.Dynamics.b2Body.b2_dynamicBody; this.bodyDef = new Box2D.Dynamics.b2BodyDef (); this.bodyDef.type = Box2D.Dyna Mics.b2Body.b2_staticBody; this.bodyDef.Position.x = 10; This.bodyDef.position.y = 6; stability.spep = new box2d.collection size.bc.cyclal (1); var circle = this.w .CreateBody (this.bodyDef); Circle.CreateFixture (stability); This.c = circle; This.bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; This.populate (); This.testJoints (); } Physics.prototype Protocol = function () {var stability = new box 2D. Dynamics.b2 fixstaff (); (Var i = 0; i & lt; this.testObjectCount; ++ i) for {var rnd = Math.random (); If (rnd> 0.7) {fixture.shape = Box2D.Collision.Shapes.b2PolygonShape.Asbox (Math.random () + 0.1, Math.random () + 0.1); } And if (rnd <.7 & amp; amp; rnd> .3) {fixture.shape = new Box2D.Colision.Shapes.b2CircleShape (Math.random (+ 0.1); } Else {var corner = [New Box2D.Common.Math.b2Vec2 (0.0, 0.0), New Box2D.Common.Math.b2Vec2 (1.0, 0.0), New Box2D.Common.Math.b2Vec2 (0.0, 1.0)]; Stability Size = Box 2D Coalition Shape. B2 polygon Shape.AsArray (corner); } This.bodyDef.position.x = Math.random () * 20; This.bodyDef.position.y = Math.Random () * 10; Var body = this.w.CreateBody (this.bodyDef); Body.CreateFixture (stability); This.bodies.push (body); }}; Physics.protitip.bindoconvas = function (canvas id) {var _this = this; Var debug draw = new box 2d. Dynamics.B2Debug Draw (); DebugDraw.SetSprite ((document.getElementById (canvasId) getContext ("2D").); DebugDraw.SetDrawScale (30.0); DebugDraw.SetFillAlpha (0.3); DebugDraw.SetLineThickness (1.0); Debug draw .setflag (box 2d. dynamics.b2dbugdra.a_shapbit | box 2d. dynamics.b2dbugdra.e_jointbit); This.w.SetDebugDraw (debugDraw); Window.setInterval (function () {_this.update ();}, 1000/60); }; Physics.protipip.connecttocentterwaterjoin = function (b) {var jd = new box 2d. Dynamics.juns.b2 paracetamistival def (); Var axis = box 2d. Common Math B2 Math Subtract VV (B.Getworld Center), this .. Gateworld center ()); Axis.Normalize (); Jd.Initialize (this.c, b, b.GetWorldCenter (), axis); Jd.lowerTranslation = -1; Jd.upperTranslation = 0; Jd.enableLimit = true; This.w.CreateJoint (JD); }; Physics.protipip.Testgiet = function (for (var i = 0; i & lt; this.testObjectCount; ++ i) {this.connectToCenterWithJoint (this. Bodies [i]);}}; physics.protipip ApplyTestFoce = function (for (var i = 0; i & lt; this.testObjectCount; ++ i) {this.bodies [i] .phyphorph (new Box2D.Common.Math.b2Vec2 (5000, 0), This. Bodies [i] .GetWorldCenter ());}}; Physics.protitip.update = function () {this.w.Step (1/60, 10, 10); this.w.DrawDebugData (); this. W.ClearForces ();}; Return Physics;});) The problem was that density should be set for prismatic joints to work.

OK:

fixture.density = .5;

Work here Do:

No comments:

Post a Comment