Game Development Reference
In-Depth Information
Numerical solutions of differential equations may be unstable because the prob-
lem being solved is unstable or because the numerical method fails. Care has to
be taken to construct forces that prevent these instabilities. Additionally, damping
can help to get an integration scheme stable.
The next logical step now is to model realistic forces. We will start with a
simple force that forms the basis for all other forces we will discuss.
14.2.2 The Spring Force
To get a force that pulls a vertex towards a desired goal position (like its rest
position), think of a spring that links the vertex to its goal position. Each spring
has a certain constant, which gives us the force driving it to its goal position.
When the spring force is too strong compared to the time step, the system will
overshoot, which means that it will be driven to the other side of the spring, and
even more far away than it was before. This way, the vertex will never reach its
goal position, but it will steadily increase its energy. The system “explodes.”
The maximum force that will drive an object towards a rest position without
overshooting is given by
= x i
x i
f rest
i
.
h 2
That this force does not overshoot can be seen by starting off at some time 0
and calculating the succeeding positions and velocities for the next two time steps.
The system will “convert” the displacement from the rest position (which means
potential energy) into speed (which means kinetic energy), and the speed back
into displacement, but the displacement will not get bigger over time, so the total
energy will not rise over time. This force can be scaled by a factor smaller than 1
to make the force smaller—this is a first example of a material property that can
be tuned by the designer on a per-vertex basis.
When we calculate the force as presented above, it is absolutely necessary
that the time step h be fixed to a certain value throughout the simulation and the
system be integrated in constant intervals. The physics integration should be run
on a dedicated thread, where it updates the positions and velocities at a constant
rate, like 30 frames per second (FPS).
With the knowledge of this force, a simple form of secondary motion can
be constructed. With the calculated force, we need to update our velocities and
the actual positions (that are drawn on the screen) according to the presented
integration scheme.