Polygon poly = (Polygon) shape;
PolygonDef def = new PolygonDef();
// TODO Set def.density for realistic mass;
def.restitution = (float) elasticity;
for (int i = 0; i < poly.npoints; i++) {
def.vertices.add(new Vec2(poly.xpoints[i], poly.ypoints[i]));
}
return def;
} else if (shape instanceof Ellipse2D) {
Ellipse2D ell = (Ellipse2D) shape;
CircleDef def = new CircleDef();
def.localPosition = new Vec2((float) ell.getCenterX(), (float) ell.getCenterY());
def.radius = (float) (ell.getWidth() / 2);
def.restitution = (float) elasticity;
return def;
}
throw new RuntimeException("Shape type not implemented: " + shape.getClass());