Game Engine Architecture

(Ben Green) #1
663

ly, it would be called an impulse—more on that below.) The forces in a game
are oft en dynamic in nature—they oft en change their directions and/or their
magnitudes every frame. So the force-application function in most physics
SDKs is designed to be called once per frame for the duration of the force’s
infl uence. The signature of such a function usually looks something like this:
applyForce(const Vector& forceInNewtons), where the duration of the
force is assumed to be Δt.


12.4.9.3. Applying Torques


When a force is applied such that its line of action passes through the center of
mass of a body, no torque is generated, and only the body’s linear acceleration
is aff ected. If it is applied off -center, it will induce both a linear and a rotational
acceleration. A pure torque can be applied to a body as well by applying two
equal and opposite forces to points equidistant from the center of mass. The
linear motions induced by such a pair of forces will cancel each other out (since
for the purposes of linear dynamics, the forces both act at the center of mass).
This leaves only their rotational eff ects. A pair of torque-inducing forces like
this is known as a couple (htt p://en.wikipedia.org/wiki/Couple_(mechanics)).
A special function such as applyTorque(const Vector& torque) may be
provided for this purpose. However, if your physics SDK provides no apply
Torque() function, you can always write one and have it generate a suitable
couple instead.


12.4.9.4. Applying Impulses


As we saw in Section 12.4.7.2, an impulse is an instantaneous change in veloc-
ity (or actually, a change in momentum). Technically speaking, an impulse
is a force that acts for an infi nitesimal amount of time. However, the short-
est possible duration of force application in a time-stepped dynamics simu-
lation is Δt, which is not short enough to simulate an impulse adequately.
As such, most physics SDKs provide a function with a signature such as
applyImpulse(const Vector& impulse) for the purposes of applying
impulses to bodies. Of course, impulses come in two fl avors—linear and an-
gular—and a good SDK should provide functions for applying both types.


12.4.10. The Collision/Physics Step


Now that we’ve covered the theory and some of the technical details behind
implementing a collision and physics system, let’s take a brief look at how
these systems actually perform their updates every frame.
Every collision/physics engine performs the following basic tasks during
its update step. Diff erent physics SDKs may perform these phases in diff erent


12.4. Rigid Body Dynamics

Free download pdf