Silverlight Physics Helper (using Blend!)

Sep 16, 2008 at 2:13 PM
Hi All,

If you have tried creating a Silverlight game using Farseer
, you may have found it a bit difficult to translate your game sprites into Farseer Polygon geometries. Another challenge is lining up Farseer Joint elements with your game elements - because there is no visual link between your design tool (generally Expression Blend) and the Farseer objects.

To help with this, I’ve created a small library of Silverlight User Controls which allow for quick design of physics-based applications using Expression Blend 2.5 as the design surface and Farseer for simulations and games.

This is a preliminary alpha version, but you can do sure do some stuff with it... More details here:

Sep 16, 2008 at 10:54 PM
Very nice work Andy. It seems really easy.

You also have a nice webcast voice BTW :) hehe
Sep 16, 2008 at 11:09 PM
Thanks genbox, I had my "James Earl Jones" effects filter turned on :)

I noticed there is a refactoring effort going on with Farseer. I would welcome any suggestions for a similar object model with the "Physics Helper" controls, as I am planning on moving this into a Codeplex project. I think this approach could open up Farseer to designers and more novice programmers.
Sep 16, 2008 at 11:40 PM
I took a quick look at your code. It seems pretty okay.

It's what I would call glue-code as it as no defined structure, but focuses on "gluing" parts third-party applications together. Don't get me wrong, this is all fine as long as there is no need for a structure.

I could only find some small places where the code does some redundant casts and the like. (The compiler would take care of most of this anyway) Nothing big and a small cleanup would make the code very nice.

Have you had any thoughts about creating a debug view for Silverlight, just as XNA has it, in the Farseer XNA samples?  If you have, I might begin developing a unified structure for debugviews (if it's possible) and start up a small project that collects debugviews for different platforms.
Sep 17, 2008 at 12:02 AM
I have made some small cleanups. If you want the cleaned code, contact me by codeplex and I will reply with the code.

There is a note to be made.

I see that you have stuff like this:

public virtual double getWidth
    get { return Width; }
    set { Width = value; }

First of all, there is no need for that property as you only provide an overridable member of the class. If you wan't people to be able to override it and do some stuff (like calculations) before getting or setting the property, this should be done by methods instead. (The property is read/write anyway).
Another thing that might make this a tricky implementation; You are calling the getWidth property from the constructor. This might cause some inconsistency in your logic execution. Have a look at this and this
Sep 17, 2008 at 1:46 AM
Cool, thanks for the feedback genbox.

I'm not sure what the debug view for XNA looks like, but the code does have a PhysicsController.IsDebugMode property which shows the Body and Geometry outline for any subsequently added Farseer objects.

What I was really wondering about is how to abstract the Farseer classes into simpler, "flattened out" controls. For example, the current PhysicsJoint usercontrol includes an option for both a RevoluteJoint and an AngularSpring - lumped together into a single usercontrol. The idea here is that I didn't want to end up with a gazillion separate user controls for each separate Farseer class, forcing the user to drag/drop a bunch of related user controls onto the design surface.

So yeah, this is dumbing down the API, but if the UserControls can be designed to cover the 90% case, then the 10% case can be handled in code.

Sep 17, 2008 at 11:32 AM
The debug view for XNA is kind of like the one you made. It shows the vertices, boundingbox, center of object and so on. It's very nice in debugging physics related problems.

Oct 18, 2008 at 3:16 PM
I just wanted to note that Beta 1 of the Physics Helper is available, with some new demos (including a simple Rag Doll)

If you're using Farseer and Silverlight, you should check it out as I hope it makes your life easier!