[ODE] Leftover step time step instability

Matthews, Steve USA swmatthe at nps.navy.mil
Thu Aug 14 15:54:02 2003


Hi all;
   I have seen this general issue pop up before, but I have never seen the following question:

I have the following code in my program execution loop, so that the physics world in ODE steps forward as much as the 3d visual scene, but by small and consistent time steps:

           int i;
           const static double WORLD_STEP_TIME = 0.01;

           //divide the time since the last system frame by the time each ODE (physics)
           // world step needs to be to get the number of whole world steps we currently need to take
           int numWorldSteps = (int)(mSysData.mDeltaFrameTime/WORLD_STEP_TIME);


           //step the physics world by the set world step time for the number of
           // iterations as derived above in numWorldSteps
           for (i=0; i < numWorldSteps; i++)
           {
              //account for all collisions at present time
              cdCollide();

              //then step the world, letting objects move in the physics world
              gfWorldStep(WORLD_STEP_TIME);

              //and finally, remove all collision contact points, so the process can be repeated
              emptyContactGroup();
           }

This code works fine, but when I first wrote this code, I expected to have to step forward by the (probably much smaller) leftover time, as such:

           //calculate the leftover time (not a whole world step)
           double leftoverWorldStepTime =
                 mSysData.mDeltaFrameTime - numWorldSteps * WORLD_STEP_TIME;

           //step the physics world by the leftover time
           cdCollide();
           gfWorldStep(leftoverWorldStepTime);
           emptyContactGroup(); 

But I found that stepping by the leftover time created instability; not terrible while the app was in foreground and the running process, but if I switched to another window, the app would blow up.  Removing the code concerning the leftover time seemed to fix everything, even though you would think there should be a disparity.

Can anyone tell me why trying to step by this leftover time would create instability?  And do you know if there are any issues with forgetting about the leftover time, as I have done. (which, as I said, works)

Thanks much for any insight,
   Bootshine