Game Development Reference
In-Depth Information
objects around with the mouse, then you'll need some virtualization of the force applied
by the user via the mouse or a finger on a touch screen. This is an example of a direct
force. Another direct force effector could be a virtual jet engine. If you associate that
virtual engine, which produces some thrust force, with some object, then the associated
object will behave as though it were pushed around by the jet.
Some examples of indirect force effectors include gravity and wind. Gravity applies force
on objects by virtue of their mass, but it is typically modeled as body acceleration and
not an explicit force. Wind can be viewed as exerting a pressure force on an object, and
that force will be a function of the object's size and drag coefficients.
You can imagine all sorts of force effectors, from ones similar to those just described to
perhaps some otherworldly ones. Whatever you imagine, you must remember that a
force has magnitude, direction, and some central point of application. If you put a jet
engine on the side of a box, the box will not only translate but will spin as well. Wind
creates a force that has a center of pressure, which is the point through which you can
assume the total wind force acts. The direction of the force and point of application are
important for capturing both translation and rotation. As an example, consider the
hovercraft we modeled in Chapter 9 that included two bow thrusters for steering and a
propeller for forward motion. Each of these direct force effectors—the bow thrusters
and the propeller—is applied at specific locations on the hovercraft. The bow thrusters
are located toward the bow and point sideways in order to create spin, thus allowing
some steering. The propeller is located on the center line of the hovercraft, which passes
through the hovercraft's center of gravity so that it does not create spin and instead
simply pushes the craft forward. There's another force effector in that model—aerody‐
namic drag, which is an indirect force effector. The drag force is applied at a point aft
of the center of gravity so that it creates some torque, or moment, which in this model
helps keep the hovercraft pointed straight; it provides some directional stability.
Whatever force effectors you contrive, they all must be aggregated for each object and
dealt with in your numerical integrator. Thus, your integrator must have some means
of accessing all the force effector information required to accurately simulate their effect
on each associated object.
Numerical Integrator
The integrator is responsible for solving the equations of motion for each object. We
showed you how to do this earlier, in Chapter 7 through Chapter 13 . In your generic
physics engine you'll iterate through all the objects in the simulation to compute their
new velocities, positions, and orientations at every time step. To make these calculations,
your integrator must have access to the force effectors associated with each object. The
forces will be used to compute accelerations, which will then be integrated to compute
velocities, and those in turn will be used to compute positions and orientations.