PolygonShape box = new PolygonShape();
box.setAsBox(10.0f, 0.25f);
body.createFixture(box, 1.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.initialize(ground, body, body.getPosition());
jd.lowerAngle = -8.0f * MathUtils.PI / 180.0f;
jd.upperAngle = 8.0f * MathUtils.PI / 180.0f;
jd.enableLimit = true;
m_world.createJoint(jd);
body.applyAngularImpulse(100.0f);
}
// Bridge
{
int N = 20;
PolygonShape shape = new PolygonShape();
shape.setAsBox(1.0f, 0.125f);
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 1.0f;
fd.friction = 0.6f;
RevoluteJointDef jd = new RevoluteJointDef();
Body prevBody = ground;
for (int i = 0; i < N; ++i) {
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(161.0f + 2.0f * i, -0.125f);
Body body = m_world.createBody(bd);
body.createFixture(fd);
Vec2 anchor = new Vec2(160.0f + 2.0f * i, -0.125f);
jd.initialize(prevBody, body, anchor);
m_world.createJoint(jd);
prevBody = body;
}
Vec2 anchor = new Vec2(160.0f + 2.0f * N, -0.125f);
jd.initialize(prevBody, ground, anchor);
m_world.createJoint(jd);
}
// Boxes
{
PolygonShape box = new PolygonShape();
box.setAsBox(0.5f, 0.5f);
Body body = null;
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(230.0f, 0.5f);
body = m_world.createBody(bd);
body.createFixture(box, 0.5f);
bd.position.set(230.0f, 1.5f);
body = m_world.createBody(bd);
body.createFixture(box, 0.5f);
bd.position.set(230.0f, 2.5f);
body = m_world.createBody(bd);
body.createFixture(box, 0.5f);
bd.position.set(230.0f, 3.5f);
body = m_world.createBody(bd);
body.createFixture(box, 0.5f);
bd.position.set(230.0f, 4.5f);
body = m_world.createBody(bd);
body.createFixture(box, 0.5f);
}
// Car
{
PolygonShape chassis = new PolygonShape();
Vec2 vertices[] = new Vec2[8];
vertices[0] = new Vec2(-1.5f, -0.5f);
vertices[1] = new Vec2(1.5f, -0.5f);
vertices[2] = new Vec2(1.5f, 0.0f);
vertices[3] = new Vec2(0.0f, 0.9f);
vertices[4] = new Vec2(-1.15f, 0.9f);
vertices[5] = new Vec2(-1.5f, 0.2f);
chassis.set(vertices, 6);
CircleShape circle = new CircleShape();
circle.m_radius = 0.4f;
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(0.0f, 1.0f);
m_car = m_world.createBody(bd);
m_car.createFixture(chassis, 1.0f);
FixtureDef fd = new FixtureDef();
fd.shape = circle;
fd.density = 1.0f;
fd.friction = 0.9f;
bd.position.set(-1.0f, 0.35f);
m_wheel1 = m_world.createBody(bd);
m_wheel1.createFixture(fd);
bd.position.set(1.0f, 0.4f);
m_wheel2 = m_world.createBody(bd);
m_wheel2.createFixture(fd);
WheelJointDef jd = new WheelJointDef();
Vec2 axis = new Vec2(0.0f, 1.0f);
jd.initialize(m_car, m_wheel1, m_wheel1.getPosition(), axis);
jd.motorSpeed = 0.0f;
jd.maxMotorTorque = 20.0f;
jd.enableMotor = true;
jd.frequencyHz = m_hz;
jd.dampingRatio = m_zeta;
m_spring1 = (WheelJoint) m_world.createJoint(jd);
jd.initialize(m_car, m_wheel2, m_wheel2.getPosition(), axis);
jd.motorSpeed = 0.0f;
jd.maxMotorTorque = 10.0f;
jd.enableMotor = false;
jd.frequencyHz = m_hz;
jd.dampingRatio = m_zeta;