How can I create polygons in Farseer 3.3.1?

Topics: User Forum
May 20, 2013 at 6:54 PM
I tried the example in the documentation but it isn't working. I always get these two error messages:
No overload for method 'CreatePolygon' takes 4 arguments
'FarseerPhysics.Factories.FixtureFactory' does not contain a definition for 'CreateCompoundPolygon'

What is wrong? How can I create polygons?
//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
            polygonTexture.GetData(data); 
            //Find the vertices that makes up the outline of the shape in the texture
          Vertices  verts = PolygonTools.CreatePolygon(data, polygonTexture.Width, polygonTexture.Height, true);
            //For now we need to scale the vertices (result is in pixels, we use meters)
            Vector2 scale = new Vector2(3.50f, 1.50f);
            verts.Scale(ref scale);  
            //Since it is a concave polygon, we need to partition it into several smaller convex polygons
            _list = BayazitDecomposer.ConvexPartition(verts);   
            //Create a single body with multiple fixtures
            List<Fixture> compund = FixtureFactory.CreateCompoundPolygon(world, _list, 1);
            compund[0].Body.BodyType = BodyType.Dynamic; 
May 21, 2013 at 12:15 AM
Try changing
List<Fixture> compund = FixtureFactory.CreateCompoundPolygon(world, _list, 1);
compund[0].Body.BodyType = BodyType.Dynamic;
to
Body body = BodyFactory.CreateCompoundPolygon(world, _list, 1);
body.BodyType = BodyType.Dynamic;
May 21, 2013 at 8:35 AM
Thanx. But I still have difficulties with this line:
 //Find the vertices that makes up the outline of the shape in the texture
          Vertices  verts = PolygonTools.CreatePolygon(data, polygonTexture.Width, polygonTexture.Height, true);
No overload for method 'CreatePolygon' takes 4 arguments

What should I change in this line?
May 21, 2013 at 8:47 AM
Look at the specs! Its (data, width, holeDetection), so change it to
Vertices  verts = PolygonTools.CreatePolygon(data, polygonTexture.Width, true);
But I highly recommend to look at the farseer samples project. There, AdvancedDemo1 greatly explains how to make an physical object out of a texture.
May 22, 2013 at 9:21 PM
Thanx. That helped me a lot.