#pragma mark bridge
b2Body* ground = NULL;
{
b2PolygonDef sd;
sd.SetAsBox(0.2f, 0.1f);
b2BodyDef bd;
bd.position.Set(0.0f, 0.0f);
ground = m_world->CreateBody(&bd);
ground->CreateShape(&sd);
}
{
b2PolygonDef sd;
sd.SetAsBox(0.5f, 0.125f);
sd.density = 20.0f;
sd.friction = 0.2f;
b2RevoluteJointDef jd;
const int32 numPlanks = 30;
b2Body* prevBody = ground;
for (int32 i = 0; i < numPlanks; ++i)
{
b2BodyDef bd;
bd.position.Set(-14.5f + 1.0f * i, 5.0f);
b2Body* body = m_world->CreateBody(&bd);
body->CreateShape(&sd);
body->SetMassFromShapes();
b2Vec2 anchor(-15.0f + 1.0f * i, 5.0f);
jd.Initialize(prevBody, body, anchor);
m_world->CreateJoint(&jd);
prevBody = body;
}
b2Vec2 anchor(-15.0f + 1.0f * numPlanks, 5.0f);
jd.Initialize(prevBody, ground, anchor);
m_world->CreateJoint(&jd);
}
No comments:
Post a Comment