physics simulation games
Mon, 11 Apr 2011 00:14 categories: blog, debianAs I own a Always Innovating Touchbook I wanted to make use of its touchscreen by having some physics simulation games on it. Unfortunately it's kinda hard to find such open source games as the really good ones, phun (now algodoo), zanydoodle and crayonphyiscs are proprietary. Noteable opensource games I found were numptyphysics and the powder toy
While phun and the powder toy come with their own simulation engine, the rest are using open source libraries. This got me to research a bit to what is available on open source 2D rigid body physics simulation libraries.
The one that numptyphysics and crayonphysics (and angrybirds!) rely upon is box2d. As it is also used by the torque 2d engine it is probably also used in amazing games like Insanely Twisted Shadow Planet. Starting of in 2007 it is the older library but doesnt seem to be further developed since 2010. It is implemented in C++, released under the zlib license, rendering agnostic and supports lot of features like hinges, motors, friction and springs. Its sort and prune based broadphase collision detection is supposed to work better with objects of varying size.
The newer and more fancy one is chipmunk which builds on parts of box2d, is implemented in C99 and is more high level than box2d. It is used by zany doodle and xmoto and released under MIT license. The spatial hash broad phase collision detection is supposed to make it faster for lots of objects of the same size. This is also one of the reasons why chipmunk seems to be much faster with fluids which are quite problematic for box2d because of the huge number of small circles used to simulate it.
Box2d is ported to many languages, chipmunk as many bindings. They are both cross platform, running on Windows, Mac OS, GNU/Linux, Android and Apple iOS. Chipmunk has a more modern and thought out API but that might just be because of my C++ dislike. In the end, forum posts suggest that each of them has it's strengths and weaknesses and (as usual) in the end one has to go with the one than one is more comfortable in using.
Unfortunately the most impressive engine seems to be integrated in the propriety game phun, or algodoo as it was renamed. But this might just be an impression by the immensely complex and function rich program that phun/algodoo is. Most noteably is probably its smooth handling of water including simulation of buoyancy but it also simulates specular reflection, fraction and dispersion of light. Its other features like hinges, motors, springs, friction and mass are also handled by chipmunk and box2d but there is an editor missing that is as powerful as the one of phun/algodoo.
Now the two open source games I was checking out were numptyphysics and the powder toy. I wanted to have both on my touchbook and be able to control them with the touchscreen only.
Now numptyphysics is packaged in debian but development seems to have stopped in 2008. Fortunately it's quite useable and even supports touchscreen only operation by two slide-out menus on the left and right. It took me ages to find those and i only found them by accidentally clicking on the 5 pixel border of the window which slides out the menu. With this one it can be fully controlled with the left mouse button and is hence ready for touchscreens. Unfortunately it needs some tweaks to be nicely useable. Those changes were, to increase the window size to 1024x600 (there is no way to do that without recompiling), change the selection and click tolerance to bigger values for touchscreen use (also needs recompilation), increase the area on both sides for the slide-out menus (again needs to be recompiled) and disable drawing of the rotating joint symbol as it doesnt get scaled.
You can find my changes here maybe some time I will make a better patch that also includes command line options to change all of that at runtime.
Then there is the powder toy. It comes with a fixed resolution as well which is mainly due to the fact that it builds on an online community that shares their creation and those are of fixed size. If one doesnt care about that, changing the resolution is very easy but also only possible at compile time. It involves just changing XRES, YRES, XCNTR and YCNTR in includes/defines.h. Since I wanted to run it on the armel architecture I added a new target to the makefile that built powder without sse. Also to make it run faster I didnt choose 1024x600 but 512x300 as the resolution and combined that with the scale:2 commandline parameter. Sadly scale can be only 1 or 2.
While numptyphysics is perfectly useable on the touchbook performance wise, the powder toy runs at a mere 9 fps with an empty screen. Maybe this will improve with armhf but i didnt check out how much the powder toy uses floating point arithmetics.
In the end here are some videos that are worth watching: