i
i
i
i
i
i
i
i
88 4. Transforms
many more targets to be used in a single model and the effects computed
exclusively on the GPU [793].
A real example of using both skinning and morphing is shown in Fig-
ure 4.15.
Figure 4.15. The Rachel character’s facial expressions and movements are controlled by
skinning and vertex morphing, which are accelerated by using graphics hardware sup-
port. (Images by Alex Vlachos, John Isidoro, Dave Gosselin, and Eli Turner; courtesy
of ATI Technologies Inc. and LifeFX.)
i
i
i
i
i
i
i
i
4.6. Projections 89
4.6 Projections
Before one can actually render a scene, all relevant objects in the scene must
be projected onto some kind of plane or into some kind of simple volume.
After that, clipping and rendering are performed (see Section 2.3).
The transforms seen so far in this chapter have left the fourth com-
ponent, the w-component, unaffected. That is, points and vectors have
retained their types after the transform. Also, the bottom row in the 4 ×4
matrices has always been (0 0 0 1). Perspective projection matrices are
exceptions to both of these properties: The bottom row contains vector
and point manipulating numbers, and the homogenization process is often
needed (i.e., w is often not 1, so a division by w is needed to obtain the
nonhomogeneous point). Orthographic projection, which is dealt with first
in this section, is a simpler kind of projection that is also commonly used.
It does not affect the w component.
In this section, it is assumed that the viewer is looking along the nega-
tive z-axis, with the y-axis pointing up and the x-axis to the right. This is
a right-handed coordinate system. Some texts and software, e.g., DirectX,
use a left-handed system in which the viewer looks along the positive z-
axis. Both systems are equally valid, and in the end, the same effect is
achieved.
4.6.1 Orthographic Projection
A characteristic of an orthographic projection is that parallel lines remain
parallel after the projection. Matrix P
o
, shown below, is a simple ortho-
graphic projection matrix that leaves the x-andy-components of a point
unchanged, while setting the z-component to zero, i.e., it orthographically
projects onto the plane z =0:
P
o
=
1000
0100
0000
0001
. (4.59)
The effect of this projection is illustrated in Figure 4.16. Clearly, P
o
is
non-invertible, since its determinant |P
o
| = 0. In other words, the trans-
form drops from three to two dimensions, and there is no way to retrieve
the dropped dimension. A problem with using this kind of orthographic
projection for viewing is that it projects both points with positive and
points with negative z-values onto the projection plane. It is usually use-
ful to restrict the z-values (and the x-andy-values) to a certain interval,
i
i
i
i
i
i
i
i
90 4. Transforms
Figure 4.16. Three different views of the simple orthographic projection generated by
Equation 4.59. This projection can be seen as the viewer is looking along the negative
z-axis, which means that the projection simply skips (or sets to zero) the z-coordinate
while keeping the x-andy-coordinates. Note that objects on both sides of z =0are
projected onto the projection plane.
from, say n (near plane) to f (far plane).
14
This is the purpose of the next
transformation.
A more common matrix for performing orthographic projection is ex-
pressed in terms of the six-tuple, (l, r, b,t, n, f), denoting the left, right, bot-
tom, top, near, and far planes. This matrix essentially scales and translates
the AABB (Axis-Aligned Bounding Box; see the definition in Section 16.2)
formed by these planes into an axis-aligned cube centered around the or i-
gin. The minimum corner of the AABB is (l, b, n) and the maximum corner
is (r, t, f ). It is important to realize that n>f,becausewearelooking
down the negative z-axis at this volume of space. Our common sense says
that the near value should b e a lower number than the far. OpenGL, which
also looks down the negative z-axis, presents their input near value as less
than far in the orthographic matrix creation call glOrtho, then internally
negates these two values. Another way to think of it is that OpenGL’s
near and far values are (positive) distances along the view direction (the
negative z-axis), not z eye coordinate values.
In OpenGL the axis-aligned cube has a minimum cor ner of (1, 1, 1)
and a maximum corner of (1, 1, 1); in DirectX the bounds are (1, 1, 0) to
(1, 1, 1). This cube is called the canonical view volume and the coordinates
in this volume are called normalized device coordinates. The transformation
14
The near plane is also called the front plane or hither; the far plane is also the back
plane or yon.
i
i
i
i
i
i
i
i
4.6. Projections 91
Figure 4.17. Transforming an axis-aligned box on the canonical view volume. The box
on the left is first translated, making its center coincide with the origin. Then it is scaled
to get the size of the canonical view volume, shown at the right.
procedure is shown in Figure 4.17. The reason for transforming into the
canonical view volume is that clipping is more efficiently performed there.
After the transformation into the canonical view volume, vertices of the
geometry to be rendered are clipped against this cube. The geometry not
outside the cube is finally rendered by mapping the remaining unit square
to the screen. This orthographic transform is shown here:
P
o
= S(s)T(t)=
2
r l
000
0
2
t b
00
00
2
f n
0
00 01
100
l + r
2
010
t + b
2
001
f + n
2
000 1
=
2
r l
00
r + l
r l
0
2
t b
0
t + b
t b
00
2
f n
f + n
f n
00 0 1
.
(4.60)
As suggested by this equation, P
o
can be written as the concatenation of
atranslation,T(t), followed by a scaling matrix, S(s), where s =(2/(r
l), 2/(t b), 2/(f n)), and t =((r + l)/2, (t + b)/2, (f + n)/2). This
matrix is invertible,
15
i.e., P
1
o
= T(t)S((r l)/2, (t b)/2, (f n)/2).
15
If and only if n = f, l = r,andt = b; otherwise, no inverse exists.
i
i
i
i
i
i
i
i
92 4. Transforms
In computer graphics, a left-hand coordinate system is most often used
after projection—i.e., for the viewport, the x-axis goes to the right, y-axis
goes up, and the z-axis goes into the viewport. Because the far value is less
than the near value for the way we defined our AABB, the orthographic
transform will always include a mirroring transform. To see this, say the
original AABBs is the same size as the goal, the canonical view volume.
Then the AABB’s coordinates are (1, 1, 1) for (l, b,n)and(1, 1, 1) for
(r, t, f ). Equation 4.60 yields
P
o
=
1000
0100
0010
0001
, (4.61)
which is a mirroring matrix. It is this mirroring that converts from the
right-handed viewing coordinate system (looking down the negative z-axis)
to left-handed normalized device coordinates.
DirectX maps the z-depths to the range [0, 1] instead of OpenGL’s
[1, 1]. This can be accomplished by applying a simple scaling and trans-
lation matrix applied after the orthographic matrix, that is,
M
st
=
10 0 0
01 0 0
000.50.5
00 0 1
. (4.62)
So the orthographic matrix used in DirectX is
P
o[0,1]
=
2
r l
00
r + l
r l
0
2
t b
0
t + b
t b
00
1
f n
n
f n
00 0 1
. (4.63)
which is normally presented in transposed form, as DirectX uses a row-
major form for writing matrices.
4.6.2 Perspective Projection
A much more interesting transform than orthographic projection is per-
spective projection, which is used in the majority of computer graphics
applications. Here, parallel lines are generally not parallel after projection;
rather, they may converge to a single point at their extreme. Perspective
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset