University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections IV Week 4, Fri Feb 1 http://www.ugrad.cs.ubc.ca/~cs314/Vjan2008
News • extra TA office hours in lab next week to answer questions • Mon 1-3 • Tue 2-4 • Wed 1-3 • reminder • Wed 2/6: Homework 1 due 1pm sharp • Wed 2/6: Project 1 due 6pm. 2
Review: View Volumes • specifies field-of-view, used for clipping • restricts domain of z stored for visibility test orthographic view volume perspective view volume orthographic view volume perspective view volume y=top y=top x=left x=left y y z x=right z VCS y=bottom z=-near x VCS z=-far z=-far x y=bottom x=right z=-near 3
Review: Understanding Z • z axis flip changes coord system handedness • RHS before projection (eye/view coords) • LHS after projection (clip, norm device coords) VCS NDCS y=top y (1,1,1) x=left y z (-1,-1,-1) z x x=right x z=-far y=bottom z=-near 4
Review: Projection Normalization • warp perspective view volume to orthogonal view volume • render all scenes with orthographic projection! • aka perspective warp x x z= α z=d z=d z=0 5
Review: Projective Rendering Pipeline object world viewing O2W W2V V2C O2W W2V V2C VCS VCS OCS WCS OCS WCS projection projection modeling viewing modeling viewing transformation transformation transformation transformation transformation transformation clipping C2N C2N CCS CCS OCS - object/model coordinate system perspective perspective WCS - world coordinate system normalized divide divide device VCS - viewing/camera/eye coordinate N2D N2D system NDCS NDCS viewport viewport CCS - clipping coordinate system transformation transformation NDCS - normalized device coordinate device system DCS DCS DCS - device/display/screen coordinate 6 system
Review: Separate Warp From Homogenization normalized clipping viewing device V2C C2N V2C CCS C2N VCS CCS VCS NDCS NDCS projection projection perspective perspective transformation transformation division division alter w alter w / w / w • warp requires only standard matrix multiply • distort such that orthographic projection of distorted objects is desired persp projection • w is changed • clip after warp, before divide • division by w: homogenization 7
Reading for Viewing • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap Viewing • RB rest of App Homogeneous Coords 8
Reading for Next Time • RB Chap Color • FCG Sections 3.2-3.3 • FCG Chap 20 Color • FCG Chap 21.2.2 Visual Perception (Color) 9
Projective Rendering Pipeline object world viewing O2W W2V V2C O2W W2V V2C VCS VCS OCS WCS OCS WCS projection projection modeling viewing modeling viewing transformation transformation transformation transformation transformation transformation clipping C2N C2N CCS CCS OCS - object/model coordinate system perspective perspective WCS - world coordinate system normalized divide divide device VCS - viewing/camera/eye coordinate N2D N2D system NDCS NDCS viewport viewport CCS - clipping coordinate system transformation transformation NDCS - normalized device coordinate device system DCS DCS DCS - device/display/screen coordinate 10 system
NDC to Device Transformation • map from NDC to pixel coordinates on display • NDC range is x = -1...1, y = -1...1, z = -1...1 • typical display range: x = 0...500, y = 0...300 • maximum is size of actual screen • z range max and default is (0, 1), use later for visibility glViewport(0,0,w,h); glDepthRange(0,1); // depth = 1 by default 0 500 x x y y 0 y y -1 viewport viewport x x NDC NDC 1 1 -1 300 11
Origin Location • yet more (possibly confusing) conventions • OpenGL origin: lower left • most window systems origin: upper left • then must reflect in y • when interpreting mouse position, have to flip your y coordinates 0 500 x x y y 0 y y -1 viewport viewport x x NDC NDC 1 1 -1 300 12
N2D Transformation • general formulation • reflect in y for upper vs. lower left origin • scale by width, height, depth • translate by width/2, height/2, depth/2 • FCG includes additional translation for pixel centers at (.5, .5) instead of (0,0) 0 500 x x y y 0 y y height -1 viewport viewport x x NDC NDC 1 width 1 -1 13 300
N2D Transformation � width � 1 � � width � � width ( x N + 1) � 1 � 1 0 0 0 0 0 � � � � � � � � � � � � x D 1 0 0 0 x N 2 2 2 2 � � � � � � � � � � � � height � 1 height height ( � y N + 1) � 1 y D 0 � 1 0 0 y N 0 1 0 0 0 0 � � � � � � � � � � � � = = 2 2 2 2 � � � � � � � z D � � 0 0 1 0 � � z N � depth depth depth ( z N + 1) � � � � � � � � 0 0 1 0 0 0 � � � � 1 0 0 0 1 1 � � � � � � 2 2 2 � � � � � � � 0 0 0 1 � � 0 0 0 1 � � 1 � � � � � � � 0 500 x x y y 0 y y height -1 viewport viewport x x NDC NDC 1 width 1 -1 14 300
Device vs. Screen Coordinates • viewport/window location wrt actual display not available within OpenGL • usually don’t care • use relative information when handling mouse events, not absolute coordinates • could get actual display height/width, window offsets from OS • loose use of terms: device, display, window, screen... 0 1024 x x 0 y y 0 500 x y offset x 0 y y display x offset viewport viewport viewport viewport height 300 display display 768 15 display width
Projective Rendering Pipeline glVertex3f(x,y,z) glVertex3f(x,y,z) object world viewing O2W W2V V2C alter w alter w O2W W2V V2C WCS VCS WCS VCS OCS OCS glFrustum(...) glFrustum (...) projection projection modeling viewing modeling viewing transformation transformation transformation transformation transformation transformation clipping glTranslatef(x,y,z) (x,y,z) gluLookAt(...) (...) glTranslatef gluLookAt C2N C2N / w / w CCS CCS glRotatef(a,x,y,z) ) glRotatef(a,x,y,z perspective perspective .... .... normalized division division OCS - object coordinate system glutInitWindowSize(w,h) (w,h) device glutInitWindowSize N2D N2D WCS - world coordinate system glViewport(x,y,a,b) (x,y,a,b) glViewport NDCS NDCS viewport viewport VCS - viewing coordinate system transformation transformation CCS - clipping coordinate system device DCS DCS NDCS - normalized device coordinate system 16 DCS - device coordinate system
Coordinate Systems viewing (4-space, W=1) clipping projection (4-space parallelepiped, matrix with COP moved backwards to infinity normalized device divide by w (3-space parallelepiped) device scale & (3-space translate parallelipiped) framebuffer 17
Perspective To NDCS Derivation VCS NDCS y=top x=left y (1,1,1) y z (-1,-1,-1) x z y=bottom z=-near z=-far x x=right 18
Perspective Derivation � � � � � � x ' 1 0 0 0 x � � � � � � simple example earlier: simple example earlier: y ' 0 1 0 0 y � � � � � � = � z ' � � 0 0 1 0 � � z � � � � � � � w ' 0 0 1/ d 0 1 � � � � � � complete: shear, scale, projection-normalization complete: shear, scale, projection-normalization � � � � � � x ' E 0 A 0 x � � � � � � y ' F 1 B 0 y � � � � � � = � z ' � � 0 0 C D � � z � � � � � � � w ' 0 0 � 1 0 1 � � � � � � 19
Perspective Derivation � � � � � � x ' 1 0 0 0 x � � � � � � earlier: earlier: y ' 0 1 0 0 y � � � � � � = � z ' � � 0 0 1 0 � � z � � � � � � � w ' 0 0 1/ d 0 1 � � � � � � complete: shear, scale, projection-normalization complete: shear, scale, projection-normalization � � � � � � x ' E 0 A 0 x � � � � � � y ' F 1 B 0 y � � � � � � = � z ' � � 0 0 C D � � z � � � � � � � w ' 0 0 � 1 0 1 � � � � � � 20
Perspective Derivation � � � � � � x ' 1 0 0 0 x earlier: earlier: � � � � � � y ' 0 1 0 0 y � � � � � � = � z ' � � 0 0 1 0 � � z � � � � � � � w ' 0 0 1/ d 0 1 � � � � � � complete: shear, scale, projection-normalization complete: shear, scale, projection-normalization � � � � � � x ' E 0 A 0 x � � � � � � y ' F 1 B 0 y � � � � � � = � z ' � � 0 0 C D � � z � � � � � � � w ' 0 0 � 1 0 1 � � � � � � 21
Recommend
More recommend