Jun 22, 2010 at 6:48 PM
Edited Jun 22, 2010 at 6:48 PM
For the last project using the Farseer Physics Engine (Snow Spill) I developed a simple technique to make creating bodies in the engine and attaching them to ui elements in Silverlight much easier.
I've started wondering if anybody else would find this useful.
I don't have access to the code right now so I'm doing this from memory, but it works something like this.
<local:PhysicalBox Width="400" Height="600">
<Rectangle Canvas.Left="20" Canvas.Top="40" Width="100" Height="20">
<local:PhysicalRectangle Mass="14" RestitutionCoefficient="0.1" />
PhysicalBox derives from canvas and creates the simulator. It looks for ui elements that have the Body attached property set, and adds the bodies to the simulator. PhysicalRectangle is a class that will create the body with geometries for the simulator.
Then in your own loop when you call Update on the PhysicalBox The ui elements will be moved and rotated based on the body in the simulator. There are other classes that create bodies for ellipses and polygons too. Or you can set the geometry (or geometries)
manually. I also created some other ui elements that make different joints. I never created springs but it would be easy to do.
I've looked a little into the Physics Helper for Silverlight project, and this is probably very similar. But I believe this method has a little more emphasis on control and less on blend integration.
I was considering moving this code to it's own Silverlight dll and starting a project on CodePlex. Would anybody be interested in using this and/or helping me maintain the project?