cs5500 computer graphics april 23, 2007. today’s topic details of the front-end of the 3d...

25
CS5500 Computer Graphics April 23, 2007

Upload: doreen-sims

Post on 18-Jan-2018

220 views

Category:

Documents


0 download

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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