cs5500 computer graphics april 23, 2007. today’s topic details of the front-end of the 3d...
Post on 18-Jan-2018
221 Views
Preview:
DESCRIPTION
TRANSCRIPT
CS5500 Computer GraphicsApril 23, 2007
Today’s Topic• Details of the front-end of the 3D
pipeline:– How to construct the viewing matrix?– How to construct the projection matrix?
• References:– [Ed Angel] Sections 5.3.3, 5.5.1, 5.9.– McMillan’s lecture slideshttp://www.unc.edu/courses/2003spring/comp/236/001/handouts.html
Two Tasks for Today• Deriving the viewing matrix
– e.g., For gluLookAt()• Deriving the projection matrix
– e.g., for glFrustum()
Specifying the View• Eye position• Look-at point• Up direction• Remember gluLookAt(eye, center, up)?• Note that the up vector may not be
orthogonal to the viewing direction (i.e., from eye to look-at)
Defining the Eye Space• We have two vectors: viewing direction and
up vector. Can we set up the three basis vectors for the eye space?
• v: viewing direction – The easy one = (look_at – eye)
• r: right vector– Orthogonal to both v and the up vector
• u: almost like up vector, except:– Orthogonal to both v and r
Inverse = Transpose• For an orthonormal matrix, its inverse
matrix is its transpose.
vur
vurM
vurM
133
33
100010001
Task #2 for Today• Deriving the viewing matrix
– e.g., For gluLookAt()• Deriving the projection matrix
– e.g., for glFrustum()
Simple PerspectiveConsider a simple perspective with the COP at
the origin, the near clipping plane at z = -1, and a 90 degree field of view determined by the planes
x = z, y = z
Simple Perspective
• After division by w,• Sometimes, we write is as:
10100000000100001
0 zyx
z
yx
x’ =zx y’ =
zy
10100000000100001
0 zyx
w
ywxw
Perspective in OpenGL• glFrustum( left, right,
bottom, top, near, far )
• gluPerpective( FOV_vertical, aspect_ratio,
near, far )
Scaling & Translation in X,Y
• Find Sx, Sy, Tx, Ty, so that:– (left, bottom, near, 1) (-1, -1, -1, 1)– (right, top, near, 1) (1, 1, -1, 1)
010001000000
0100010000100001
10000100
0000
yy
xx
yy
xx
TSTS
TSTS
The Z Component• So far, we have ignored the Z
coordinate.• We want to convert Z so that the range
of [near, far] becomes [-1, 1]• Note that this is NOT a “uniform”
scaling. We will see why after a few slides.
Now let’s look at the Z more carefully…
Range of Z• If Z = near, what is Z’?
-1• If Z = far, what is Z’?
1• Does Z’ change linearly with Z?
– No!– Let a= b=– Z’ = Zw / w = (a*Z+b) / Z = a + b/Z
nearfarnearfar
nearfarnearfar
2
Why Not Linear?• To make it linear, we will have to make
WZ’ = a*Z2 + bZ (so that Z’ = WZ’/W = a*Z + b)
• But that’s impossible with the 4x4 perspective matrix…
Z Resolution• Since screen Z’ is expressed in the form
of a+b/Z, most of the Z resolution is used up by the Z’s closer to the near plane.
• So, what does this mean?• You should NOT set zNear to be very
close to the eye position.
Now, some more math…
Transformation of Normals• Transformation does not necessarily
preserve the normal vectors.– If a.b=0, does T(a).T(b)=0 also?
• For example: what happen if we scale (X, Y) by (0.5, 1.0) in a 2D image?
We shouldn’t transform the two end points of a normal vector.
What we should do is to transform (three points of) the plane first, then find its normal.
What does that mean in math?
(See Appendix F of the OpenGL red book.)
Transformation of Normals• (Foley/vanDam pages 216-217)
– NT.P = 0 but is (MN)T.MP=0? Not always!!– Let (QN)T.MP=0 (i.e., transform P first, then try
to find its normal)– NTQTMP=0– So QTM=I QT= M-1 or Q=(M-1)T
• Special case when M-1=MT
– If M consists of only the composition of rotation, translation, and uniform scaling.
– Q=M
top related