i
i
i
i
i
i
i
i
154 7. Viewing
As you can see, x and y are scaled and, more importantly, divided by z. Because
both n and z (inside the view volume) are negative, there are no “flips” in x
and y. Although it is not obvious (see the exercise at the end of the chapter),
the transform also preserves the relative order of z values between z = n and
z = f, allowing us to do depth ordering after this matrix is applied. This will be
important later when we do hidden surface elimination.
Sometimes we will want to take the inverse of P, for example to bring a screen
coordinate plus z back to the original space, as we might want to do for picking.
The inverse is
P
−1
=
⎡
⎢
⎢
⎣
1
n
00 0
0
1
n
00
00 0 1
00−
1
fn
n+f
fn
⎤
⎥
⎥
⎦
.
Since multiplying a homogeneous vector by a scalar does not change its meaning,
the same is true of matrices that operate on homogeneous vectors. So we can
write the inverse matrix in a prettier form by multiplying through by nf:
P
−1
=
⎡
⎢
⎢
⎣
f 00 0
0 f 00
00 0 fn
00−1 n + f
⎤
⎥
⎥
⎦
.
This matrix is not literally
the inverse of the matrix
P, but the transformation
it describes
is
the inverse
of the transformation de-
scribed by P.
Taken in the context of the orthographic projection matrix M
orth
in Equa-
tion (7.3), the perspectivematrix simply maps the perspective view volume (which
is shaped like a slice, or frustum, of a pyramid) to the orthographic view volume
(which is an axis-aligned box). The beauty of the perspective matrix is, that once
we apply it, we can use an orthographic transform to get to the canonical view
volume. Thus, all of the orthographic machinery applies, and all that we have
added is one matrix and the division by w. It is also heartening that we are not
“wasting” the bottom row of our four by four matrices!
Concatenating P with M
orth
results in the perspective projection matrix,
M
per
= M
orth
P.
One issue, however, is: How are l,r,b,t determined for perspective? They
identify the “window” through which we look. Since the perspective matrix does
not change the values of x and y on the (z = n)-plane, we can specify (l, r,b, t)
on that plane.
To integrate the perspective matrix into our orthographic infrastructure, we
simply replace M
orth
with M
per
, which inserts the perspective matrix P after the
camera matrix M
cam
has been applied but before the orthographic projection. So