Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Introducing Farseer - An Open Source Physics Engine for Silverlight and XNA

Introducing Farseer - An Open Source Physics Engine for Silverlight and XNA

In the modern push for showier and more interactive interfaces, it is inevitable that real-time animation is going to be asked for from time to time. When this animation involves objects on the screen bouncing off each-other or being affected by gravity, a physics engine is a must.

The Farseer Physics Engine, though primarily billed as something for writing 2D games, addresses this need. We interviewed Jeff Weber, designer of Farseer.

Why did you decide to start the Farseer Physics Engine project in the first place?

I built the Farseer Physics Engine because I had a desire to make 2D physics games using .Net. I looked around for a good 2D physics engine written in managed code that would allow me to make the games I had in my head. There were very few and the ones that did exist didn't quite have all the features I knew I would need.

There was however a very interesting C++ physics engine called Box2D written by Erin Catto. It had most the features I needed and I was pretty sure I could add the rest so I decided to use it as a basis to build my own managed physics engine. The Farseer Physics Engine is this engine.

Note: The Box2D engine behind the link above is a newer version of Erin Catto's engine. The concepts are similar but Farseer was build of an earlier version of the Box2D engine.

Do you have any prior background in physics engines or are you learning this as you go?

I have a B.S. in Mathematics from way back. I never really had the opportunity to use it until I started doing game development as a hobby about 6 yrs ago. Since then I've always tried to include some type of physics in my projects, which, by the way, have always just ended up being demos of one sort or another rather than a finished game.

I was also fortunate enough to work for about a year on a Truck Driving simulator several years back for my "real" job as a .Net developer consultant. For that project we used the Open Dynamics Engine (ODE) with a managed .Net wrapper.

So, yes I've had some experience here and there with physics and physics engines, but the Farseer Physics Engine is my first "finished" project outside of my day job.

When having to choose between ease of use and power/flexibility, which direction do you tend to lean towards when creating libraries like Farseer?

With Farseer simple-to-use was definitely my primary goal. I even had "Keep It Simple" written on my whiteboard. (still do actually) The object hierarchy of some of my earlier versions started to get more and more complex with a bunch of abstract classes, interfaces, and levels of inheritance Finally I remembered my goal to keep it simple and re-factored everything to meet that goal. I am very happy with the way it turned out.

In general I try to find a balance between power, flexibility, ease-of-use, and finishing in a timely manner. If I have to lean one way or the other, I lean toward keeping things simple.

Have you given any thought to compatibility with non-Microsoft runtimes like Mono?

Not really. Not to sound too selfish, but I really created Farseer for my own needs. I don't use Mono and I don't have any immediate plans to use it so I've never really given it any consideration. I'll leave that up to others. I'm guessing it would be an easy port as the engine doesn't really rely on to much outside the core .Net framework.

Overall, what is your impression of Silverlight and XNA for building software like this? Does they lend themselves to this kind of code or do you find yourself fighting against the platforms?

I love both these frameworks and both lend themselves well to Farseer. Farseer is pretty much identical on both these platforms. The Silverlight version required the creation of some math constructs to duplicate those in XNA, but other than that the only difference is that each is compiled against different version of the .Net framework. The demos, of course were a little more work. Bill Reiss of Blue Rose Games was the guy who ported both the Farseer Physics Engine and demos to Silverlight. It was a great idea to do the port and I'm very glad he approached me about it.

Currently, I've moved away from XNA for a while and I am focusing more on Silverlight. I'm able to get things on screen and usable much quicker in Silverlight than in XNA. Mostly because of the 2D vector drawing built into Silverlight. I wish Microsoft would build an XAML parser into the XNA framework.

I also like the idea of building games for the web. I think there is a bright future there.

What are your future plans for Farseer?

My future plans mostly revolve around actually USING the Farseer Physics Engine now that it's finished. I will continue to update it as useful

ideas/code is submitted by users or when I need some new functionality for games I'm writing. I've already had some very good stuff submitted by users in the user forum and I'm working on getting that incorporated into the engine.

Overall, I'd like to use the engine to make the games I have in my head and to hopefully earn some supplemental income from them. I currently have a Silverlight game in progress that I feel is unlike most existing web games. (I know, they all say that.) Oddly enough, this will be my first finished game since I started game development as a hobby 5 or 6 years ago.

The Farseer Physics Engine is available on CodePlex.

Rate this Article