Motor Physics: 50 dancing boxes

move mouse inside stage, press ‘w’ key to wiggle the floor

This is a follow up to the post about the SI-Solver from the Box2D engine. The revised demo shows a worst case scenario with 50 stacked boxes. It took great effort to max out performance, but I think it’s fast enough now, especially when realizing that the engine does a lot of computations each frame to make things stable (for example 50 sequential impulse computations per box). Performance is top priority, because a physics system which sucks up all processing time doesn’t leave room for rendering, AI and other game engine elements and hence is useless for more complex games.

I still see a lot potential to make it faster, probably in the range of 30-70%, but I won’t go into that for now. Instead I’m concentrating on putting the engine pieces together and adding forces, constraints and user interactivity. Enough with just bouncing stuff!

As a side note, I also decoupled the simulation from the frame rate (which I should have done a long time ago), so the physics attempts to run at a constant rate, which is very important for games. The example above is limited to 60fps so it tries to update the simulation every ~16ms. When the fps counter shows more than 60fps, there is still processing time available.