I want to create something similar to this using farsser and Kinect:


This is my implementation until now:


I have the outline vertices and the triangulation of the user. And following the Texture to Polygonmsample i used this line to create the shape, where farseerObject is a list of vertices of the triangles:

_compound = BodyFactory.CreateCompoundPolygon(World, farseerObject, 1f, BodyType.Dynamic);

But I have to update the body each frame (like 30 fps) and this is very slow. I get just 2 or 3 fps.

There's another (faster) way to create the Body from a list of triangles or the contour vertices?

How do you think they do this on Box2D?


After some testings i used EdgeShapes for the user contour (without triangulation) and i update the vertices for that edges in the fixtures every frame, now all is faster.

((EdgeShape)(farseerBody.FixtureList[i].Shape)).Vertex1 = new Vector2(farseerVertices[i].X, farseerVertices[i].Y);

But the collisions does not work!

My approach is incorrect?

  • \$\begingroup\$ Are you creating the whole thing every frame? Might be running a little slow if you create huge amounts of garbage perhaps? In that case just try to recycle the same objects instead. \$\endgroup\$ – Mikael Högström Sep 3 '12 at 17:42
  • \$\begingroup\$ Do you see the video? The user contour is created every frame, so the vertices are differents. There are some Body type that I can recycle? <br/> This is another example in Box2D youtube.com/watch?v=BPWKx3KAvTI \$\endgroup\$ – EdgarT Sep 3 '12 at 19:50
  • \$\begingroup\$ Until i know, farseer physics is "based" on box2d. There must be a way to do this. I feel that i missing something obvious or not? \$\endgroup\$ – EdgarT Sep 3 '12 at 19:59
  • \$\begingroup\$ why you need to triangulate if you are just using the overall shape? \$\endgroup\$ – user827992 Sep 3 '12 at 20:11
  • \$\begingroup\$ Because the object needs to be convex, or not? I did a test using the ear clipping algorithm and a get up to 10fps, not much better... \$\endgroup\$ – EdgarT Sep 3 '12 at 20:18

Finally works!

I had the vertices of the contour as a sequence, so the solution was use the LoopShape to create the fixture of the body. I did not even know that Class =P

 LoopShape loopShape = new LoopShape(farseerVertices);
 //Delete the previous fixture
 //Create new fixture with the new contour

And that's all!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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