[ODE] Different behavior on different PCs (Try 2)

Frederic Ferland fref at videotron.ca
Sun Apr 27 09:33:01 2003


Thanks a lot guys!  A few people have suggested that I step the world using 
a constant interval instead of using the elapsed time since the last 
step.  I have modified my code accordingly and I do get the correct 
behavior on my home system now (Pentium 3 @ 1Ghz + GeForce2).  I'll try the 
program on my work PC tomorrow (Pentium 4 @ 1.8Ghz + GeForce3) to make sure 
that the behavior on that PC has not changed too much as an effect of this 
code change, but I doubt it will create any major problem.

In case other people who are having this same problem read this, here is 
how I had written my first UpdatePhysics( ) function:

//////////////////////////////////////////////////////////////////////////////
void C3DDemo::UpdatePhysics( float fTimeElapsed )
{
         if( m_bPhysicsUpdatePaused )
                 return;

         CPhysicsManager& manager = CPhysicsManager::Get( );

         manager.DetectCollisions( );
         manager.DoStep( fTimeElapsed );
         manager.UpdateScene( );
         manager.ClearCollisions( );
}
//////////////////////////////////////////////////////////////////////////////



And here's the new function:

//////////////////////////////////////////////////////////////////////////////
static const float STEP_SIZE = 0.005f;

void C3DDemo::UpdatePhysics( float fTimeElapsed )
{
         if( m_bPhysicsUpdatePaused )
                 return;

         CPhysicsManager& manager = CPhysicsManager::Get( );

         m_fPhysicsTimeAccumulator += fTimeElapsed;
         while( m_fPhysicsTimeAccumulator > STEP_SIZE )
         {
                 manager.DetectCollisions( );
                 manager.DoStep( STEP_SIZE );
                 manager.UpdateScene( );
                 manager.ClearCollisions( );

                 m_fPhysicsTimeAccumulator -= STEP_SIZE;
         }
}
//////////////////////////////////////////////////////////////////////////////

Thanks again!

Fred




At 08:28 AM 4/25/2003 -0700, you wrote:
>On Fri, 25 Apr 2003, Frederic Ferland wrote:
>
> > How do programs using ODE usually manage to get the same behavior
> > regardless of the speed of the computer being used?
>
>The easiest way to get INconsistent behavior is to let the speed of the
>computer determine the interval passed into dWorldStep.  If you pass a
>constant value (rather than, for example, using the elapsed time since the
>last step), you'll probably get consistent behavior.
>
>--
>
>Nate Waddoups
>Redmond WA USA
>http://www.natew.com
>
>
>_______________________________________________
>ODE mailing list
>ODE@q12.org
>http://q12.org/mailman/listinfo/ode