Having never done it, I can't offer any solid advice, but I would start by looking at one of the physics engines like Newton, and having a good google as I suspect there are lots of examples on-line.

A good place to start might be Sascha's website here.