Game Development Reference
In-Depth Information
The two loops add all the forces being applied to the game object. The first loop just
iterates through and accumulates a result. The second loop is different, because as it
accumulates the result, the list is emptied. This is because the forces are impulses, and
thus they only happen once. The resulting acceleration is calculated by dividing the accu-
mulated force (F) by the object
'
s mass. Once that is done, you can update the object
'
s
velocity and position. I
'
ll leave the implementation of RemoveForce() up to you.
Physics Engines Are Very Time Sensitive
You must be extremely careful with the value of time. If you send in a value
either too big or too small, you
ll get some unpredictable results. Very small
values of time can accentuate numerical imprecision in floating-point math,
and since time is essentially squared in the position calculation, you can run
into precision problems there, too. If your physics system is acting strangely,
check how often it is being called first.
'
Rotational Inertia, Angular Velocity, and Torque
When an object moves through space, its location always references the center of
mass. Intuitively, you know what the center of mass is, but it is interesting to note
some special properties about it. For one thing, when the object rotates freely, it
always rotates about the center of mass. If the object is sitting on the ground, you
can tip it, and it will only fall when the center of mass is pushed past the base of
the object. That
s easier to knock over a cardboard tube standing on its end
than a pyramid sitting on its base.
Different objects rotate very differently, depending on their shape and how their
weight is distributed around the volume of the shape. A Frisbee spins easily when I
throw it, but it doesn
'
s why it
'
t spin as well end-over-end, like when my youngest nephew
throws it! Mathematically, this property of physical objects is called the inertia tensor.
It has a very cool name, and you can impress your friends by working it into
conversations.
The inertia tensor is something that is calculated ahead of time and stored in the
physical properties of the object. It
'
s pretty expensive to create at runtime. It is a
3 × 3 matrix, describing how difficult it is to rotate an object on any possible axis.
An object
'
s shape, density, and mass are all used to compute the inertia tensor; it is
usually done when you create an object. It
'
s much more preferable to precompute the
inertia tensor and store it. This calculation isn
'
'
t trivial. As you might expect, the iner-
tia tensor is to orientation as mass is to position; it is a property of the object that
will affect how the object rotates.
 
 
Search WWH ::




Custom Search