|
Documentation
Chipmunk PhysicsNote: The documentation on this wiki documents Chipmunk v5.0.0. First of all, Chipmunk is a 2D rigid body physics library distributed under the MIT license. Though not yet complete, it is intended to be fast, numerically stable, and easy to use. I've put hundreds of hours of work into making Chipmunk what it is today. If you find Chipmunk has saved you a lot of time, please consider donating. You'll make an indie game developer very happy. I would like to give a Erin Catto a big thank you, as the most of the ideas for the constraint solver I use now come from his Box2D example code. (Now a full fledged physics engine all it's own: Box2D). His contact persistence idea allows for stable stacks of objects with very few iterations of the contact solution. Previously my solver produced mushy piles of objects or required a large number of iterations in order to get a stable behavior. OverviewThere are 4 basic things you need to know about in order to work with Chipmunk.
SupportThe best way to get support is to visit the Chipmunk Forums. There are plenty of people around using Chipmunk on the just about every platform I've ever heard of. If you are working on a commercial project, Howling Moon Software is also available for contracting. Rigid bodies, collision shapes and sprites:There is often confusion between rigid bodies and their collision shapes in Chipmunk and how they relate to sprites. A sprite would be a visual representation of an object, the sprite is drawn at the position and rotation of the rigid body. Collision shapes representation of the object, and how it should collide with other objects. A sprite and collision shape have little to do with one another other than you probably want the collision shape to match the sprite’s shape. Chipmunk BasicsInitializationBefore you do anything else, you must initialize Chipmunk. Otherwise you will crash as soon as the first collision happens. cpInitChipmunk(); // That is all Additionally, if you didn't compile Chipmunk with the NDEBUG flag, it will print out the debug mode message and the current version number to stdout. Memory Management the Chipmunk wayFor many of the structures you will use, Chipmunk uses a more or less standard set of memory management functions. For example:
While you will probably use the new/free versions exclusively if you are using C/C++, but the alloc/init/destroy functions can be helpful when writing language extensions so that you can more easily work with a garbage collector. In general, you are responsible for freeing any structs that you allocate. Chipmunk does not have any fancy reference counting or garbage collection. Math the Chipmunk wayFirst of all, Chipmunk uses double precision floating point numbers throughout it's calculations by default. This is likely to be faster on most modern desktop processors, and means you have to worry less about floating point round off errors. You can change the floating point type used by Chipmunk when compiling the library. Look in chipmunk.h. Chipmunk defines a number of aliases for common math functions so that you can choose to use floats or doubles for Chipmunk's floating point type. In your own code, there probably isn't a strong reason to use these aliases unless you expect you might want to change Chipmunk's floating point type later and a 2% performance hit from using the wrong float/double version of math functions will matter. That said, there are a few functions you will probably find very useful: cpFloat cpfclamp(cpFloat f, cpFloat min, cpFloat max) Clamp f to be between min and max. cpFloat cpflerp(cpFloat f1, cpFloat f2, cpFloat t) Linearly interpolate between f1 and f2. cpFloat cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d) Linearly interpolate from f1 towards f2 by d. To represent vectors, Chipmunk defines the cpVect type and a set of inline functions for working with them (cpv, cpvadd, cpvmult, etc). See the API reference for more information.. Chipmunk C APIMain API
Links
|
question: 0 degrees means right 90 degrees means up
there isn't enough detail in here
Here is a very very good tutorial for chipmunk http://www.alexandre-gomes.com/articles/chipmunk/