Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

As the title says, I need to draw a shape/polygon in Farseer using debugview. I have this piece of code which converts a Texture to polygon:

//load texture that will represent the tray
        trayTexture = Content.Load<Texture2D>("tray");

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

        //Transfer the texture data to the array
        trayTexture.GetData(data);

        //Find the vertices that makes up the outline of the shape in the texture
        Vertices verts = PolygonTools.CreatePolygon(data, trayTexture.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));
        foreach (Vertices verti in _list)
        {
            verti.Scale(ref vertScale);
        }

        tray = BodyFactory.CreateCompoundPolygon(MyWorld, _list, 10);

Now in DebugView I guess I have to use "DrawShape" method which requires:

DrawShape(Fixture fixture, Transform xf, Color color)

My question is how can I get the variables needed for this method, namely Fixture and Transform?

share|improve this question
    
Have you looked at the sample implementation of the DebugView? It draws shapes perfectly for me. –  Vaughan Hilts Aug 5 '12 at 22:30
    
You will find Fixtures and Transform in created body: FixtureList and GetTransform –  krzat Feb 1 '13 at 20:45

1 Answer 1

Have you tried the official documentation?

The getting started section shows how to create a fixture:

http://farseerphysics.codeplex.com/documentation

Fixture A fixture attaches (fix) the shape to the body so that the centroid of the shape becomes the body’s position. Whenever you move the body, you also move the shape. Once a collision occur to the shape, the force is calculated and applied to the body.

Her is the code to create a World with a single body:

   1:  //Create a World object with zero gravity    
   2:  World world = new World(Vector2.Zero);    
   3:              

   4:  //We create a body object and make it dynamic (movable)    
   5:  Body myBody = world.CreateBody();    
   6:  myBody.BodyType = BodyType.Dynamic;    
   7:   
   8:  //We create a circle shape with a radius of 0.5 meters    
   9:  CircleShape circleShape = new CircleShape(0.5f);    
  10:       
  11:  //We fix the body and shape together using a Fixture object    
  12:  Fixture fixture = myBody.CreateFixture(circleShape);

You can also use the fixture factory

  Fixture fixture = FixtureFactory.CreateCircle(_world, 0.5f, 5, new Vector2(10, 0));

You can probably create a default transform (that doesn't transform anything) using:

Transfrom transform;
transform.SetIdentity();

Note that you can also use the Box2D manuals, since Farseer offers the same features.

share|improve this answer
    
Hi Roy. Farseer documentation is just obsolete since it's made for version 2.X. FixtureFactory have been removed in Version 3, and another problem is I don't want a circle shape! I want my own custom shape which is made from the texture. –  keyvan kazemi Apr 7 '12 at 16:49
    
It's true that the V3 docs are way basic, but I pulled this from them. I haven't installed Farseer, but have you looked at the other methods of the FixtureFactory, I'm sure there are more options :). –  Roy T. Apr 7 '12 at 18:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.