Game Development Reference
In-Depth Information
// And return it.
return contactVelocity;
}
The code finds the acceleration and multiplies it by the duration to find the ve-
locity introduced at the rigid-body integration step. It converts this into contact co-
ordinates, and removes the component in the direction of the contact normal. The
resulting velocity is added to the contact velocity, to be removed in the velocity res-
olution step, as long as there is sufficient friction to do so. If there isn't sufficient
friction, then the object will slide down the slope exactly as it should.
16.1.3
I NTEGRATION S TABILITY
This enhancement needs some background explanation, so we'll return to the inte-
gration algorithm from chapters 3 and 10.
For both particles and rigid bodies I have used a similar integration algorithm.
It calculates the linear and angular acceleration and applies these to the velocity and
rotation, which are in turn applied to the position and orientation. This integration
algorithm is called Newton-Euler. Newton refers to the linear component (which is
based on Newton's laws of motion), and Euler refers to the angular component (Euler
was a mathematician who was instrumental in our understanding of rotation).
Our integrator uses the equations
p = ˙
˙
+ ¨
p
p t
and
p =
p
+ ˙
p t
(along with their rotational equivalents), each of which only depends on one level of
differentiation. They are therefore termed “first-order.” The overall method is more
fully called “first-order Newton-Euler,” or Newton-Euler 1.
Newton-Euler 2
As we saw in chapter 3, Newton-Euler 2 is an approximation. In high school physics
the equation
1
2 ¨
p =
+ ˙
p t 2
p
p t
+
is taught. This depends on two levels of differentiation. With the equivalent equation
for angular updates we have a second-order Newton-Euler integrator.
Newton-Euler 2 is more accurate than Newton-Euler 1. It takes into account ac-
celeration when determining the updated position. As we saw in chapter 3, the t 2
term is so small for high frame-rates that we may as well ignore the acceleration term