Mar 2, 2013 at 7:25 PM
Edited Mar 2, 2013 at 9:34 PM
Hi, i'm pretty new to Farseer Physics and i'm trying to use it to build a worms-like game.
I downloaded the TestBed project and robert's patch for destructable body and tried to use it with the Texture2polygon method found in samples files.
The ground (terrain) vertices are calculated this way:
uint data = new uint[_polygonTexture.Width * _polygonTexture.Height];
textureVertices = PolygonTools.CreatePolygon(data, _polygonTexture.Width, false);
Vector2 centroid = -textureVertices.GetCentroid();
// draw the texture the correct place.
_origin = -centroid;
//We simplify the vertices found in the texture.
textureVertices = SimplifyTools.ReduceByDistance(textureVertices, 6f);
//We create a new destructable body for the whole polygon
// no need to decompose the vertices, it'll be done with the creation of the
// destructable body
DestructableBody db = new DestructableBody(world, textureVertices);
_ground = db.Body;
used this way, the destructable body scales at a very strange size so, in the DestructableBody.CreateFixture i've forced vertices to be scaled the size I want by using verties.Scale(ref _myscale). This cause the Scale to be applied everytime a shape is subtracted
to the destructable body.
The problem is, now the subtracted shape is not calculated the correct place : the algorithm is subtracting shape at the place the _ground would be if I weren't scaling it. Otherwise, the algorithm seems to be working pretty well, unless there is no holes gestion
(which i don't need)
I think the problem comes from the fact we scale the polygon everytime but if i got the texture scaled only once, before converting it to destructable body, it loss its scales as soon as I subtract a new shape...
This problem is giving me headache at the moment, please help, any ideas or sugestions are welcomed, I can post more source/screenshots if needed.
EDIT: Moreover, when the body is splited up, i can no longer subtract a shape from the new bodies from the bullet OnCollision eventHandler : I got a NullReferenceException in the Update method of the Contact class.