(by Sean Anderson)
Know:
- How to construct a perspective matrix given the left, right, top,
bottom, near, and far clipping planes (look up and read about
glFrustum()).
- What the OpenGL viewing pipeline is, from object space to window
coordinates.
- Off-axis viewing frustums.
Simple Perspective Questions
- Give 2 reasons for clipping before homogenization.
- Avoids unnecessary divisions.
- Allows easier clipping of lines or polygons that go
through the view frustum and have a point behind the viewer.
Imagine you have a line that has one point in the frustum and
another point that is behind it. For concreteness, suppose
the points of the line are P1 = [1 1 10000 1]' and P2 = [-1
-1 10000 1]' (where ' means transpose). Suppose that the
perspective view frustum has near=1, far=2, and the
horizontal and vertical fields of view are both 90 degrees.
The viewer is at the origin looking down the -z axis. So,
left = -1, right = +1, bottom = -1,
top = +1, and the perspective matrix, M, we get after
plugging in the expression described in the glFrustum() man
pages, we get:
1 0 0 0
0 1 0 0
0 0 -3 -4
0 0 -1 0
So, applying the perspective transformation and homogenizing, we get:
M*P1' = [1 1 -30004 -10000]' -> [-.0001 -.0001 3.0004 1]'
M*P2' = [-1 -1 29996 10000]' -> [-.0001 -.0001 2.9996 1]'
Notice that the line connecting these two transformed points
does not go through the normalized device space box,
(-1, -1, -1) to (+1, +1, +1). The line does
intersect the view frustum, though. Thus we see clipping lines
(and my a similar reason, polygons) after homogenizing is not such
a simple matter.
- Note the following
reason, which is given in the online notes and previously here
too, is wrong: Allows detection of points behind the viewer (This
benefit is only an issue when points can have W values other than
1, such as in rendering NURBS or fancy shadow algorithms). Sorry
for the confusion.
- What is the condition used to determine if the x coordinate (xc) of a
non-homogeneous projected point is within the left and right walls (at
-1 and +1 on the near plane) of a perspective view frustum?
if (-wc <= xc <= wc) then inside.
(Since we can multiply by wc through (-1 <= xc/wc <= 1).)
- What part of a 4x4 matrix tells you that it is a perspective
transformation?
If any of the first 3 elements of the last row are not [0 0 0], then it
is a perspective transform.
- Consider a view of a scene with 2 cubes oriented arbitrarily; how many
vanishing points could there be in the image?
Six (one for each distinct edge direction).
- Where is the viewer's eye and what is the viewing direction when the
perspective transform is applied?
The eye is at the origin. The view is down the -z direction.
Minor Clarification:
* The normalized device coordinate space used in Foley (your
encyclopedic text) has z ranging from 0 to 1. In lecture and in OpenGL,
it ranges from -1 to +1.