Game Development Reference
where s is the speed of the object, and d is its direction of movement. Using the equa-
tions for the magnitude and direction of any vector, the speed is given by
and the direction by
Both the speed and the direction can be calculated from a velocity vector using the
magnitude and normalize methods we developed earlier in the chapter; they do not
need additional code.
The speed of an object is rarely needed in physics development: it has an applica-
tion in calculating aerodynamic drag, but little else. Both the speed and the direction
of movement are often used by an animation engine to work out what animation to
play as a character moves. This is less common for physically controlled characters.
Mostly this is a terminology issue: it is worth getting into the habit of calling
velocity velocity ,because speed has a different meaning.
I NTEGRAL C ALCULUS
In mathematics, integration is the opposite of differentiation. If we differentiate
something, and then integrate it, we get back to where we started.
In the same way that we got the velocity from the position using differentiation,
we go the other way in integration. If we know the velocity, then we can work out
the position at some point in the future. If we know the acceleration, we can find the
velocity at any point in time.
In physics engines, integration is used to update the position and velocity of each
object. The chunk of code that performs this operation is called the “integrator.”
Although integration in mathematics is an even more complex process than dif-
ferentiation, involving considerable algebraic manipulation, in game development it
is very simple. If we know that an object is moving with a constant velocity (i.e., no
acceleration), and we know this velocity along with how much time has passed, we
can update the position of the object using the formula
p is the constant velocity of the object over the whole time interval.
This is the integral of the velocity: an equation that gives us the position. In the
same way we could update the object's velocity in terms of its acceleration using the
p = ˙
Equation 2.7 only works for an object that is not accelerating. Rather than finding
the position by the first integral of the velocity, we could find it as the second integral