Vec2 vertices[] = new Vec2[3];
vertices[0] = new Vec2(-1.0f, 0.0f);
vertices[1] = new Vec2(1.0f, 0.0f);
vertices[2] = new Vec2(0.0f, 2.0f);
PolygonShape polygon = new PolygonShape();
polygon.set(vertices, 3);
FixtureDef triangleShapeDef = new FixtureDef();
triangleShapeDef.shape = polygon;
triangleShapeDef.density = 1.0f;
BodyDef triangleBodyDef = new BodyDef();
triangleBodyDef.type = BodyType.DYNAMIC;
triangleBodyDef.position.set(MathUtils.randomFloat(xLo, xHi), MathUtils.randomFloat(yLo, yHi));
Body body1 = getWorld().createBody(triangleBodyDef);
body1.createFixture(triangleShapeDef);
// Large triangle (recycle definitions)
vertices[0].mulLocal(2.0f);
vertices[1].mulLocal(2.0f);
vertices[2].mulLocal(2.0f);
polygon.set(vertices, 3);
triangleBodyDef.position.set(MathUtils.randomFloat(xLo, xHi), MathUtils.randomFloat(yLo, yHi));
Body body2 = getWorld().createBody(triangleBodyDef);
body2.createFixture(triangleShapeDef);
// Small box
polygon.setAsBox(1.0f, 0.5f);
FixtureDef boxShapeDef = new FixtureDef();
boxShapeDef.shape = polygon;
boxShapeDef.density = 1.0f;
BodyDef boxBodyDef = new BodyDef();
boxBodyDef.type = BodyType.DYNAMIC;
boxBodyDef.position.set(MathUtils.randomFloat(xLo, xHi), MathUtils.randomFloat(yLo, yHi));
Body body3 = getWorld().createBody(boxBodyDef);
body3.createFixture(boxShapeDef);
// Large box (recycle definitions)
polygon.setAsBox(2.0f, 1.0f);
boxBodyDef.position.set(MathUtils.randomFloat(xLo, xHi), MathUtils.randomFloat(yLo, yHi));
Body body4 = getWorld().createBody(boxBodyDef);
body4.createFixture(boxShapeDef);