Game Development Reference
In-Depth Information
be the position of an object, or the force in a spring, or its rotational speed. The
quantities we are tracking in this way are mostly vectors (we'll return to the non-
vectors later in the topic).
There are two ways of understanding these changes: we describe the change itself,
and we describe the results of the change. If an object is changing position with time,
we need to be able to understand how it is changing position (i.e., its speed, the direc-
tion it is moving in, if it is accelerating or slowing) and the effects of the change (i.e.,
where it will be when we come to render it during the next frame of the game). These
two viewpoints are represented by differential and integral calculus, respectively. We
canlookateachinturn.
No code will be provided for this section; it is intended as a review of the concepts
involved only. The corresponding code makes up most of the rest of this topic, very
little of which will make sense unless you grasp the general idea of this section.
2.2.1
D IFFERENTIAL C ALCULUS
For our purposes we can view the differential of a quantity as the rate at which it
is changing. In the majority of this topic we are interested in the rate at which it is
changing with respect to time. This is sometimes informally called its “speed.”
When we come to look at vector calculus, however, speed has a different meaning.
It is more common in mathematics and almost ubiquitous in physics programming
to call it “velocity.”
Velocity
Think about the position of an object, for example. If this represents a moving object,
then in the next instance of time, the position of the object will be slightly different.
We can work out the velocity at which the object is moving by looking at the two
positions. We could simply wait for a short time to pass, find the position of the
object again, and use the formula
p
p
p
t
v
=
=
t
where v is the velocity of the object, p and p are its positions at the first and second
measurements (so p is the change in position), and t is the time that has passed
between the two. This would give us the average velocity over the time period. It
wouldn't tell us the exact velocity of the object at any point in time, however.
Figure 2.8 shows the position of two objects at different times. Both objects start
at the same place and end at the same place at the same time. Object A travels at a
constant velocity, whereas object B stays near its start location for a while and then
zooms across the gap very quickly. Clearly they aren't traveling at the same velocity.
If we want to calculate the exact velocity of an object, we could reduce the gap
between the first and second measurement. As the gap gets smaller, we get a more