[ODE] Is a variable frame rate possible?

Bram Stolk bram at sara.nl
Tue Dec 6 02:17:23 MST 2005


John wrote:
> Is there any way, hack or otherwise, to have a variable frame rate with 
> ODE?

What I do, is the following:

Measure the elapsed time since last display iteration.
Based on this dt, determine a nr of simulation iterations
to do. E.g. on a very slow MESA renderer, where it takes
a second to render, I do a LOT of ode iterations.
On a high end graphics card, dt is very low, so I do
just one ODE iteration for each display iteration.
In code, it looks like this:


  // Somewhere in your mainloop (I do this in glut idle)

  // measure dt (NOTE: use moving average if CLK res is low,
  // e.g. 100Hz is too low. 250Hz is OK.

  int timesteps = (int) ceilf(dt / (1.0/60.0));
  float stepsz = dt /  timesteps;

  for (i=0; i<timesteps; i++)
  {
    dSpaceCollide (bigspace, 0, &near_callback);
    // some app updates can go here (e.g. joystick ctrl)
    dWorldQuickStep (world, stepsz);
    dJointGroupEmpty (contactgroup);
  }

As you can see: if app runs at 60Hz of faster, I do
one collide and quickstep per display. Else, there are
more. This will keep your simulation accurate, despite
a very slow renderer.

  Bram


> _______________________________________________
> ODE mailing list
> ODE at q12.org
> http://q12.org/mailman/listinfo/ode


-- 
Bram Stolk, VR Engineer SARA, Amsterdam.   tel +31 20 592 3000

"Windows is a 32-bit extension to a 16-bit graphical shell for an 8-bit
 operating system originally coded for a 4-bit microprocessor by a 2-bit
 company that can't stand 1 bit of competition."


More information about the ODE mailing list