Game Development Reference
In-Depth Information
electrical bonds present in that tiny piece of tissue paper are sufficient to withstand the gravitational force
exerted on the cell phone by the entire planet Earth.
Heavier things exert a larger force in a gravitational field, such as when you place a
weight on your chest. At sea level, Earth
s gravity causes an acceleration of exactly
9.80665 meters/s 2 on every object. Thus, a one kilogram object exerts a force of
9.80665N. To get an idea of how big that force is, lie down and set this topic on
your chest. It turns out to be around 1.5 kilograms, give or take Chapter 5, so you
will experience a force of about 1.5N. So one Newton is not all that big, really, if
you are the size of a human being and the force is somewhat distributed over a
book-sized area. Balance this topic on a fork, tines downward, and you
'
ll see how
that distribution will change your perception of one Newton. Area, as it seems,
makes a huge difference.
Let
'
s look at the code that would apply a constant acceleration, like gravity, to an
object. We
'
ll also look at code that applies an instantaneous force. Forces are vectors
and are therefore additive, so multiple forces (f 0 ,f 1 ,f 2 ,
'
) on one object are added
together to get an overall force (f):
f 0 +f 1 +f 2 +
or in shorthand, we write
n
x ¼ 0 f x
Just so you know, the C++ version of that math formula is a simple for loop:
F ¼
Vec3 AddVectors(const Vec3 *f, int n)
{
Vec3 F = Vec3(0,0,0);
for (int x = 0; x < n; x++)
F += f[x];
return F;
}
A constant force over time equates to some acceleration over time, depending on the
object
s mass. An impulse is instantaneous, so it only changes the acceleration once.
Think of it like the difference between the force of a rocket motor and the force of
hitting something with a golf club: One happens over time, and the other is instanta-
neous. Take a look at a simple game object class:
'
typedef std::list<Vec3> Vec3List;
 
Search WWH ::




Custom Search