Monday, February 1, 2010

Upgrading the physics engine

I'm continuing to work on my lunar-lander-on-a-disc game.

This week I started updating my physics engine to match the latest version of Chipmunk. My physics library is basically a C++ translation of Chipmunk, so it's easiest to just look at the diffs in the source library and make equivalent changes to mine. I also took the opportunity to replace uses of cpHashSet with more idiomatic C++ (std::set and std::map). This reduces the amount of code in the library and makes it more type-safe.

Upgrading the library is my way of re-familiarizing myself with the code since I have a set of high-priority physics-related things to do:
  • Detect impact damage
  • Finish landing gear: absorb shock in all directions, have a proper foot, and break if stressed too hard
  • Add hydraulic entry ramps that fold down when landed
I'm also interested to examine the new constraint model to see how things are arranged. It strikes me that you might be able to unify contact constraints and joint constraints into a single set of constraints; I'd have to look at things some more to decide if that would be worthwhile though.

3 comments:

Dmitry Korzh said...

Hello! I see you have good relationship with Chipmunk. So could you tel me what a book or any other programming guide i can read to understand this library? There are a lot of difficult parameters like p - position, m - mass and so on. Thanks for your time!

James McNeill said...

Hi Dmitry,

A calculus-based university physics textbook will do a good job of introducing the basic concepts: mass, momentum, angular momentum, and so forth. I'd recommend starting there. I think mine may have been Serway's "Principles of Physics" (many years ago). If that is too expensive, look over Dover's publications: they republish older textbooks in inexpensive editions.

Unfortunately my university textbook didn't do a very good job of addressing how to do physics simulation. It was aimed at solving individual problems that can be done via calculator.

This is where two gentlemen named Baraff and Witkin come in. They ran (still run?) a yearly SIGGRAPH course on physically-based modeling. This is where lots of people I know got started with physics simulation:

http://www.cs.cmu.edu/~baraff/sigcourse/

There are several physics forums that can help out if you get stuck. Chipmunk's got one; Box2D has one; and Bullet Physics has one as well.

It takes a few years of hard work to get an understanding of physics simulation.

If anyone else is reading this and has recommendations, feel free to post them below.

Carlos Camacho said...

Dmitry, feel free to stop by iDevGames.com. Many of Chipmunk's devs hang out there. Cheers.