Game Development Reference
In-Depth Information
Figure 14.10. The projection x proj of the vertex x i on the bone is used to construct the
distance x ib from the bone for vertex x i . The distance is compared to the distance of the
rest position x i
bone
i
to construct a force f
that maintains the distance to the bone.
axis = joint.pos parentJoint.pos;
normalize(axis);
From this, the part of the vertex position that points in the direction of the joint's
parent can be calculated by taking the dot product, and the projection x proj of x i
on the bone can be calculated by multiplying the unit vector in the direction of the
bone with this quantity.
projection = dotProduct(axis, v.pos);
projVector = scaledVector(axis, projection);
The vector that points from the nearest point on the bone to the vertex x i is
now just the difference between x i and x proj . We call it x ib for the actual positions
and x ib for the goal positions. This is shown graphically in Figure 14.10.
With these two quantities, a force that pulls the vertex to the desired distance
from the bone can be constructed:
| x
1 x ib
0
ib |
| x ib |
f bone
i
=
,
h 2
is the length of x ib . Whenever x ib is longer than x ib , the force is
directed away from the bone (in the direction of x ib ), and if x ib
where
|
x ib |
is shorter than
x ib , the force is directed towards the bone, as is needed.