This project has moved. For the latest updates, please go here.

texture to polygon problem

Topics: Developer Forum, User Forum
Feb 26, 2011 at 12:55 PM


I'm trying to make a Polygon from a Texture2D but it works very very bad :( What did I make wrong ? Could someone help me please ?


            texture = Content.Load<Texture2D>("object");


#region cut

            uint[] data = new uint[texture.Width * texture.Height];
            Vertices textVertices = PolygonTools.CreatePolygon(

            Vector2 scale = new Vector2(0.01f, -0.01f);
            textVertices.Scale(ref scale);

            textVertices = SimplifyTools.ReduceByDistance(textVertices, 1f);

            liste = BayazitDecomposer.ConvexPartition(textVertices);

            myBody = BodyFactory.CreateBody(world);
            myBody.BodyType = BodyType.Dynamic;

            foreach (Vertices v in liste)
                myBody.CreateFixture(new PolygonShape(v, 1));

            rectangle = FixtureFactory.CreatePolygon(textVertices, 1, myBody);


            spriteBatch.Draw(texture, ConvertUnits.ToDisplayUnits(rectangle.Body.Position) , Color.White);
Feb 28, 2011 at 6:55 PM
Edited Feb 28, 2011 at 7:07 PM

I'm guessing you have the same problem I had a couple of days ago where my fixtures were all upside down and the reason for that is because I, like you are doing, was flipping the y-axis (note the -0.01f for the y-axis) when initializing the scale variable.

Trying using 'Vector2 scale = new Vector2(0.01f);' instead and see how it goes.


Also, check out the latest Texture-to-Vertices sample because it's implemented a bit differently there.


Finally, I would also recommended you spend some time setting up the DebugView because the data it provides is invaluable; in fact, I realized that my fixtures were all upside down with the help of the DebugView (and I was on the verge of tearing my hair out :] )

Mar 1, 2011 at 6:01 PM

Thanks for your response =)

new Vector(0.01f) didn't resolve the problem :'(  .... I'm trying with TextureConverter but I've an assert error :s