I've finally managed to finish the Kite Physics Demo I started back in October:
It's more of a plaything than anything else. It did give me a chance to try out writing some physics code again, something I don't get much of a chance to do during web development. Though of course advances in Javascript speed and the Canvas tag may change that in the future.
Originally I made use of the keyboard to control the figure and the kite, but I switched to using the mouse as it makes interacting with the scene more pleasing. There's a certain joy to being able to grab the kite to move it around or shift the wind direction by nudging a cloud.
It's all written in Java, using maven to build and package. The code is available in my kite repo on guthub.
There's about one third of a physics engine in the code. There's no real collision detection for example. Most of the physics code is for handling constraints and basic forces. For the constraints I made use of the Gauss-Seidel technique, as outlined in Advanced Character Physics by Thomas Jakobsen. This was quite a revelation to me. Previously I'd experimented with rigid body dynamics (see my 2D racing game circa 2001), but the Gauss-Seidel method seemed much more intuitive. I found it much easier to think of bodies made up of points connected by lines. The "physics" naturally emerges from the way the bodies are then constructed.
The core physics code (in the com.psychicorigami.physics.* package) is fairly well structured. There a bit of compiler placation to (theoretically) allow for the same code to work for 2D and 3D physics. I've only actually implemented the 2D side of things, but have tried to use generics to make room for 3D too. When everything is points and lines, moving from 2D to 3D is not that tricky. Whereas for rigid body dynamics this can mean quite a big change in representation.
The code in the default package is used for the specifics of the demo itself, so is a bit messy really. Lots of tweaking and prodding was needed to get things how I wanted.
The physics for the kite and wind interaction were aided massively by this guide to forces on a kite. Particularly useful for understanding how to tweak the rigging, centre of gravity and centre of pressure of the kite to make it behave in a pleasing - if not entirely realistic - manner.
At some point I hope to revisit the physics code here. I've always had a wish to create something like Karl Sims "blocky creatures", but lacked the specific technical knowledge. Know that I have a technique for simulating complex constraints in an intuitive manner maybe I'll manage it yet.