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

Farseer Physics Engine 3.0 Status update

Sep 21, 2009 at 9:47 PM

I think it is time for a new status update on the ongoing porting work and future of Farseer Physics Engine.

We were 4 guys updating the source code and we got to the point where we had a working version of Box2D ported to C#. In the middle of it all Erin (the Box2D owner) switched source control to google code and implemented some HUGE changes. Unfortunately 3 of my team members had other things to do and opted out, so things are not going too fast at the moment. I've been able to keep up with Erin in that I recently updated the source code to revision 17 and the simulation seems like it is working (still some known problems left).

Erin has been very busy with fixing the latest bugs. Today (Monday 21 September) Erin fixed 3 more bugs and added a new test to the testbed. I will be updating to revision 21 (that contains those 4 changes) on Tuesday - So everything is still going well. Just to give you an idea of the latest changes and what they do, I've compiled a list:

Broad phase based on Dynamic Tree

The broad phase looks finished and it is working very well. It is a lot simpler than the previous one and it is just as fast. The algorithm is based on a tree structure of AABBs and is easy to extend. The broadphase is decoupled from the dynamic tree implementation so you are able to use the dynamic tree algorithm for other stuff in your game.

Automatic mass generation

Erin removed the manual call to SetMassFromShape() and made it automatic. You no longer have to worry about calling that method after creating a shape and that makes for leaner and more readable code. It was actually one of the main things I was going to do to the code, but I'm happy that it got solved upstream instead.

More tests

Erin added more tests that works both as functionality tests and implementation demos. They test the output of the engine to make sure everything is correct and they show you how to do common tasks. The newest test is the Breakable test that shows you how to combine shapes and break them apart.


I've fixed some bugs in the port thanks to Tim Dodd and his work on the Dynamic Tree class. Right now performance is very low and a lot of bugs still exists in the TOI and Distance classes. There are also some bugs with copying of shapes that cause most of the tests to show the wrong results. Feel free to help me out with those bugs (they are marked with TODO's in the code) - Any help I can get will be much appreciated.

As for Farseer Physics Engine 2.x - I will be releasing an update that fixes some bugs and improves performance. All my attention is on 3.0 at the moment but I hope that the next weekend will be spent on 2.x.

Sep 22, 2009 at 1:23 AM

Hey genbox this looks very promising and is good to hear.

Sucks that you are the only guy left now on it, perhaps someone else will come around.

I was wondering what is going to be happening after we update to revision 21? Is it then time to start actually turning this into farseer a little bit and fix all the bugs due to porting? Or are we going to be waiting for some more changes still on the box2d side of things? Also one other thing, will the dynamic tree broad phase be a better architecture for the 360 or about the same (obviously you don't know for sure yet i was just wondering if you had any ideas on it)

Anyway keep up the great work.

Sep 22, 2009 at 2:04 PM

I'm extremely grateful for the work that the 3 other guys have done. I know Matt are in the progress of moving and Paul is probably busy working. That is just the life of an opensource project :)

As for the future after rev 21:

My guess is that Erin is waiting for bugs to get reported before releasing 2.1. I'm sure that he is not going to implement more features (other than maybe a single test or two). The plan so far is to keep getting up to date with the latest changes and fixing the known bugs related to porting. The simulation seems quite stable, but the performance is very low. Next step is to optimize the obvious places in the code (My guess is that the garbage collector is working overtime at the moment).

Then Box2DX should be ready for a release and I can start working on Farseer Physics Engine. I still can't say anything about how long all of this is going to take, but once Box2D is ready Box2DX will be ready soon after that. FPE should only take a few months to optimize and polish before porting over the tools and implementing a huge amount of new features. I all depends on how much help I get from the community :)

The dynamic tree broadphase can sometimes be faster and sometimes be slower (A dynamic tree will usually use more memory and it does a lot of object allocations). We are talking about very small variations compared to the old SAP broad phase. By the way, the Xbox360 I ordered has not yet arrived. I got tired of waiting so I canceled the order and bought it elsewhere. Hopefully I will have it within a week.

Sep 22, 2009 at 2:34 PM

Well thats all very good to hear.

I'm sure we are all very thankful that you manage to find the time to work on farseer.
I imagine it would be hard making a library for a peice of hardware you dont own... you have done quite well.

Thanks as always.

Sep 22, 2009 at 10:26 PM
Edited Sep 22, 2009 at 10:27 PM

I'm not only thankful, but also I'm impressed and constantly admiring genbox's work.

Sep 28, 2009 at 2:05 AM

Sounds awesome!! :)
And it is great to hear hat you are also working on a new release for the 2.x Version :) Maybe after the improvements my game will run faster/smoother on my xbox360!! =)

Sep 28, 2009 at 1:29 PM

There are some patches in the patches section that improves the performance of the engine. I've not tested them yet - I'll take a look at it later this week.

Sep 28, 2009 at 3:06 PM

Hey genbox and others.

I can defantly say that this one is true for sat as I found it a couple weeks ago..

"in Geom.CS avoid recalculating the inverse matrix over and over again. Instead, when the matrix changes, the inverse matrix is recalculated and cached"

I found that this alone gave me a 21% fps rate improvement. what was 90 now is now 109

I might try some of the others that are up there thou.
Also has anyone had trouble with thin objects and sat? expesially thin triangles that look like this

Image of issue...

hmm i should probably use numbers too
point[0] = new Vector2(0,0);   //Bottom Left
point[1] = new Vector2(200,0); //Top Left
point[2] = new Vector2(0,-20); //Right

Basicly what happens is that the right point will fall through any other object with ease... Once it slips
I can show you a video of what happens if you would like.

Anyway i would love to know what you find when you test those patchs as they look quite good...

Sep 28, 2009 at 5:26 PM


I've actually looked at caching the inverse matrix before - problem back then was that the inverse matrix almost always changed. I've since made it so that the Update event is only fired on real changes in position and rotation and now we can gain something from caching the inverse matrix.

It would be great if you could test out the performance improvements and tell me if the simulation seems stable or not. I'm really busy at the moment writing about physics engines on my blog (part of my schoolwork actually) and work, so time is very limited. I have a vacation in 2 weeks, I should be able to test out the changes then and release a new version.

I've seen that SAT problem happen before. Are you using the release or source control version?

As for FPE 3.0, I've not yet updated it to rev 21 (22 is out), but whenever I get the time (a lunch-break or something) I will update to the latest version.

Sep 28, 2009 at 7:27 PM

The performance improvements in patch 3936 and 3978 shouldn't change anything to the simulation: the 'physics' should be exactly the same as before. The only thing the patches do is do optimize certain operations that are executed very frequently in the critical path (removing items from the ArbiterList, and checking whether there already is an arbiter for a certain Geom-pair), but they  don't change the semantics of these operations.  So except for an increase in performance, applying the patches shouldn't change the behavior in any other way (famous last words). A simple code review should be enough to validate whether the patches are functionally correct or not.

Sep 29, 2009 at 1:53 AM

Sorry i should of menchend that the sat issue has nothing to do with the performance patch and is present in both the old release version of sat and the new sat in the svn (which i am using)
Any idea how i can fix this?

Sep 29, 2009 at 2:04 AM

@dreamcreamer: Indeed, but since I've not looked at your patches yet, I'll need to cover all bases. I'm looking forward to take a look at them.

@danthekilla: I've seen that bug in the old implementation. I've not used the new one at all since Matt was working on it, but it might be the same bug there as well. I've been focusing on the 3.0 version and I'm not sure if SAT will be stable in 2.x series at all. It is not that I don't want it, it is simply that Matt is busy and so am I - so whenever I get some spare time, I have to use it on 3.0.

Right now I don't have an idea why it happens. It could simply be a rounding error or it could be something more.

Sep 29, 2009 at 5:25 PM

Hi danthekilla,

I discussed the SAT bug in this thread and provided a solution.

Sep 30, 2009 at 12:19 AM

Did Matt not fix that? I send him 2-3 fixes, I never checked if they made it into the engine (the source control version) - he might have waited until the new SAT implementation was done. I'll send him an email and see what is up.

Oct 1, 2009 at 11:44 PM

In the celebration of our 10.000th download of Farseer Physics Engine 2.1.1 I took some time to update Box2DX to revision 22. It is now up to date and only a few bugs (2 by my count) are left to be fixed. I hope to get Paul to help me this weekend to fix those bugs and others that I might have missed.

Box2D 2.1 are very close to release (Documentation is the only item left on TODO list and latest check-ins have been bugfixes only.) so I hope that we can fix Box2DX to be just as stable as Box2D. Then I hope to get Igor (owner of Box2DX) to implement some performance critical sections in unsafe code before I optimize (and rewrite) parts of the engine to better suit .NET.

Performance will be one of our main goals (always a hard goal to achieve in general physics engines ;) ) - the performance right now is way to low to be usable, so the main focus will be on optimization. More updates will come during/after the weekend.

Oct 5, 2009 at 10:39 PM

Hi genbox, you did say that Matt fixed that. I think it's just that some people haven't gotten the patch for one reason or another, so I gave him a link to that code in case he cannot apply the patch for some reason.

Oct 5, 2009 at 10:46 PM

I thought that release 2.1.1 included a couple of patches I received by mail. That is not the case.

I included the patches in the newest version in the source control. Could you try out the very latest check-in and see if the static geometry bug is fixed?