A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by misho » Wed Jan 13, 2016 3:19 am
Windrider wrote:http://gamedev.stackexchange.com/questions/1589/when-should-i-use-a-fixed-or-variable-time-step
Interesting. If I understand this, the way to go is to let Physics loop run at one "speed", and have graphics engine "fetch" results at every frame update. There could be many Physics updates between every frame update... makes sense?
-
misho
-
- Posts: 675
- Joined: Tue May 04, 2010 10:13 am
by JoeJ » Wed Jan 13, 2016 3:30 am
- Code: Select all
void NewtonUpdate(const NewtonWorld* const newtonWorld, dFloat timestep)
{
TRACE_FUNCTION(__FUNCTION__);
Newton* const world = (Newton *)newtonWorld;
dgFloat32 minstep = dgFloat32 (DG_MIN_TIMESTEP);
dgFloat32 maxstep = dgFloat32 (DG_MAX_TIMESTEP);
timestep = dgClamp (dgFloat32 (timestep), minstep, maxstep);
//NewtonSerializeToFile (newtonWorld, "xxx.bin", NULL, NULL);
world->UpdatePhysics (timestep);
}
You can change min/max timestep defines and see if the simulation still runs fine.
For a flight sim this might be ok, because there are no constraints and mostly just integration.
Otherewise fixed timestep is recommended for stable simulation, which means async graphics and physics and you need to interpolate current und previous physics state for graphics to keep graphics looking smooth.
-

JoeJ
-
- Posts: 1489
- Joined: Tue Dec 21, 2010 6:18 pm
by Windrider » Wed Jan 13, 2016 3:34 am
Could you please elaborate a little on "you need to interpolate current und previous physics state for graphics to keep graphics looking smooth" please?
-
Windrider
-
- Posts: 22
- Joined: Mon Nov 02, 2015 2:34 pm
by misho » Wed Jan 13, 2016 3:39 am
I always thought this line (from tutorials) took care of the interpolation:
- Code: Select all
// calculate the interpolation parameter for smooth rendering
g_sceneManager->SetIntepolationParam(dFloat (g_timeAccumulator) / dFloat(DEMO_FPS_IN_MICROSECUNDS));
along with
- Code: Select all
dVector posit (m_prevPosition + (m_curPosition - m_prevPosition).Scale (interpolationParam));
dQuaternion rotation (m_prevRotation.Slerp(m_curRotation, interpolationParam));
m_matrix = dMatrix (rotation, posit);
Is that correct?
-
misho
-
- Posts: 675
- Joined: Tue May 04, 2010 10:13 am
by misho » Wed Jan 13, 2016 4:17 am
Thanks for confirming that! Looks like a cozy bedtime read!

-
misho
-
- Posts: 675
- Joined: Tue May 04, 2010 10:13 am
by Sweenie » Wed Jan 13, 2016 8:16 am
I usually do something like this...
- Code: Select all
const float TimeStep = 1.0f / 60.0f; // 60 physics updates per second
float accumulator = 0.0f;
void PhysicsUpdate(float deltaTime)
{
accumulator += deltaTime;
while (accumulator >= TimeStep)
{
NewtonUpdate(TimeStep); // A step of 0.016 seconds will occur when 0.016+ seconds has passed.
accumulator -= TimeStep;
}
}
Now, you should be able to implement a timescale by doing something like this...
- Code: Select all
const float TimeStep = 1.0f / 60.0f; // 60 physics updates per second
const float TimeScale = 2.0f;
float accumulator = 0.0f;
void PhysicsUpdate(float deltaTime)
{
accumulator += deltaTime;
while (accumulator >= TimeStep * TimeScale)
{
NewtonUpdate(TimeStep); // A step of 0.016 seconds will occur when 0.032+ seconds has passed.
accumulator -= (TimeStep * TimeScale);
}
}
The above change should make the simulation go at half speed while still stepping the simulation at at fixed 0.016 second time steps.
But objects will not move smoothly when slowing down time but choppy so if you want "Matrix" style slowmotion you will probably need to implement some interpolation tweening as well. Gaffer on Games explains it pretty well as Joe mentioned.
-
Sweenie
-
- Posts: 503
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest