i
i
i
i
i
i
i
i
4.6. Projections 93
Figure 4.18. The notation used for deriving a perspective projection matrix. The point
p is projected onto the plane z = d, d>0, which yields the projected point q.The
projection is performed from the perspective of the camera’s location, which in this case
is the origin. The similar triangle used in the derivation is shown for the x-component
at the right.
more closely matches how we perceive the world, i.e., objects further away
are smaller.
First, we shall present an instructive derivation for a perspective pro-
jection matrix that projects onto a plane z = d, d>0. We derive from
world space to simplify understanding of how the world-to-view conversion
proceeds. This derivation is followed by the more conventional matrices
used in, for example, OpenGL [970].
Assume that the camera (viewpoint) is located at the origin, and that
we want to project a point, p, onto the plane z = d, d>0, yielding a
new point q =(q
x
,q
y
, d). This scenario is depicted in Figure 4.18. From
the similar triangles shown in this figure, the following derivation, for the
x-component of q, is obtained:
q
x
p
x
=
d
p
z
⇐⇒ q
x
= d
p
x
p
z
. (4.64)
The expressions for the other components of q are q
y
= dp
y
/p
z
(obtained
similarly to q
x
), and q
z
= d. Together with the above formula, these give
us the perspective projection matrix, P
p
, as shown here:
P
p
=
1000
0100
0010
001/d 0
. (4.65)
i
i
i
i
i
i
i
i
94 4. Transforms
Figure 4.19. The matrix P
p
transforms the view frustum into the unit cube, which is
called the canonical view volume.
That this matrix yields the correct perspective projection is confirmed
by the simple verification of Equation 4.66:
q = P
p
p =
1000
0100
0010
001/d 0
p
x
p
y
p
z
1
=
p
x
p
y
p
z
p
z
/d
dp
x
/p
z
dp
y
/p
z
d
1
.
(4.66)
The last step comes from the fact that the whole vector is divided by the
w-component (in this case p
z
/d), in order to get a 1 in the last position.
The resulting z value is always d since we are projecting onto this plane.
Intuitively, it is easy to understand why homogeneous coordinates al-
low for projection. One geometrical interpretation of the homogenization
process is that it projects the point (p
x
,p
y
,p
z
) onto the plane w =1.
As with the orthographic transformation, there is also a perspective
transform that, rather than actually projecting onto a plane (which is non-
invertible), transforms the view frustum into the canonical view volume
described previously. Here the view frustum is assumed to start at z = n
and end at z = f,with0>n>f. The rectangle at z = n has the mini-
mum corner at (l, b,n) and the maximum corner at (r, t, n). This is shown
in Figure 4.19.
The parameters (l, r, b, t,n, f) determine the view frustum of the cam-
era. The horizontal field of view is determined by the angle between the
left and the right planes (determined by l and r) of the frustum. In the
same manner, the vertical field of view is determined by the angle between
the top and the bottom planes (determined by t and b). The greater the
field of view, the more the camera sees.” Asymmetric frustums can be
created by r = l or t = b. Asymmetric frustums are, for example, used
for stereo viewing (see Section 18.1.4) and in CAVEs [210].
i
i
i
i
i
i
i
i
4.6. Projections 95
The field of view is an important factor in providing a sense of the scene.
The eye itself has a physical field of view compared to the computer screen.
This relationship is
φ = 2 arctan(w/(2d)), (4.67)
where φ is the field of view, w is the width of the object perpendicular
to the line of sight, and d is the distance to the object. For example,
a 21-inch monitor is about 16 inches wide, and 25 inches is a minimum
recommended viewing distance [27], which yields a physical field of view
of 35 degrees. At 12 inches away, the field of view is 67 degrees; at 18
inches, it is 48 degrees; at 30 inches, 30 degrees. This same formula can
be used to convert from camera lens size to field of view, e.g., a standard
50mm lens for a 35mm camera (which has a 36mm wide frame size) gives
φ = 2 arctan(36/(2 50)) = 39.6 degrees.
Using a narrower field of view compared to the physical setup will lessen
the perspective effect, as the viewer will be zoomed in on the scene. Setting
a wider field of view will make objects appear distorted (like using a wide
angle camera lens), especially near the screen’s edges, and will exaggerate
the scale of nearby objects. However, a wider field of view gives the viewer
a sense that objects are larger and more impressive, and has the advantage
of giving the user more information about the surroundings.
The perspective transform matrix that transforms the frustum into a
unit cube is given by Equation 4.68:
16
P
p
=
2n
r l
0
r + l
r l
0
0
2n
t b
t + b
t b
0
00
f + n
f n
2fn
f n
00 1 0
. (4.68)
After applying this transform to a point, we will get another point q =
(q
x
,q
y
,q
z
,q
w
)
T
.Thew-component, q
w
, of this point will (most often) be
nonzero and not equal to one. To get the projected point, p, we need to
divide by q
w
: p =(q
x
/q
w
,q
y
/q
w
,q
z
/q
w
, 1)
T
.ThematrixP
p
always sees
to it that z = f maps to +1 and z = n maps to 1. After the perspective
transform is performed, clipping and homogenization (division by w)is
done to obtain the normalized device coordinates.
To get the perspective transform used in OpenGL, first multiply with
S(1, 1, 1), for the same reasons as for the orthographic transform. This
simply negates the values in the third column of Equation 4.68. After
this mirroring transform has been applied, the near and far values are
16
The far plane can also be set to infinity. See Equation 9.8 on page 345 for this form.
i
i
i
i
i
i
i
i
96 4. Transforms
entered as positive values, with 0 <n
<f
, as they would traditionally
be presented to the user. However, they still represent distances along
the world’s negative z-axis, which is the direction of view. For reference
purposes, here is the OpenGL equation:
17
P
OpenGL
=
2n
r l
0
r + l
r l
0
0
2n
t b
t + b
t b
0
00
f
+ n
f
n
2f
n
f
n
00 10
. (4.69)
Some APIs (e.g., DirectX) map the near plane to z = 0 (instead of
z = 1) and the far plane to z = 1. In addition, DirectX uses a left-
handed coordinate system to define its projection matrix. This means
DirectX looks along the positive z-axis and presents the near and far values
as positive numbers. Here is the DirectX equation:
P
p[0,1]
=
2n
r l
0
r + l
r l
0
0
2n
t b
t + b
t b
0
00
f
f
n
f
n
f
n
00 1 0
. (4.70)
DirectX uses row-major form in its documentation, so this matrix is nor-
mally presented in transposed form.
One effect of using a perspective transformation is that the computed
depth value does not vary linearly with the input p
z
value. For example,
if n
=10andf
= 110 (using the OpenGL terminology), when p
z
is
60 units down the negative z-axis (i.e., the halfway point) the normalized
device coordinate depth value is 0.833, not 0. Figure 4.20 shows the effect
of varying the distance of the near plane from the origin. Placement of
the near and far planes affects the precision of the Z-buffer. This effect is
discussed further in Section 18.1.2.
17
So, to test that this really works in the z-direction, we can multiply P
OpenGL
with
(0, 0, n
, 1)
T
.Thez-component of the resulting vector will be 1. If we instead use
the vector (0, 0, f
, 1)
T
,thez-component will be +1, as expected. A similar test can
be done for P
[0,1]
.
i
i
i
i
i
i
i
i
4.6. Projections 97
Figure 4.20. The effect of varying the distance of the near plane from the origin. The
distance f
n
is kept constant at 100. As the near plane becomes closer to the origin,
points nearer the far plane use a smaller range of the normalized device coordinate depth
space. This has the effect of making the Z-buffer less accurate at greater distances.
Further Reading and Resources
One of the best books for building up one’s intuition about matrices in
a painless fashion is Farin and Hansford’s The Geometry Toolb ox [333].
Another useful work is Lengyel’s Mathematics for 3D Game Progr amming
and Computer Graphics [761]. For a different perspective, many computer
graphics texts, such as Hearn and Baker [516], Shirley [1172], Watt and
Watt [1330], and the two books by Foley et al. [348, 349], also cover matrix
basics. The Graphics Gems series [36, 405, 522, 667, 982] presents various
transform-related algorithms and has code available online for many of
these. Golub and Van Loan’s Matrix Computations [419] is the place to
start for a serious study of matrix techniques in general. See: http://www.
realtimerendering.com for code for many different transforms, including
quaternions. More on skeleton-subspace deformation/vertex blending and
shape interpolation can be read in Lewis et al.’s SIGGRAPH paper [770].
Hart et al. [507] and Hanson [498] provide visualizations of quaternions.
Pletinckx [1019] and Schlag [1126] present different ways of interpolating
smoothly between a set of quaternions. Vlachos and Isidoro [1305] derive
formulae for C
2
interpolation of quaternions. Related to quaternion inter-
polation is the problem of computing a consistent coordinate system along
a curve. This is treated by Dougan [276].
Alexa [16] and Lazarus & Verroust [743] present surveys on many dif-
ferent morphing techniques.
..................Content has been hidden....................

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