texture to polygon, shapes is flipped horizontally

Feb 10, 2012 at 6:40 AM


I managed to create a shape from a texture, but the shape seems to be flipped horizotally... It's upside down... 
What am i doing wrong??

Thx for the help!

This is my code:

	    Vertices _verts;
            List<Vertices> _list;
            //load texture that will represent the physics body
            _polygonTexture = contentManager.Load<Texture2D>("Texture");
            //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
            _verts = PolygonTools.CreatePolygon(data, _polygonTexture.Width, false);

            //Since it is a concave polygon, we need to partition it into several smaller convex polygons
            _list = BayazitDecomposer.ConvexPartition(_verts);
            Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1)) * 10f;
            foreach (Vertices verti in _list)
                verti.Scale(ref vertScale);

            //Create a single body with multiple fixtures

            _Ground = BodyFactory.CreateCompoundPolygon(_World, _list, 1);            
            _Ground.BodyType = BodyType.Static;
            _Ground.Position = new Vector2(0, -100);

Feb 16, 2012 at 6:59 PM

Have you tried the MSTerrain.ApplyTexture() method? It will create a body in the shape of your texture. You can find an example of this in the Testbed project called "DestructibleTerrainMSTest.cs". That example sounds exactly like what you are trying to do here.

Mar 1, 2012 at 9:53 AM

The MSTerrain seems to work.

Thx for pushing me in the right direction!