Game Development Reference

In-Depth Information

i
(left) to global coordinates
x
i
(right)

using the positions of its joint
j
i
and the joint's parent
j
p
.

rel

Figure 14.9.
Transforming a relative coordinate
x

where
q
is the rotation quaternion and
j
i
is the position of the joint. Quaternions

are explained in the introductory chapter (Chapter 1), since they are quite use-

ful for the representation of rotations in computer graphics—especially character

animation.

The vertex positions are relative to its supporting joint and have to be trans-

formed into global space (se
e
Figure 14.9
)
.

The vertex structure is extended by a vector called
relPos
, which is the

position of a vertex relative to its supporting joint. This is the only coordinate

the designer has to supply; the
restPos
is calculated from this coordinate using

the above formula.

for
each joint j
{

v = j.pos

j.parent.pos;

normalize(v);

j

−

orient = rotationQuaternion(u, v);

for
each vertex v
{

j = v.joint;

tempPos = rotateVector(v.relPos, j.orient)

v.goalPos = tempPos + j.pos;

−>

}

In the first loop, we calculate the rotation quaternion of the joint as described

above. In the second loop, we use the calculated quaternion to transform our

relPos
coordinates into global space (
restPos
). These are again the positions

that are used by all the force calculations we discussed before.

Calculating the force.
We need a force that maintains the distance to the bone

for each vertex. For this, we compare the actual distance to the desired distance.

We have to calculate the distance from the bone to the actual positions
x
i
and

the distance to the rest positions
x
i
.

First, the unit vector in the direction of the joint's parent is obtained by