[ODE] continuous forces w/ constant step size

Tyler Streeter tylerstreeter at yahoo.com
Thu Sep 16 14:18:40 MST 2004


So far I have been using the following type of loop in
my simulation:

while(1)
{
   getUserInput();
   addForcesToObjects();
   dt = getElapsedTime();
   physics.step(dt);
   redraw();
}
...
void PhysicsEngine::step(dReal dt)
{
   timeAccumulation += dt;

   while (dt >= STEP_SIZE)
   {
      //step ODE ahead by a constant value
      ODESystem.step(STEP_SIZE);
   }
}

This works well to make things move the same on
different machines (no slow motion on slower machines)
and to yield repeatable results (due to the constant
step size).  Additionally, it's nice to have this
iterative stepping loop hidden within the above "step"
function so the application can just pass in some
arbitrary dt.

Here's the problem with it: The continuously-applied
forces and the input only get updated once per frame,
not once per time step, which yields different results
depending on the frame rate.  These things need to get
applied per time step to get consistent results.

Assuming I want to keep the iterative stepping
function, here's a possible solution: calculate the dt
since the last frame, call some addForce wrapper
function that takes a force vector and a dt value,
update physics, redraw..  This addForce function
creates a "force event" that gets added to a queue,
storing the force vector and the amount of time it
should be applied.  Whenever physics gets stepped
ahead, each force event's time left gets decremented
until eventually they stop getting applied.  This
allows forces to be applied for some time into the
future which is helpful since you don't know exactly
how long it'll be until the next frame comes around.

Any comments?

Tyler


	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 


More information about the ODE mailing list