[ODE] simulation steps in a game

henry.maddocks@met.co.nz henry.maddocks at met.co.nz
Thu Apr 11 13:54:02 2002


I've only been using ODE for a couple of weeks (but I love it, I haven't 
had so much fun for ages) so if this is wrong let me know, but...

I wouldn't worry about matching rendering frames and physics 'frames'. 
You're talking about milli seconds which isn't a big deal for a game. 
Here's my render loop...


const float ODE_WORLD_STEP = 0.01;

void render( float gameTime) // milliseconds
{
		while( physicsTime < gameTime)
		{
			for( size_t i = 0; i < cars.size(); ++i)
			{
				cars[i]->Simulate();
			}
			
			odeWorld->step( ODE_WORLD_STEP);
			
			odeJointGroup->empty();
			
			physicsTime += ODE_WORLD_STEP;
		}

	scene->render( gameTime);
}

If you want before you call render you could make gameTime = 
physicsTime. Mind you I use ODE to handle ALL my body positions and 
orientations which probably means the same thing.
This gives me visually identical results when the fps is 20 or 100.

Henry


On Friday, April 12, 2002, at 05:14  AM, madmax@red-falcon.net wrote:

> I'll try that. If I encounter problems, I think I'll try fixed time 
> steps for physics while
> rendering as fast as possible. I think I'll have to do some 
> interpolation between
> rendered frames in order to match the physics steps...


"C makes it easy to shoot yourself in the foot; C++ makes it harder, but 
when you do it blows your whole leg off." - Bjarne Stroustrup