Topics: Developer Forum, User Forum
Oct 4, 2012 at 2:16 PM

hi there,

i wanna use the PolygonTools.CreatePolygon with  MultiBody, i am trying to use it directli in the xna samples bevore using it in my game, i have changed the method at the moment as follows:

 //load texture that will represent the physics body
            _polygonTexture = ScreenManager.Content.Load("Samples/Map01");

            //Create an array to hold the data from the texture
            uint[] data = new uint[_polygonTexture.Width * _polygonTexture.Height];

            //Transfer the texture data to the array

            //Find the vertices that makes up the outline of the shape in the texture
            //Vertices textureVertices = PolygonTools.CreatePolygon(data, _polygonTexture.Width,false);

            List textureVertices = PolygonTools.CreatePolygon(data, _polygonTexture.Width, 0, 0,true, false);
            //The tool return vertices as they were found in the texture.
            //We need to find the real center (centroid) of the vertices for 2 reasons:

            //1. To translate the vertices so the polygon is centered around the centroid.
            //Vector2 centroid = -textureVertices.GetCentroid();
            //textureVertices.Translate(ref centroid);
            _origin = new List();
            centroid = new List();

            for (int i = 0; i < textureVertices.Count; i++ )
                centroid[i] = -textureVertices[i].GetCentroid();
                Vector2 tmp = centroid[i];
                textureVertices[i].Translate(ref tmp);
                textureVertices[i] = SimplifyTools.ReduceByDistance(textureVertices[i], 4f);

but i don't know how to calc the orgin, do i have to calc it for every part or just for one big? if anybody has an working example or an link to an tutorials this would be great