My book, Designing Data-Intensive Applications, was published by O’Reilly in March 2017.
Published by Martin Kleppmann on 25 Oct 2008.
My final-year project at university was on “Rigid body simulation for 3D character animation”, which is a very fancy way of saying that I spent a year trying to make a video of a person falling down a flight of stairs. Without hurting any real people obviously – it’s all simulated and 3D animated, and most of the content of the project is working out the maths and the algorithms to calculate how bodies move and rotate in space, how they collide, and how they react when they are being held together by joints. I started out on that project thinking it would be fun, and it actually turned out to be fairly hard, so I published the results in a technical report of the University of Cambridge afterwards.
More importantly, here’s the video which was the end result of the project. It presents several scenes of increasing complexity:
There’s a better quality MPEG download on maniation.com. Feel free to download and read the report; it’s not the most exciting read and contains a lot of maths, but it does contain one or two minor new discoveries. I tried to make it unpretentious and useful by explaining the material in such a way that it serves as a readable and useful introduction to the topic (mainly because I struggled to find decent introductory texts myself).
And in fact, in the 2 years since I completed the project I have had a few people contact me and ask for further details and/or bits of source code for their own projects. I have not developed it any further and probably won’t be doing so anytime soon, but I’m still keen to hear from anybody who’s doing things in this space. And as a help for anybody working on their own physics engine, I am now releasing some of the source code from my project.
SOURCE CODE NOW AVAILABLE
The code is in Java 5 and covers some of the fundamental data structures and algorithms which I needed to implement:
Note that this is not elegant, optimised or even particularly robust code; if you’re writing a computer game and need a physics engine, consider using something like the Open Dynamics Engine (open source), Tokamak (open source) or Havok (commercial). But if you want to learn how to make a simulation like this using Lagrange multiplier methods, then maybe this is for you.
You will quickly notice that the source is not complete. Hell, there’s not even a ‘main’ method. That’s deliberate – this code is there to help you figure out how this stuff works, it’s not intended to work out of the box. If you want to write an application which uses it, you’re probably going to have read the whole report and some of the papers it references, read all of the code, think about it for a while, get annoyed about the fact that I didn’t put more comments in the code (sorry), and then start writing some stuff around it.
Nevertheless, I hope it will be useful. I release it under a MIT license.