cs5500 computer graphics april 23, 2007. today’s topic details of the front-end of the 3d...
DESCRIPTION
Two Tasks for Today Deriving the viewing matrix –e.g., For gluLookAt() Deriving the projection matrix –e.g., for glFrustum()TRANSCRIPT
![Page 1: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/1.jpg)
CS5500 Computer GraphicsApril 23, 2007
![Page 2: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/2.jpg)
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
![Page 3: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/3.jpg)
Two Tasks for Today• Deriving the viewing matrix
– e.g., For gluLookAt()• Deriving the projection matrix
– e.g., for glFrustum()
![Page 4: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/4.jpg)
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)
![Page 5: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/5.jpg)
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
![Page 6: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/6.jpg)
![Page 7: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/7.jpg)
Inverse = Transpose• For an orthonormal matrix, its inverse
matrix is its transpose.
vur
vurM
vurM
133
33
100010001
![Page 8: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/8.jpg)
![Page 9: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/9.jpg)
Task #2 for Today• Deriving the viewing matrix
– e.g., For gluLookAt()• Deriving the projection matrix
– e.g., for glFrustum()
![Page 10: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/10.jpg)
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
![Page 11: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/11.jpg)
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
![Page 12: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/12.jpg)
Perspective in OpenGL• glFrustum( left, right,
bottom, top, near, far )
• gluPerpective( FOV_vertical, aspect_ratio,
near, far )
![Page 13: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/13.jpg)
![Page 14: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/14.jpg)
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
![Page 15: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/15.jpg)
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.
![Page 16: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/16.jpg)
![Page 17: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/17.jpg)
![Page 18: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/18.jpg)
Now let’s look at the Z more carefully…
![Page 19: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/19.jpg)
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
![Page 20: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/20.jpg)
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…
![Page 21: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/21.jpg)
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.
![Page 22: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/22.jpg)
Now, some more math…
![Page 23: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/23.jpg)
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?
![Page 24: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/24.jpg)
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.)
![Page 25: CS5500 Computer Graphics April 23, 2007. Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct](https://reader035.vdocument.in/reader035/viewer/2022062317/5a4d1b407f8b9ab0599a0b60/html5/thumbnails/25.jpg)
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