9
710 Chapter 13: reactor
t it is better to split this into n steps of a smaller
time inter val t/n.
This is also true of the math. As the simulation
becomes more complex, the math required to
calculate the new positions and velocities of objects
in a simulation also becomes more complex, and
as a result the g uesses produced by the math give
progressively less-accurate results.
So the principle is to take small time steps, evaluate
all the forces acting on the objects, determine
the new positions and velocities (and other
parameters)oftheobjectsattheendofthetime
steps, and then s tart over. We e nd up with a series
of snapshots of the state of the system as it evolves,
asshowninthefollowingillustration.
Substeps
In the previous section, we said that the physics
engine passes on the necessary information to
update the display after it determines the new
positions for all its objects. However, what if you
don’twanttoupdatethedisplayineachsimulation
time step?
Let ’s say we absolutely need to update the
application once every 1/60th of a second, either
because we’re playing a real-time game that
refreshes t he screen at 60Hz. or we’re creating a
keyframe every frame for a 60FPS movie. T his
effectively means that we want to step the physics
engine at intervals of 1/60th of a second. In many
cases this does not present a problem, but if,
hypothetically, the accuracy of the simulation was
not sufficient (remember: smaller time steps mean
better accuracy), then we’d like to decrease the
time step even further, say to 1/120th of a second.
But this would mean we gener ate twice the number
of images/keyf rames we are interested in, which
is wasteful. To get around this, the Havok engine
allows you to specify the number of substeps to
take per key.
The Substeps/Key par ameter specifies the number
of steps the physics engine takes before updating
the application. This gives control over the
granular ity of the physics simulation independent
of the display update or keyframe-creation
frequency. So with Substeps/Key=1, reactor uses
a single simulation step for each update to the
3D display. With Substeps/Key=2, reactor takes
two physics steps each time before updating the
application, and so on.
In this figure, we have specified that the physics
simulation should step at intervals of 1/240th of a
second, but that we create a keyframe only once
every 1/60th of a second. The red spots indicate
a keyframe and simulation step, the yellow spots