Game Development Reference
In-Depth Information
screen just like the left-handed conventions assumed earlier. (In OpenGL,
clip space is actually a left-handed coordinate space!) This means we need
to negate our incoming z values, or alternatively, negate the third column
(after we've transposed the matrix), which is the column that is multiplied
by z.
The above procedure results in the following perspective projection ma-
trix
2
4 zoom x
3
0
0
0
5
0
zoom y
0
0
Clip matrix for
perspective projection
assuming OpenGL
conventions
,
f+n
f−n
−2nf
f−n
0
0
0
0
−1
0
and the orthographic projection matrix is
2
4 zoom x
3
5
0
0
0
Clip matrix for
orthographic projection
assuming OpenGL
conventions
0
zoom y
0
0
.
−2
f−n
f+n
f−n
0
0
0
0
0
1
So, for OpenGL conventions, you can tell whether a projection matrix is
perspective or orthographic based on the bottom row. It will be [0,0,−1,0]
for perspective, and [0,0,0,1] for orthographic.
Now that we know a bit about clip space, we can understand the need
for the near clip plane. Obviously, there is a singularity precisely at the
origin, where a perspective projection is not defined. (This corresponds
to a perspective division by zero.) In practice, this singularity would be
extremely rare, and however we wanted to handle it—say, by arbitrarily
projecting the point to the center of the screen—would be OK, since putting
the camera directly in a polygon isn't often needed in practice.
But projecting polygons onto pixels isn't the only issue. Allowing for
arbitrarily small (but positive) values of z will result in arbitrarily large
values for w. Depending on the hardware, this can cause problems with
perspective-correct rasterization. Another potential problem area is depth
buffering. Su ce it to say that for practical reasons it is often necessary
to restrict the range of the z values so that there is a known minimum
value, and we must accept the rather unpleasant necessity of a near clip
plane. We say “unpleasant” because the near clip plane is an artifact of
implementation, not an inherent part of a 3D world. (Raytracers don't
necessarily have this issue.) It cuts off objects when you get too close
to them, when in reality you should be able to get arbitrarily close. Many
readers are probably familiar with the phenomena where a camera is placed
in the middle of a very large ground polygon, just a small distance above
it, and a gap opens up at the bottom of the screen, allowing the camera to
see through the ground. A similar situation exists if you get very close to
Search WWH ::




Custom Search