Game Development Reference
In-Depth Information
Here is the pseudocode notation:
for each vertex v {
v.force = (v.restPos v.pos) / (timeStep timeStep);
v.vel += v.force
v.pos += v.vel timeStep;
With such a simulation, we would see the vertex positions oscillate about the
rest position on and on, for infinity (apart from numerical errors that are intro-
duced in every time step). The contribution of this force can be reduced as more
realistic forces are added to the system, but it should still be integrated into the
simulation since it helps to keep the system controllable, as there is always a trend
to the completely undeformed shape.
14.2.3 Safety Belts
This discussion would be completely out of place in a scientific simulation, but
here we are speaking of computer games—we have to deal with a lot of user
interaction, collisions, and rapid change of motion. Safety comes first.
Although the algorithms introduced in this chapter provide excellent robust-
ness that should be suitable for computer games, it can always happen that be-
cause of some unforeseeable reason, suddenly the system is totally pushed away
from its rest position or gets a boost in velocity that will blow up the whole sys-
We deal with this in the most straightforward way: we just have to follow the
simple principle of “If X hurts, don't do X .”
So whenever a vertex is too far away from its rest position, we just have to
make sure that it isn't.
Define a radius in which the vertex is allowed to be, and whenever it leaves
this sphere, put it back on the surface of the sphere.
The same should be done for the velocities. This is called position and velocity
clamping—a quick way to get rid of all possible accidents that can happen to the
14.2.4 Global Damping
This falls into the same category as position and velocity clamping but it can be
motivated on a physical basis. We always want our objects to come to rest at some
point in time, so we make sure they do.
Search Nedrilad ::

Custom Search