A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by adam450 » Fri Feb 06, 2009 10:33 pm
I am using the windows function QueryPerformanceFreq and QueryPerformanceCounter. I convert these correctly and divide to get a timestep value which is fine, and I calcluate the FPS and everything is fine. But when I slow my game down, Newton is not fine its the only think that doesnt run at this correct timestep.
Any suggestions?
How does newton multiply things. Am I supposed to multiply all my forces by time or does newton do that (which is what I'm assuming).
-
adam450
-
- Posts: 21
- Joined: Fri Jan 16, 2009 11:11 pm
by Stucuk » Fri Feb 06, 2009 10:41 pm
If you use different values for the NewtonUpdate() procedure you will get different results. The only way to get the same results that i have seen is to change the amount of times you call NewtonUpdate(). As in if you call it twice as much it will go twice as fast. Tho calling it half as much can cause jumpyness.
-
Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by adam450 » Fri Feb 06, 2009 10:46 pm
Ok, so Newton runs at 60fps it seems right? So I should just calculate how many times I'm supposed to call it based on my current FPS?
What if my FPS is 30 though, I cant call NewtonUpdate() 1/2 a time.
Can I just do NewtonUpdate(....., .01) and just call it for FRAME_TIME/.01 times? That still seems really bad.
-
adam450
-
- Posts: 21
- Joined: Fri Jan 16, 2009 11:11 pm
by agi_shi » Sat Feb 07, 2009 9:24 am
- Code: Select all
float accumulatedTime = 0;
const float UPDATE_FREQUENCY = 1.0 / 60; // 60 FPS for physics, you can go higher if you need some crazy precision, but 60 is good
game loop
{
accumulatedTime += deltaTime;
while (accumulatedTime >= UPDATE_FREQUENCY)
{
NewtonUpdate(world, UPDATE_FREQUENCY);
accumulatedTime -= UPDATE_FREQUENCY;
}
}
This is how you should be integrating the physics. A constant time step for the physics engine.
For slow motion, you simply lower the delta time per frame, and that makes it so that NewtonUpdate() is called less often, resulting in slower motion. What this introduces, of course, is jumpiness. This is why you need interpolation. The graphics are integrated as fast as possible, and read the current physics state and previous physics state, interpolating between the two based on the scale between the graphics update speed and the "world" (physics, logic, etc.) update speed.
Here's an excellent post on this:
http://gafferongames.com/game-physics/f ... -timestep/
-
agi_shi
-
- Posts: 263
- Joined: Fri Aug 17, 2007 6:54 pm
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 19 guests