Rigid Body Dynamics

Note: the text of this page is from my original website, and I haven't updated it in a while. Make sure you look at the physics category for all of the articles related to rigid body dynamics.

I started getting interested in high end physical simulation for games sometime in 1995. Since I didn't know anything about physics or know any real math (I had calculus in high school and enjoyed it, but had forgotten most of it), I had to teach myself everything from scratch. Let me just say it was a total blast. I highly recommend everyone taking the time to learn something really big and new every once in a while, in addition to all the little things we're all [hopefully] learning every day. As a bonus, it seems that the more we learn, the faster we're able to learn even newer things, which makes the whole process even more pleasurable.

As much fun as I had figuring this stuff out, I sure would have appreciated some references and articles aimed at my level when I was starting. So, I've created this web page in the hopes I can help everyone else get past those difficult first steps.

Physics Articles

I wrote a total of four articles about rigid body dynamics for Game Developer Magazine. I've posted them as PDF files, so they look just like they do in the magazine. There are downsides to PDF, however, including the general way in which Acrobat sucks at letting you navigate through documents (it's clear Adobe thinks a monitor is a lowres printer), and perhaps more seriously, the way some of the equations came out garbled. However, you should think of the latter problem as a challenge to figure out the correct equations! [If people complain enough I'll figure out how to fix them.] Please respect the copyright information in the front of each article.

  • Physics, Part 1: The Next Frontier - Oct/Nov 96
    This is the introduction to the physics series. It covers the linear parts of 2D rigid body mechanics, and a little bit of numerical integration.
  • Physics, Part 2: Angular Effects - Dec/Jan 96
    This article covers 2D angular rigid body mechanics and the overall 2D dynamics algorithm.
  • Physics, Part 3: Collision Response - Feb/Mar 97
    We finish off 2D physics with collision response, including the angular effects induced by a collision. The 2D physics sample, discussed below, demonstrates all the concepts learned so far.
  • Physics, Part 4: The Third Dimension - June 97
    The final article in the series. To pack in all the 3D equivalents of the first three articles, I created this monster of an article. It comes in at twice the length of the others, with 6000 words and 20 equations.

Four articles, no matter how long, are just not enough to do justice to rigid body dynamics. If you plan on using real dynamics in your game, you simply have to read my Physics References. The 3D sample application below shows the beginnings of some really cool technology, but you'll have to take the initiative to teach yourself more math and physics to turn it into a production quality simulator.

Physics Samples

I created two sample applications to accompany my physics articles.

Remember, these are just sample programs, not the ultimate physics simulators. They're really just a translation of the equations in my articles into code, so don't expect too much. They're fun to play with and change, but you'll have a lot of your own work to do before you can use this stuff in a production quality game. These apps will get you started, but not much more than that.

The most obvious thing the samples are missing is inter-body collisions. They don't do collision detection between bodies, but only between bodies and the world. It wouldn't be too hard to add a very simple discrete collision detector, but I didn't have time.

The second biggest problem is the lame integrator used in both apps. Both samples are relatively unstable because I'm using the simplest Euler integrator. If you play with the spring and damping coefficients you'll quickly see how tweaky they are with relation to the timestep with this cheesy integrator. There are tons of books on numerical integration to help you fix this problem.

  • The 2D Physics Sample, a 34kb PK-zipped file. Includes Win32 executable.
    I never quite got finished porting this app to the mac, but the code is quite portable (the simulator talks to the OS code through a few functions in iface.h). A couple people have hacked up mac ports, but I haven't had time to integrate them with the code and update the zip. Some other people have ported it to Java, so I might just include that here for kicks.
  • The 3D Physics Sample, a 47kb PK-zipped file. Includes Win32 executable.
    I used OpenGL for the 3D rendering in this sample, so it's nice and clean and portable. In addition to the stock Win32 wrapper I always use (abuse?) for my test apps, I also hacked up a GLUT wrapper and included it in the zip, so any platform that supports OpenGL and has a GLUT port should run the app (make sure you fix the GetTime function in glut.cpp as the assert will tell you). I've tested it on Win95 with a bunch of drivers. I've also tested it on the MacOS using GLUT with Mac Mesa and with Conix's OpenGL. The performance is totally acceptable for the software renderers on a low-end (100Mhz) Pentium or PowerPC.

Physics References

I've moved the annotated physics references here.

todo: lots more work to do on this page

This page was last edited on 14 May 2007, at 03:43.