Breakable body supported?

May 3, 2011 at 3:03 AM

Are breakable bodies supported and if so, how do I set implement it? I looked through the behaviors, but couldn't see it. Am I supposed to add a normal Physics Object behavior and then change some settings? thanks

May 3, 2011 at 11:52 AM

No, there is nothing in the helper to support breakable bodies.

This would be a little interesting because you need to create the textures for each "piece" after the Body breaks (Farseer doesn't do this for you either). I think you could do this maybe with a polygon Clip, and then use a WriteableBitmap to get each piece into a separate Canvas (because only rectangular clips can be GPU accelerated, you wouldn't want to keep the Clip on each piece).


May 3, 2011 at 1:23 PM

I see what you mean and am trying to create it. If I have a fixture, how can I attach that fixture to a UIElement? I'm looking through the Physics Helper code but can't see how it's done. At the moment, the fixture is invisible (but still takes part in collisions). Thanks for your reply.

May 3, 2011 at 1:43 PM

Most of the linking between UI element and Physics element is done in the PhysicsSprite class. So probably what you want to do is add a constructor overload for PhysicsSprite that can define the sprite into the simulation for a "fragment" (a piece of the broken Body).

Or maybe just add a method to PhysicsSprite which handles the Break of the Body and creates more PhysicsSprite elements for each fragment.

May 3, 2011 at 2:53 PM
Edited May 3, 2011 at 2:53 PM

I'm trying your second method of adding a method, but any UIElement that I use just disappears from the screen. I'm calling the constructor like this:


PhysicsSprite ps = new PhysicsSprite(_physicsController.Simulator, LayoutRoot, breakObject, pointsList, true, 0, null, false);


'pointsList' is the points list which I obtain by iterating through the Fixture's vertices:


   List<System.Windows.Point> pl = new List<System.Windows.Point>();
   foreach(var v in ((PolygonShape)firstFix.Shape).Vertices)
        pointsList.Add(new System.Windows.Point(v.X,v.Y));
May 3, 2011 at 2:56 PM

Not sure but it might be that you need to convert from screen X,Y to world X,Y for those points. The PhysicsController class has ScreenToWorld and WorldToScreen methods for doing this.

May 3, 2011 at 3:49 PM

No luck :( I tried changing it to:

foreach(var v in ((PolygonShape)firstFix.Shape).Vertices)
      var newPoint = new System.Windows.Point(v.X, v.Y);
      Vector2 vec = _physicsController.ScreenToWorld(newPoint);
      pointsList.Add(new System.Windows.Point(vec.X,vec.Y));