15-462 Computer Grphics I Lecture 5 Viewing nd Projection Sher Trnsformtion Cmer Positioning Simple Prllel Projections Simple Perspective Projections [Angel, Ch. 5.2-5.4] Jnury 30, 2003 [Red s Drem, Pixr, 1987] Frnk Pfenning Crnegie Mellon University http://www.cs.cmu.edu/~fp/courses/grphics/ Trnsformtion Mtrices in OpenGL Trnsformtion mtrices in OpenGl re vectors of 16 vlues (column-mjor mtrices) In gllodmtrixf(glflot *m); m = {m 1, m 2,..., m 16 } represents Some books trnspose ll mtrices! 01/30/2003 15-462 Grphics I 2 Pondering Trnsformtions Derive trnsformtion given some prmeters Choose prmeters crefully Consider geometric intuition, bsic trigonometry Compose trnsformtion from others Use trnsltions to nd from origin Test if mtrix describes some trnsformtion Determine ction on bsis vectors Mening of dot product nd cross product Sher Trnsformtions x-sher scles x proportionl to y Leves y nd z vlues fixed 01/30/2003 15-462 Grphics I 3 01/30/2003 15-462 Grphics I 4 Specifiction vi Angle cot(θ) = (x -x)/y x = x + y cot(θ) y = y z = z y Specifiction vi Rtios Sher in both x nd z direction Leve y fixed Slope α for x-sher, γ for z-sher Solve (x,y) (x,y ) y Yields θ x -x x 01/30/2003 15-462 Grphics I 5 01/30/2003 15-462 Grphics I 6 1
Composing Trnsformtions Every ffine trnsformtion is composition of rottions, sclings, nd trnsltions How do we compose these to form n x-sher? Exercise! Thinking in Frmes Action on frme determines ffine trnsfn. Frme given by bsis vectors nd origin xz-sher: preserve bsis vectors u x nd u z Move u y = [0 1 0 0] T to u v = [α 1 γ 0] T 01/30/2003 15-462 Grphics I 7 01/30/2003 15-462 Grphics I 8 Preservtion of Origin Preserve origin P 0 Outline Sher Trnsformtion Cmer Positioning Simple Prllel Projections Simple Perspective Projections Results comprise columns of the trnsfn. mtrix 01/30/2003 15-462 Grphics I 9 01/30/2003 15-462 Grphics I 10 Cmer in Modeling Coordintes Cmer position is identified with frme Either move nd rotte the objects Or move nd rotte the cmer Initilly, pointing in negtive z-direction Initilly, cmer t origin Moving Cmer nd World Frme Move world frme reltive to cmer frme gltrnsltef(0.0, 0.0, -d); moves world frme 01/30/2003 15-462 Grphics I 11 01/30/2003 15-462 Grphics I 12 2
Order of Viewing Trnsformtions Think of moving the world frme Viewing trnsfn. is inverse of object trnsfn. Order opposite to object trnsformtions glmtrixmode(gl_modelview); gllodidentity(); gltrnsltef(0.0, 0.0, -d); /*T*/ glrottef(-90.0, 0.0, 1.0, 0.0); /*R*/ The Look-At Function Convenient wy to position cmer glulookat(e x, e y, e z, x, y, z, p x, p y, p z ); e = eye point = t point p = up vector p e 01/30/2003 15-462 Grphics I 13 01/30/2003 15-462 Grphics I 14 Implementing the Look-At Function (1) Trnsform world frme to cmer frme Compose rottion R with trnsltion T W = T R (2) Invert W to obtin viewing trnsformtion V V = W -1 = (T R) -1 = R -1 T -1 Derive R, then T, then R -1 T -1 World Frme to Cmer Frme I Cmer points in negtive z direction n = ( e) / e is unit norml to R mps [0 0-1 0] T to [n x n y n z 0] T e p n 01/30/2003 15-462 Grphics I 15 01/30/2003 15-462 Grphics I 16 World Frme to Cmer Frme II R mps y to projection of p onto α = (p n) / n = p n v 0 = p α n v = v 0 / v 0 p World Frme to Cmer Frme III x is orthogonl to n nd v in u = n v (u, v, -n) is right-hnded p V 0 e α n u v e n 01/30/2003 15-462 Grphics I 17 01/30/2003 15-462 Grphics I 18 3
Summry of Rottion glulookat(e x, e y, e z, x, y, z, p x, p y, p z ); n = ( e) / e v = (p (p n) n) / p (p n) n u = n v World Frme to Cmer Frme IV Trnsltion of origin to e = [e x e y e z 1] T 01/30/2003 15-462 Grphics I 19 01/30/2003 15-462 Grphics I 20 Cmer Frme to World Frme V = W -1 = (T R) -1 = R -1 T -1 R is rottion, so R -1 = R T Putting it Together Clculte V = R -1 T -1 T is trnsltion, so T -1 negtes displcement This is different from book [Angel, Ch. 5.2.2] There, u, v, n re right-hnded (here: u, v, -n) 01/30/2003 15-462 Grphics I 21 01/30/2003 15-462 Grphics I 22 Other Viewing Functions Roll (bout z), pitch (bout x), yw (bout y) Outline Sher Trnsformtion Cmer Positioning Simple Prllel Projections Simple Perspective Projections Assignment 2 poses relted problem 01/30/2003 15-462 Grphics I 23 01/30/2003 15-462 Grphics I 24 4
Projection Mtrices Recll geometric pipeline Projection tkes 3D to 2D Projections re not invertible Projections lso described by mtrix Homogenous coordintes crucil Prllel nd perspective projections Orthogrphic Projections Prllel projection Projectors perpendiculr to projection plne Simple, but not relistic Used in blueprints (multiview projections) 01/30/2003 15-462 Grphics I 25 01/30/2003 15-462 Grphics I 26 Orthogrphic Projection Mtrix Project onto z = 0 x p = x, y p = y, z p = 0 In homogenous coordintes Perspective Perspective chrcterized by foreshortening More distnt objects pper smller Prllel lines pper to converge Rudimentry perspective in cve drwings 01/30/2003 15-462 Grphics I 27 01/30/2003 15-462 Grphics I 28 Discovery of Perspective Middle Ages Foundtion in geometry (Euclid) Murl from Pompeii Art in the service of religion Perspective bndoned or forgotten Ottonin mnuscript, c. 1000 01/30/2003 15-462 Grphics I 29 01/30/2003 15-462 Grphics I 30 5
Renissnce Rediscovery, systemtic study of perspective Filippo Brunelleschi Florence, 1415 Perspective Viewing Mthemticlly More on history of perspective (icscis) http://www.cyberus.c/~icscis/icscis.htm y/z = y p /d so y p = y/(z/d) Note this is non-liner! 01/30/2003 15-462 Grphics I 31 01/30/2003 15-462 Grphics I 32 Exploiting the 4 th Dimension Perspective projection is not ffine: Perspective Projection Mtrix Represent multiple of point hs no solution for M Ide: represent point [x y z 1] T by line in 4D Solve for rbitrry w 0 with 01/30/2003 15-462 Grphics I 33 01/30/2003 15-462 Grphics I 34 Perspective Division Normlize [x y z w] T to [(x/w) (y/w) (z/w) 1] T Perform perspective division fter projection Prllel Viewing in OpenGL glortho(xmin, xmx, ymin, ymx, ner, fr) Projection in OpenGL is more complex z min = ner, z mx = fr 01/30/2003 15-462 Grphics I 35 01/30/2003 15-462 Grphics I 36 6
Perspective Viewing in OpenGL Two interfces: glfrustum nd gluperspective glfrustum(xmin, xmx, ymin, ymx, ner, fr); Field of View Interfce gluperspective(fovy, spect, ner, fr); ner nd fr s before Fovy specifies field of view s height (y) ngle z min = ner, z mx = fr 01/30/2003 15-462 Grphics I 37 01/30/2003 15-462 Grphics I 38 Mtrices for Projections in OpenGL Next lecture: Use sher for predistortion Use projections for fke shdows Other kinds of projections Announcements Assignment 1 due Thursdy midnight (100 pts) Lte policy Up to 3 dys ny time, no penlty No other lte hnd-in permitted Assignment 2 out Thursdy (1 week, 50 pts) Extr credit policy Up to 20% of ssignment vlue Recorded seprtely Weighed for borderline cses Remember: no collbortion on ssignments! 01/30/2003 15-462 Grphics I 39 01/30/2003 15-462 Grphics I 40 Looking Ahed Lighting nd shding Video: Red s Drem, John Lsseter, Pixr,1987 http://www.pixr.com/shorts/rd/index.html 01/30/2003 15-462 Grphics I 41 7