This project has moved and is read-only. For the latest updates, please go here.

Path generated "soft body" question

Topics: Developer Forum, User Forum
Mar 27, 2013 at 11:56 AM
Edited Mar 27, 2013 at 11:58 AM

I'm quite new to farseer and currently working on a small game. I've created a soft body made of solid ones with the path generator from one of the samples.

Now what I am wondering is if anyone has any idea about how i could color everything so it just looks like a single body? I thought that maybe I could create a polygon where all the vertices are all the small bodies positions and then fill that with a texture/color, and then update the positions as it moves in the world. But I've gotten nowhere after some days now and I cannot find any questions about this on the internet so thought I could ask here if someone has tried to do this before and has any ideas/tips! Some sample code would be creatly appreciated since I'm not so good at this :) (if its even possible at all)

(I'm working in xna)
Mar 27, 2013 at 6:34 PM
Triangles are your friend. I would try creating a triangle from each line segment in the outer edge of your soft body polygon to a point in the middle (any point in the middle would do). Alternatively you could just try using one of the polygon cutting tools that ships with farseer. Anyway, once you have an array of triangles, you can use DrawUserPrimitives on GraphicsDevice with PrimitiveType.TriangleList. You can modify the existing PrimitiveBatch class in farseer to accommodate a TriangleList without too much trouble.

I think that should work for you.

Good luck!
Mar 28, 2013 at 1:44 PM
Edited Mar 28, 2013 at 1:44 PM
I've tried using DrawUserPrimitives in the following way:
private void SetUpVertices()
    vertices = new VertexPositionColor[3];

    Color color = Color.Green;

    vertices[0].Position = new Vector3(middlePoint.X, middlePoint.Y, 0f);
    vertices[0].Color = color;
    vertices[1].Position = new Vector3(softBodies[1].Position.X, softBodies[1].Position.Y, 0f);
    vertices[1].Color = color; 
    vertices[2].Position = new Vector3(softBodies[2].Position.X, softBodies[2].Position.Y, 0f);
    vertices[2].Color = color;
public void Draw(SpriteBatch spriteBatch)
    effect.CurrentTechnique = effect.Techniques["Pretransformed"];
    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
          gd.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1, VertexPositionColor.VertexDeclaration);
That should from what I understand draw a triangel from a point in the middle (which i know is correct from testing) and the first 2 bodies in the path, but the code does not seem to draw anything, no triangle appears. I also tried coverting the vertices to displayunits with the convertunits class from the farseer samples. Seems like I am missing something :/

The vertices function is running in every update so the positions should be updated as the body moves aswell.

The effect is from the file riemers posted in a tutorial that seemed to be recommended to use for simple triangles :)