A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by KATO2 » Thu Nov 10, 2011 11:24 pm
Hello peoples.
I have a physics simulation developed with ogre3d and ogrenewt, but i run this simulation with the same parameters in differents computers and the resulting simulation is very different. someone know how to fix this problem. i think this is a problem with simulation framerate. but i don't know how to keep the same framerate in different computers.
PD: Excusame my bad english.
-
KATO2
-
- Posts: 23
- Joined: Thu Nov 10, 2011 11:16 pm
by JernejL » Fri Nov 11, 2011 5:05 am
This is a normal aspect - whenever the timestep or input data varies on different simulations (such as using non-deterministic random() funcs in your code ), the simulation will not occur the same in all cases.
If you need determinism (always same result from same input data), you need to run newton in a fixed timestep, and without using specific features (advanced cpu features can sometimes produce different results on different processors).
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by KATO2 » Fri Nov 11, 2011 8:03 am
Hello JernejL. Thank you by your response. I understand perfectly. But, do you have any code o pseudo code that help me how implement determinism in my code?
Thank you
-
KATO2
-
- Posts: 23
- Joined: Thu Nov 10, 2011 11:16 pm
by Sweenie » Fri Nov 11, 2011 10:07 am
I usually do something like this...
- Code: Select all
const float timeStep = 1.0f / 60.0f;
float accumulator = 0.0f;
while (gamerunning)
{
float dt = game->elapsedFrameTime;
accumulator += dt;
while (accumulator >= timeStep)
{
NewtonUpdate(world, timeStep);
accumulator -= timeStep;
}
}
It's based on this article...
http://gafferongames.com/game-physics/f ... -timestep/
-
Sweenie
-
- Posts: 503
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by Julio Jerez » Fri Nov 11, 2011 1:02 pm
In addition to play at a fix rate, in newton each time you want to save the scene it is not enought to simply save the satate of each body,
you have to make sure all caches memory the engine keeps for persistance and performance are flushed. the function for that is
void NewtonInvalidateCache(const NewtonWorld* const newtonWorld);
not calling that function and it is possible that part of the scene is recreated in a different order. than teh scne tah is on the other coumputer
for example say you have a stack of two boxes, and you save it.
the box on top has contacts 3, 4, 1, 0
if you continue the simulation some contact will be resused and so will be recreated, if you save the simulation and the late on you recreated with thee same initial conditions,
now the contact will have the same values but the will be is different order say 1, 2, 3, 4
that lead to slighlly different arithmetic resuts because the laws or transitivity, comutativity, and assosicativy are not exact with finite presitioon arithmetic.
do not call NewtonInvalidateCache after every simulation frame, tha will make the iterative solver very slow an inacurate because
when the caches are flush the solver start from the begining and it has to execute the maximun number of iterations each time.
It also makes the collision system very slow.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by KATO2 » Tue Nov 15, 2011 5:53 pm
Well, I modified the code according to your suggestions, but the problem persists, I think it's because CPUs are of different architecture.
i will migrate the code to the server aplication and synchronize the objects, every time this change.
Thak you for your help.
-
KATO2
-
- Posts: 23
- Joined: Thu Nov 10, 2011 11:16 pm
by JernejL » Wed Nov 16, 2011 4:33 am
Try settting newtonarchitecture to basic calls only then.
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest