Sunday, November 8, 2015

ODE brief tutorial

Very quick top level understanding of the key components in ODE...
An object in ODE is made of two entities:
  1. The body: holds the masses (one in the centre of gravity or distributed...). This is what gives the kinetic behaviour to the object.
  2. The geometries used to describe the physical boundaries of the object (detect collisions).
Bodies belong to the World, while geometries belong to the Space.

To create the objects, we create their bodies (which can actually be made of bodies). Each body is basically a mass, with a centre and an orientation (which later will be tight to the same centre and orientation of the geometry). Then we create geometries that we assign to that body so that it's all linked together. Setting a body on a geom automatically combines the position vector and rotation matrix of the body and geom, so that setting the position or orientation of one will set the value for both objects. This is important because even if we have created the geometry somewhere else, once we assign it to the body, the centre of the geometry will be shifted to match the centre of the body. To offset that, use dGeomSetOffsetPosition.

Program starts (in main C function) by creating the simulation environment with its objects and the fn function among others (see below). Then calls dsSimulationLoop (argc,argv,352,288,&fn); that starts the simulation. It will stay there, simulating, till exiting (usually ctrl+x).

fn, among other things, basically points to the 2 key functions on a simulation loop, Step (key ODE step sim) and Command which senses inputs from keyboard, for instance.

A simulation loop (Step) [1] runs dSpaceCollide in the space to detects collisions and position the objects according to that. [2] Then runs a step of physics simulation with dWorldStep which moves the object accordingly. [3] Finally draws the whole scene. Notice that you can draw whatever you want, even nothing, and may not match what/where the real geoms are. It is up to the user to keep what we see and what the sim uses to do collisions correct. For that, when drawing the objects, use their centres and orientations. Outside Step, after all that is done, [4] software checks for user inputs in Command.

Cheers!

PS.: Some of the tutorials included with ODE (I'll add as I go through them):
  1. Chain 2: uses ball and socket joints to connect a series of boxes to make it look like a chain. No user input. Simple and quite insightful.
  2. dBall: double ball and socket demonstration. Shows two objects tight by a rope under the wind.
  3. cylvssphere: just drops a sphere and a cylinder in screen. Pretty simple.
  4. feedback: that's a cool one... draws a bridge out of tiles and then drops a bunch of stuff on it that ends-up breaking it...
  5. gyro2: the boxes spinning in space, using dBodySetGyroscopicMode. Not sure what for...
  6. joints: that is a pretty spectacular/psychodelic one. Many different type of joints applied between two boxes... Sim seems to re-start between each type.

No comments:

Post a Comment