Oi people. I've been having a problem with a simple shape that's important to the program I'm making. The shape is just an X made from five boxes, joined by four revolute joints, with the hubs in the corner boxes. Something so simple should work fine right?? Well, try it yourself and see. (Code for this is below.)
My project uses JBox2D, but the code below is for Box2D. This problem also appears in the D port of Box2D, I guess. Here's the thread I made in the JBox2D forum: viewtopic.php?f=9&t=3602
It contains more information about the problem I saw in the ports. But the problem is pretty much the same in all versions, I guess: just a crazy dancing X when what I ordered was a rigid, sedate X. So, what's the deal? Is this a known problem? Is it gonna be fixed? Is there a workaround?
My project uses JBox2D, but the code below is for Box2D. This problem also appears in the D port of Box2D, I guess. Here's the thread I made in the JBox2D forum: viewtopic.php?f=9&t=3602
It contains more information about the problem I saw in the ports. But the problem is pretty much the same in all versions, I guess: just a crazy dancing X when what I ordered was a rigid, sedate X. So, what's the deal? Is this a known problem? Is it gonna be fixed? Is there a workaround?
Code:
// place this chunk of code into the end of the SphereStack constructor;
// run the SphereStack test in the testbed; watch as the terror known as
// the catastrophe reveals itself
float offset = 5;
float boxWidth = .5;
float xo = -17.5;
float yo = 15;
int xs[4] = {1, -1, -1, 1};
int ys[4] = {1, 1, -1, -1};
b2BodyDef bodyDefinition;
b2PolygonDef boxDefinition;
boxDefinition.SetAsBox(boxWidth, boxWidth);
boxDefinition.density = 1;
bodyDefinition.position.Set(xo, yo);
b2Body* center = m_world->CreateBody(&bodyDefinition);
center->CreateFixture(&boxDefinition);
center->SetMassFromShapes();
for (int i = 0; i < 4; i++)
{
bodyDefinition.position.Set(offset * xs[i] + xo, offset * ys[i] + yo);
b2Body* box = m_world->CreateBody(&bodyDefinition);
box->CreateFixture(&boxDefinition);
box->SetMassFromShapes();
b2RevoluteJointDef jointDefinition;
jointDefinition.Initialize(box, center, box->GetWorldCenter());
m_world->CreateJoint(&jointDefinition);
}
// run the SphereStack test in the testbed; watch as the terror known as
// the catastrophe reveals itself
float offset = 5;
float boxWidth = .5;
float xo = -17.5;
float yo = 15;
int xs[4] = {1, -1, -1, 1};
int ys[4] = {1, 1, -1, -1};
b2BodyDef bodyDefinition;
b2PolygonDef boxDefinition;
boxDefinition.SetAsBox(boxWidth, boxWidth);
boxDefinition.density = 1;
bodyDefinition.position.Set(xo, yo);
b2Body* center = m_world->CreateBody(&bodyDefinition);
center->CreateFixture(&boxDefinition);
center->SetMassFromShapes();
for (int i = 0; i < 4; i++)
{
bodyDefinition.position.Set(offset * xs[i] + xo, offset * ys[i] + yo);
b2Body* box = m_world->CreateBody(&bodyDefinition);
box->CreateFixture(&boxDefinition);
box->SetMassFromShapes();
b2RevoluteJointDef jointDefinition;
jointDefinition.Initialize(box, center, box->GetWorldCenter());
m_world->CreateJoint(&jointDefinition);
}