Game Development Reference
In-Depth Information
This is called Euler integration (pronounced oiler, not yew-ler). A simple
modification gives us Midpoint integration, which yields a reasonable improvement
in accuracy. All we need to do is apply the acceleration in halves before and after
applying velocity:
var halfAccel = mesh.acceleration.clone().multiplyScalar(delta *
0.5);
// Apply half acceleration (first half of midpoint formula)
mesh.velocity.add(halfAccel);
// Apply thrust
mesh.position.add(mesh.velocity.clone().multiplyScalar(delta));
// Apply half acceleration (second half of midpoint formula)
mesh.velocity.add(halfAccel);
To understand how this works, consider the following graph:
Euler versus Midpoint integration
The goal of our integration formula is to stay as close to the true position as possible.
In the graph, the vertical jumps are at our time-steps, where physics updates are
calculated. The midpoint curve is just a shift of the Euler curve so that the area
between the midpoint and true positions cancel out. More error is introduced when
acceleration, jerk, and nonlinear forces are applied, but for our purposes (and in the
space we have) the midpoint formula is a reasonable trade-off between simplicity
and accuracy.
 
Search WWH ::




Custom Search