Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS5500 Computer Graphics April 24, 2006.

Similar presentations


Presentation on theme: "CS5500 Computer Graphics April 24, 2006."— Presentation transcript:

1 CS5500 Computer Graphics April 24, 2006

2 About the graphics pipeline assignment (part 1 of 3)…

3 Major Components Data structures for: Transformation Lighting
Points, vectors, matrices Lines and polygons (or just triangles) Frame buffer and textures Transformation Lighting Clipping & Projection Rasterization & texture mapping

4 Don’t Reinvent the Wheel
A few useful 3D vector and matrix code: Or borrow one from your friends, or find a good one from the Internet.

5 Today’s Topic Details of the front-end of the 3D pipeline: References:
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 slides

6 Two Tasks for Today Deriving the viewing matrix
e.g., For gluLookAt() Deriving the projection matrix e.g., for glFrustum()

7 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)

8 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

9 Viewing Transformation
Let M be the viewing transformation matrix. (1,0,0,0) = M * r (0,1,0,0) = M * u (0,0,-1,0) = M * v (0,0,0,1) = M * eye In summary:

10 Inverse = Transpose For an orthonormal matrix, its inverse matrix is its transpose.

11

12 Task #2 for Today Deriving the viewing matrix
e.g., For gluLookAt() Deriving the projection matrix e.g., for glFrustum()

13 Simple Perspective After division by w, Sometimes, we write is as:
x’ = y’ =

14 Perspective in OpenGL glFrustum( left, right, bottom, top, near, far )
gluPerpective( FOV_vertical, aspect_ratio, near, far )

15

16 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)

17 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.

18

19

20 Now let’s look at the Z more carefully…

21 Range of Z If Z = near, what is Z’? If Z = far, 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

22 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…

23 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.

24 Now, some more math…

25 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?

26 (See Appendix F of the OpenGL red book.)
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.)

27 Transformation of Normals
(Foley/vanDam pages ) 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


Download ppt "CS5500 Computer Graphics April 24, 2006."

Similar presentations


Ads by Google