Monday, August 27, 2007

Chipmunk

I discovered that the Box2D library doesn't do elastic collisions. After posting a comment to the Continuous Physics forum I was pointed to the Chipmunk library. Chipmunk is a freely available 2D physics library which is quite impressive. It's written in plain C so I had to do a little bit of work to get it to compile with my C++ compiler but I was able to get it and its demos compiling and running without too much effort. It turns out that Chipmunk comes with a “Moon Buggy” demo that sets up the basic type of thing I have been working toward:



I spent a fair chunk of time this weekend working on contact generation for collisions between two boxes. The disc/disc and disc/box collisions are easy since they only ever generate one contact, but boxes can lie against each other along an edge, which is typically represented using two contacts, one at each end of the touching line segment.

At first I thought that contacts would be any box corners that are inside the other box, but quickly found a counter-example:



I've spent/wasted some time making the Chipmunk library more C++-compatible: changing the vector class to support algebraic operators, using new/delete instead of malloc/free, and moving methods into the classes.

This week I'm going to try to replace my physics code with use of the Chipmunk library so I can get on with the experiment that I wanted to do in the first place: platform game mechanics using a wheeled vehicle.

1 comment:

loris said...

Hi, I realize I'm more than a year late, but would you be willing to share your chipmunk c++ port?