pd.friction = friction;
pd.restitution = restituion;
}
//Create polygon body
BodyDef dymBodyDef = new BodyDef();
// dymBodyDef.position = new Vec2(position.x /worldScale, position.y /worldScale);
dymBodyDef.position = new Vec2(position.x , position.y );
this.bodyDefB4CreationCallback(dymBodyDef);
this.body = world.createBody(dymBodyDef);
// 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));
//Decompose poly and add verts to phys body if possible
int success = org.jbox2d.util.nonconvex.Polygon.decomposeConvexAndAddTo(myPoly, this.body, pd);
if (success != -1){
System.out.println("-> Ear clipping SUCCESSFUL -> Using triangulated and polygonized shape for b2d.");
this.body.setMassFromShapes();
this.body.setUserData(this);
this.setUserData("box2d", this.body); //TODO rename userData
//Performance hit! but prevents object from sticking to another sometimes
// theBody.setBullet(true);
}else{
System.out.println("-> Ear clipping had an ERROR - trying again by triangulating shape for b2d with GLU-Triangulator");
// GluTrianglulator triangulator = new GluTrianglulator(app);
// List<Vertex> physicsTris = triangulator.tesselate(bodyVerts, GLU.GLU_TESS_WINDING_NONZERO);
// Vertex[] triangulatedBodyVerts = physicsTris.toArray(new Vertex[physicsTris.size()]);
//System.out.println("GLU tris created: " + triangulatedBodyVerts.length);
//Cap the max triangles - dont use anymore triangles for the physics body..
int cap = 400;
if (triangulatedBodyVerts.length > cap){
//System.err.println("OVER cap! -> capping!");
Vertex[] tmp = new Vertex[cap];
System.arraycopy(triangulatedBodyVerts, 0, tmp, 0, cap);
triangulatedBodyVerts = tmp;
}
//Create polygon body
world.destroyBody(this.body);
dymBodyDef = new BodyDef();
dymBodyDef.position = new Vec2(position.x, position.y);
this.bodyDefB4CreationCallback(dymBodyDef);
this.body = world.createBody(dymBodyDef);
for (int i = 0; i < triangulatedBodyVerts.length/3; i++) {
//Create polygon definition