Game Development Reference
In-Depth Information
of the acceleration (just as acceleration was the second derivative of the position).
This would give us an updated equation of
p t 2
2
p =
p
+ ˙
pt
+ ¨
[2.9]
p is the velocity of the object at the start of the time interval, and
p is the
where
constant acceleration over the whole time.
It is beyond the scope of this topic to describe how these equations are arrived
at: you can see any introduction to calculus for the basic algebraic rules for finding
equations for differentials and integrals. For our purposes in this topic I will provide
the equations: they match those found in applied mathematics books for mechanics.
Just as equation 2.7 assumes a constant velocity, equation 2.9 assumes a constant
acceleration. We could generate further equations to cope with changing accelera-
tions. As we will see in the next chapter, however, even 2.9 isn't needed when it comes
to updating the position; we can make do with the assumption that there is no accel-
eration.
In mathematics, when we talk about integrating, we mean to convert a formula
for velocity into a formula for position; or a formula for acceleration into one for
velocity—in other words, to do the opposite of a differentiation. In game develop-
ment the term is often used slightly differently: to integrate means to perform the
position or velocity updates. From this point on I will stick to the second use, since
we will have no need to do mathematical integration again.
Vector Integral Calculus
Just as we saw for differentiation, vectors can often take the place of scalars in the
update functions. Again this is not the case for mathematics in general, and most
of the formulae you find in mathematical textbooks on integration will not work
for vectors. In the case of the two integrals we will use in this topic—equations 2.7
and 2.8—it just so happens that it does. So we can write
p =
+ p t
p
and perform the calculation on a component-by-component basis:
p x + ˙
p x t
p y + ˙
p =
+ ˙
p
p t
=
p y t
p z + ˙
p z t
This could be converted into code as
position += velocity * t;
Search Nedrilad ::




Custom Search