This is a car driving simulation, based on a small rigid body physics engine that I have written in C++. Drive your car round the circuit, going over the jumps, across the bridge, and around the loop. Try to avoid hitting any cubes.
Update (March 2014): The implementation of Featherstone's algorithm, which I developed as part of this work, is now being used (in a modified form) in the Bullet open-source physics library.
Click here to download the demo zip file (3.6 M)
You may also download the source code (979 K).
Unzip the demo and run "car_demo.exe". In the setup dialog, set Rendering System to either OpenGL or Direct3D (it doesn't matter which). You may also want to change the Video Mode, or set Full Screen to "no" to run in windowed mode. Then click OK to start.
WASD or IJKL keys = Drive car
Arrow keys = Move camera
Right mouse button (drag) = Rotate camera
F1 = Reset camera
F2–F4 = Alternate camera views
Left mouse button = Fire spheres into the scene.
You can also click "Settings" to adjust various parameters, or "Reset Simulation" if you crash and need to restart :)
Don't try to drive round the corners too fast!
When going over the jumps, release the accelarator once you are in mid-air; otherwise, the car tends to pitch upwards. (This should probably be fixed somehow.)
This section gives some brief notes on the implementation.
The "core" of the demo is a physics engine which I have written in C++. It implements the following features:
Please note that I did not implement the collision detection code myself; I instead re-used the collision detection routines from Bullet. However, all of the actual physics simulation and constraint solving code is my own work (i.e. the only component taken from Bullet was their collision detection library).
A physics engine by itself is fairly boring, so I decided to implement a simple car, along with a "race track" for it to drive around. The car is modelled as follows:
All car joints are simulated using generalized coordinates and Featherstone's algorithm.
The demo also contains a "rope bridge" as an example of a complex multi-jointed object. This is composed of 10 rectangular "planks" which are connected by revolute joints. It is simulated using Featherstone's algorithm together with an additional position constraint on the final plank.
Featherstone's algorithm is a method that allows articulated bodies (such as the car and the bridge) to be represented using generalized coordinates. So, for example, the bridge's position is represented by ten scalars (the joint angles), as opposed to ten vectors (positions) and ten quaternions (orientations).
The main advantage of doing this is that it is impossible for joints to "break apart"; for example, a state where the bridge planks have separated from one another is simply not possible in the generalized coordinates representation.
The disadvantage is that the algorithm is somewhat complex to implement. For this reason it is not usually implemented in game physics engines. However, I was curious to see how it would work out, so I decided to implement it in my code.
An excellent explanation of Featherstone's algorithm can be found in Brian Mirtich's thesis, "Impulse-based Dynamic Simulation of Rigid Body Systems" (see chapter 4).
The core physics engine is my own code, but other components used open source libraries, as follows:
The physics engine implemented in this demo is not perfect, and has several limitations, for example:
The demo is copyright (C) Stephen Thompson, 2011.
The Car Physics Demo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
The Demo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The text of the GPL can be viewed here: https://www.gnu.org/licenses/gpl.html, or alternatively a copy can be found within the demo zip files (see "Downloads" above).