Can newton be deterministic?

saladin

30-11-2007 04:52:04

Hi,

I'm using ogreNewt in my game and am currently implementing a replay system. And I noticed how if I only serialise the logic bit the physics world plays out a little bit different every time. Im wondering if there's a way to make the playback exactly the same every time without having to sample or 'bake' the position/orientation for the objects in my scene. There can be up to 32 characters/vehicles (each with multiple joints) in one level and up to 50 grenades/fireballs bouncing around. If I create a keyframe every few frames whenever something moves, the memory can run out pretty quickly.

I noticed how walaber used this kind of sampling in the stunt playground (WorldRecorder), is that because newton is impossible to be deterministic?

Any help will be appreciated.

Cheers.

Tubez

30-11-2007 23:02:07

First of all, realise you are fighting a losing battle.

There's this thing called the Lyapunov instability. If the initial conditions of a system of coupled differential equations differs by even a small amount, the divergence is exponential. That said, if all the numbers are exactly the same, you should get the same answer. But if only of of them is slightly different, you could get literally anything.

Now, are you sure you are applying exactly the same forces (down to the very least significant bit in whatever float representation you are using) on exactly the same locations at exactly the same time as you did the first time around? Are you applying exactly the same timesteps? Anything that's even slightly different can result in a slightly different truncation. In turn, that single bit error propagates upward through the physical quantities one bit at the time (exponential, remember?) until the macroscopic behaviour is affected.

Even if you do and manage to get the physics of the system to follow the same trajectory as it did the first time, that's a lot of stuff to store. Unless your game is low interactivity (think fire-and-forget things like bowling games and rube-goldberg simulators) keyframing starts to feel like the cheapest option.

walaber

02-12-2007 01:02:41

newton is determininistic, in the sense thatt if you give it the exact same initial state, and use an identical timestep, you will get the same result each time.

the problem comes when you are resetting the position of objects (forr example to rewind to a previous point in time), some internal variables cannot be reset by the uses (contact lists, other things I'm guessing), and this causes very slightly different results whenn the new simulation begins.

i chose a keyframe method forr StuntPlayground because it allowed me to playback the simulation both forwards and backwards, at arbitrary speeds (slow motion, etc) very easily.

the WorldRecorder system I used allows you to set a threshold forr objects, so that new keyframes aren't recorded every frame, allowing less memory for objects that are not as important. I believe I had the car and tires recording keyframes at like 120fps, but the props were only 30fps or so...