private float restituion;
public PhysicsPolygon(Vertex[] vertices, Vector3D position, PApplet applet,
World world, float density, float friction, float restitution, float worldScale
) {
super(applet, new GeometryInfo(applet, new Vertex[]{}), false);
this.angle = 0;
this.world = world;
this.density = density;
this.friction = friction;
this.restituion = restitution;
this.setGestureAllowance(ScaleProcessor.class, false);
this.setGestureAllowance(RotateProcessor.class, false);
Vertex.scaleVectorArray(vertices, Vector3D.ZERO_VECTOR, 1f/worldScale, 1f/worldScale, 1);
position.scaleLocal(1f/worldScale); //FIXME REALLY?
GluTrianglulator triangulator = new GluTrianglulator(applet);
List<Vertex> physicsTris = triangulator.tesselate(vertices, GLU.GLU_TESS_WINDING_NONZERO);
Vertex[] triangulatedBodyVerts = physicsTris.toArray(new Vertex[physicsTris.size()]);
triangulator.deleteTess();
//Set the triangulated vertices as the polygons (mesh's) vertices
this.setGeometryInfo(new GeometryInfo(applet, triangulatedBodyVerts));
this.translate(position);
Vector3D realBodyCenter = this.getCenterPointGlobal(); //FIXME geht nur if detached from world //rename futurebodycenter?
//Reset position
this.translate(position.getScaled(-1));
//Now get the position where the global center will be after setting the shape at the desired position
this.setPositionGlobal(position);
Vector3D meshCenterAtPosition = this.getCenterPointGlobal();
//Compute the distance we would have to move the vertices for the body creation
//so that the body.position(center) is at the same position as our mesh center
Vector3D realBodyCenterToMeshCenter = meshCenterAtPosition.getSubtracted(realBodyCenter);
//System.out.println("Diff:" + realBodyCenterToMeshCenter);
//Move the vertices so the body position is at the center of the shape
Vertex.translateVectorArray(triangulatedBodyVerts, realBodyCenterToMeshCenter);
this.setGeometryInfo(new GeometryInfo(applet, triangulatedBodyVerts));
// MTPolygon p = new MTPolygon(vertices, applet);
// p.translate(position);
//// p.setPositionGlobal(position);
// Vector3D realBodyCenter = p.getCenterPointGlobal(); //FIXME geht nur if detached from world //rename futurebodycenter?