[ODE] Re: variable physics rate
Scott Johnson
milkboy at austin.rr.com
Mon Dec 16 22:30:02 2002
> From: "Vianney Lecroart" <lecroart@noos.fr>
> To: <ode@q12.org>
> Date: Mon, 16 Dec 2002 22:36:50 +0100
> Subject: [ODE] dWorldStep() on non constant frame rate
>
> Hello,
>
> I use your great physics engine for a little game I made. I have a
> really strange problem, my loop is like that:
>
> While (true)
> {
> newframe = currentime;
> dt = lasttime-newtime;
> lastframe = newframe;
> dWorldStep(dt);
> sleep(100);
> }
>
> But the server, sometime slowdown a lot and the dt can be 100ms and some
> time, it near 300ms for one or 2 loops. So we call dWorldStep with 0.3.
> I think it s the good way to do but in all samples you set the
> dWorldStep with a constant value, so it s means that it s frame rate
> depend (0.05). No? It means that if the framerate is 50ms, the physics
> step is 50ms, the rendering is as fast as the realtime, but if the
> framerate is 5ms, the physics will go 10 times faster than the realtime.
> Is is correct?
>
> I don't really know the good way to manage the problem to manage
> variable framerate.
>
> Thanks for you help.
>
> Vianney Lecroart
>
Vianney,
I am new to ODE but I have done this before in games
dt = 0.0f;
While (true)
{
newframe = currentTime();
dt += lasttime - newtime;
while (dt > 1/60.0f )
{
TimeStep( 1/60.0f );
dt -= 1/60.0f;
}
// Render, etc
}
I hope that helps.
Scott Johnson
milkboy@austin.rr.com