Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 CS5500 Computer Graphics April 23, 2007

2 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 slides http://www.unc.edu/courses/2003spring/comp/236/001/handouts.html

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

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

5 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

6

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

8

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

10 Simple Perspective Consider 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

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

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

13

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

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

16

17

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

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

20 Why Not Linear? To make it linear, we will have to make WZ’ = a*Z 2 + bZ (so that Z’ = WZ’/W = a*Z + b) But that’s impossible with the 4x4 perspective matrix…

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

22 Now, some more math…

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

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

25 Transformation of Normals (Foley/vanDam pages 216-217) –N T.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) –N T Q T MP=0 –So Q T M=I  Q T = M -1 or Q=(M -1 ) T Special case when M -1 =M T –If M consists of only the composition of rotation, translation, and uniform scaling. –Q=M


Download ppt "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."

Similar presentations


Ads by Google