Game Development Reference
In-Depth Information
examples so far, let's call the first estimate v 1 and the second estimate v 2 . 2 A measure of
the truncation error is then:
e t = |v 1 - v 2 |
If you wish to keep the truncation error within a specified limit, e to , then you can use
the following formula to find out what your step size should be in order to maintain the
desired accuracy:
∆t new = ∆t old (e to / e t ) (1/2)
Here, ∆ t old is the old time step and ∆ t new is the new one that you should use to maintain
the desired accuracy. You'll have to make this check for each time step, and if you find
that the error warrants a smaller time step, then you'll have to back up a step and repeat
it with the new time step.
Here's a revised StepSimulation function that implements this adaptive step size tech‐
nique, checking the truncation error on the velocity integration:
// New global variable
float eto; // truncation error tolerance
// This function progresses the simulation by dt seconds using
// Euler's basic method with an adaptive step size
void StepSimulation(float dt)
float F; // total force
float A; // acceleration
float Vnew; // new velocity at time t + dt
float Snew; // new position at time t + dt
float V1, V2; // temporary velocity variables
float dtnew; // new time step
float et; // truncation error
// Take one step of size dt to estimate the new velocity
F = (T − (C * V));
A = F / M;
V1 = V + A * dt;
// Take two steps of size dt/2 to estimate the new velocity
F = (T − (C * V));
A = F / M;
V2 = V + A * (dt/2);
F = (T − (C * V2));
2. Even though we're talking about velocity and time here, these techniques apply to any function—for example,
displacement versus time, etc.
Search Nedrilad ::

Custom Search