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.

Using Farseer 3.3.1 I want to create a rectangular BreakableBody with many pieces. Right now here is my code:

Vertices polygon = PolygonTools.CreateRectangle( 2.5f , 1.25f );
List<Vertices> triangulated = FlipcodeDecomposer.ConvexPartition(polygon);
BreakableBody breakableBody = new BreakableBody(triangulated, World, 1);
breakableBody.MainBody.Position = Vector2.Zero;
breakableBody.Strength = 5;
World.AddBreakableBody(breakableBody);

This code turns the rectangle into two pieces (cut from corner to corner). I have tried four of the five decomposing methods (Flipcode, Bayazit, CDT and Earclip). I also haven't been able to find any good examples of a rectangle being divided into multiple pieces.

Preferably, I am looking for a way to create random sized pieces, but cutting it into 32 cubes ( 8 x 4 ) would be fine also.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Farseer breaks apart the bodies along existing polygons, it will not create new ones for you.

You seem to misunderstand what decomposing is. It breaks apart complex polygons into the triangles necessary to represent it. It always takes 2 triangles to represent a polygon so that is why your body keeps breaking to 2 triangles.

Try something along the lines of the below (Note this is just of the top of my head)

List<Vertices> pieces = new List<Vertices>();
for (int x = -4; x < 4; x++)
  for (int y = -1; y < 1; y++)
    pieces.add(PolygonTools.CreateRectangle(1, 1, new Vector2(x,y)));
_breakablebody = new BreakableBody(pieces, World, 1);
share|improve this answer
    
Yes, I learned this in between when I asked and now (but forgot to come back to address my question :p). But this is the solution I used, so thank you for your answer. –  Andrew Jackman Feb 19 '12 at 8:25

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.