ODE Tutorial
This tutorial explains the basics of ODE through the construction of a simple applications that displays cubes falling on the ground.
Preliminary setup
Discovering the QGLViewer
We are going to use ODE for the physics and a very handy library for OpenGL display of the physic simulation, named QGLViewer. This library is based on Qt and encapsulates a viewer for rendering and manipulating (flying through, rotating with a trackball,...) a 3D scene. There are excellent tutorials on the web site, so I just present here the very fundamentals of the library.
- Create a class Viewer that derives from QGLViewer
- Override the method QGLViewer::init() to indicate the OpenGL setup, such as enabling states (e.g. alpha blending) or creating context dependent objects (e.g. texture objects, frame buffers or vertex buffer objects).
- In the overidden QGLViewer::init(), you also specify the "size" of the scene, so that the viewer can optimally compute the near and far plane of the OpenGL camera used to render the scene. You can also tell the viewer to initially setup the camera so that the whole scene is encompassed by the camera frustum. Finally, you can position the camera to the position it occupied when the application was last quit (yes, the QGLViewer saves its state in a .qglviewer.xml file!).
- Overidde the method QGLViewer::draw() to indicate what OpenGL command must be issued to render the scene.
- Overidde the method QGLViewer::animate() to indicate how to animate the scene. This function is called regularly by the viewer, using a timer whose frequency is set with QGLViewer::setAnimationPeriod() (default is every 30ms).
Here is for example a simple viewer that shows a ball whose color is changing over the time.