With these orientations you can figure out the layout of each bone of the
model, and you use the same transformation matrices. Figuring out the
positions of bones, given the angles of the joints, is called forward
kinematics.
Forward Kinematics
Understanding the way transformations are concatenated is pivotal to
understanding forward kinematics. See Chapter 4 for a discussion on this
topic if you’re rusty on it.
Let’s say we’re dealing with the simple case of a 2D two-linkage sys
-
tem—an upper arm and a lower arm, with shoulder and elbow joints. We’ll
define the vertices of the upper arm with a local origin of the shoulder and
the vertices sticking out along the x-axis. The lower arm is defined in the
same manner, just using the elbow as the local origin. There is a special
point in the upper arm that defines where the elbow joint is situated.
There is also a point that defines where the shoulder joint is situated rela
-
tive to the world origin.
Chapter 8: Advanced 3D Techniques n 343
Figure 8.1: Building a hierarchy of rigid objects to make a humanoid
The first task is to transform the points of the upper arm. What you want
to do is rotate each of the points about the shoulder axis by the shoulder
angle q
1
, and then translate them so that they are situated relative to the
origin. So the transformation becomes:
upper-arm transformation = R
Z
(q
1
)T(shoulder_location)
Transforming the elbow points is more difficult. Not only are they depend
-
ent on the elbow angle q
2
, but they also depend on the position and angle
of their parent: the upper arm and shoulder joint.
We can subdivide the problem to make it easier. If we can transform
the elbow points to orient them relative to the origin of the shoulder, then
344 n Chapter 8: Advanced 3D Techniques
Figure 8.2: The untransformed upper- and lower-arm segments
Figure 8.3: The result of transforming just the shoulder
we can just add to that the transformation for the shoulder to take them to
world space. This transformation becomes:
lower-arm transformation = R
Z
(q
2
)T(elbow_location)
R
Z
(q
1
)T(shoulder_location)
or
lower-arm transformation = R
Z
(q
2
)T(elbow_location)
upper-arm transformation
This system makes at least some intuitive sense. Imagine we have some
point on the lower arm, initially in object space. The rotation by q
2
rotates
the point about the elbow joint, and the translation moves the point such
that the elbow is sticking out to the right of the origin. At this point we
have the shoulder joint at the origin, the upper arm sticking out to the
right, a jointed elbow, and then our point somewhere on the lower arm.
The next transformation we apply is the rotation by q
1
, which rotates
everything up to this point (the lower arm and upper arm) by the shoulder
angle. Finally, we apply the transformation to place the shoulder some
-
where in the world a little more meaningful than the world space origin.
This system fits into a clean recursive algorithm very well. At each
stage of the hierarchy, we compute the transformation that transforms the
current joint to the space of the joint above it in the hierarchy, appending it
to the front of the current world matrix, and recursing with each of the
children.
Chapter 8: Advanced 3D Techniques n 345
Figure 8.4: The fully transformed arm

Get Advanced 3D Game Programming with DirectX 10.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.