Hello! I am writing an application using box2d physics & I found a prismatic joint bug (as i think):
Code:
b2BodyDef bodyLadder1Def;
bodyLadder1Def.type = b2_dynamicBody;
bodyLadder1Def.position.Set(400 / PTM_RATIO, 400 / PTM_RATIO); // PTM_RATIO = 46
bodyLadder1Def.angularDamping = 0.5f;
bodyLadder1Def.linearDamping = 0.5f;
b2Vec2 verticesLadder1[4];
verticesLadder1[0].Set(0.0000f, 0.0000f);
verticesLadder1[1].Set(2.6739f, 0.0000f);
verticesLadder1[2].Set(2.6739f, 0.4130f);
verticesLadder1[3].Set(0.0000f, 0.4130f);
b2PolygonShape dynamicBox;
dynamicBox.Set(verticesLadder1, 4);
b2Body *ladder1Body = world->CreateBody(&bodyLadder1Def);
b2FixtureDef fixtureLadder1Def;
fixtureLadder1Def.shape = &dynamicBox;
fixtureLadder1Def.density = 100.0f;
fixtureLadder1Def.friction = 1.0f;
fixtureLadder1Def.restitution = 0.5f;
fixtureLadder1Def.filter.maskBits = 0x0001;
ladder1Body->CreateFixture(&fixtureLadder1Def);
// part 2
b2BodyDef bodyLadder2Def;
bodyLadder2Def.type = b2_dynamicBody;
bodyLadder2Def.position.Set(400 / PTM_RATIO, 400 / PTM_RATIO);
bodyLadder2Def.angularDamping = 0.5f;
bodyLadder2Def.linearDamping = 0.5f;
b2Vec2 verticesLadder2[4];
verticesLadder2[0].Set(0.0000f, 0.0000f);
verticesLadder2[1].Set(3.9560f, 0.0000f);
verticesLadder2[2].Set(3.9560f, 0.2391f);
verticesLadder2[3].Set(0.0000f, 0.2391f);
b2PolygonShape dynamicLadder2Box;
dynamicLadder2Box.Set(verticesLadder2, 4);
b2Body *ladder2Body = world->CreateBody(&bodyLadder2Def);
b2FixtureDef fixtureLadder2Def;
fixtureLadder2Def.shape = &dynamicLadder2Box;
fixtureLadder2Def.density = 100.0f;
fixtureLadder2Def.friction = 1.0f;
fixtureLadder2Def.restitution = 0.5f;
fixtureLadder2Def.filter.maskBits = 0x0001;
ladder2Body->CreateFixture(&fixtureLadder2Def);
// joint
b2PrismaticJointDef prismaticJointDef;
b2Vec2 worldAxis(1.0f, 0.0f);
prismaticJointDef.Initialize(ladder1Body, ladder2Body, b2Vec2((400.0f) / PTM_RATIO, (400.0f) / PTM_RATIO), worldAxis);
world->CreateJoint(&prismaticJointDef);
When I run this code on 2.1.0 version of box it works fine. But in version 2.1.2 (and 2.2 now) world sometimes crashes during one body goes through another.
Here are screencasts of program behaviour (an iPad simulator with cocos2d framework)
http://dl.dropbox.com/u/17069366/new_dont_work.swfhttp://dl.dropbox.com/u/17069366/old.swf