This project has moved and is read-only. For the latest updates, please go here.

Better integrator?

Topics: Developer Forum
Aug 14, 2009 at 7:34 PM

Hi everyone,

I have a physics engine of my own that I've been writing for a few months and I've been using it in my own little games. About a week ago I found Farseer and noticed that its interfaces are pretty close to my own engine, so I thought I'd give it a try (Farseer also contains a lot of stuff that my engine doesn't). I changed the physics engine to one of my games in less than two hours, which I think is pretty amazing itself.

But to the point: Farseer is going to save me a lot of time, but there are two things that were better in my engine:

  1. Mine uses RK4 integrator instead of Euler. For a game that involves vehicle physics (short, fast moving springs, etc.) I had to use 500 hz simulation with Farseer to achieve satisfactory accuracy -- with my own engine 200 hz was enough. With this difference RK4 also has the performance benefit, not to mention accurary.
  2. This is definitely (also) a matter of taste, but the maintainability of my code is better than Farseer's, which made fixing the problem above a pain in the ass. The manual function inlining was the single most repulsive thing. Does it actually help? The compiler inlines small functions anyway.

Anyway, keep up the good work! Version 3.0 sounds promising.


Aug 14, 2009 at 7:58 PM
Edited Aug 14, 2009 at 7:59 PM

1. As you mention, usually it is a matter of taste. In this case tho, it was simply because Euler is the most basic ODE (Ordinary Differential Equation) solver. The first Farseer Physics engine was as simple as they come. Euler integrator, brute force broad phase, distance grid narrow phase and the basics of sequential impulse with warm starting. It was built on Box2D lite back in the day.

The goal was a simple physics engine and thus it could also be very slow. Since then it has received several broadphases/narrowphases, caching and more elaborate physics.

2. I agree. I don't like the manual inline either, but it was necessary to get it running at a decent speed on the Xbox 360. The .net compiler has since then become better at optimizing code (it can inline with structs as argument in methods now) but manual inlining still beats it. To keep the physics engine simple while also running with decent performance on Xbox, we had no choice but to do a lot of manual optimizations to the code.

In 3.0 the algorithms will be a lot more complex but also a lot faster. Several optimization methods have been implemented to get the most out of the engine and already now we have a faster engine than older versions of Farseer Physics.


Thanks for writing about this. I like that people take their time to dig into the code and try to improve it. The current code has a lot of community contributed code that makes the engine what it is today. With 3.0 we start from scratch and with our previous and hopefully new contributions, we will get a better, fully featured and more efficient engine.