Game Development Reference

In-Depth Information

struct
Ve r t ex

{

Vector3 pos; Vector3 vel; Vector3 goalPos;

Vector3 force;

// force coefficients

real factorRest;

real factorDetail ;

real factorNeighbors;

real factorDamping;

// one of the edges to retrieve neighborhood

DirectedEdge edge;

real mass;

}
;

Listing 14.1.
The complete vertex class.

for the model in question. A suitable parameter-fitting algorithm is presented

in [Shi et al. 08]. We have to keep in mind that there are limits within which the

parameters have to be set for a stable simulation. A complete vertex structure

that accumulates the per-vertex information about everything discussed until now

could look like Listing 14.1.

We accumulate the forces discussed so far with

+
α
neigh

i

f
neigh

i

f
total

i

=
α
rest

i

f
rest

i

+
α
detail

i

f
detail

i

·

·

·

and check whether the calculations work as intended. A block of 16 vertices

connected in a simple geometry is defined to test the implementation (see
Fig-

ure 14.7)
. The red spheres are the rest positions of the mesh while the white

spheres are the goal positions of the shape-matching algorithm. The actual po-

sitions are the yellow spheres. First, we can displace every vertex just a bit and

watch it go back into its original shape. If we apply a driving force to our block

on the right, even the vertices on the other end of the body start to wiggle about.

In the demo, we can also switch on a gravitational force (and set
factorRest

to zero) and watch the body hit the ground. The body stays in shape just by means

of the shape-matching algorithm (see
Figure 14.8
)
. A demo is included with the

supplemental materials.