University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Viewing/Projection V, Vision/Color Week 5, Mon Feb 1 http://www.ugrad.cs.ubc.ca/~cs314/Vjan2010
Department of Computer Science Undergraduate Events RIM Info Session Events this week Date: Thurs., Feb 4 Resume Editing Drop-In Session Time: 5:30 – 7 pm Date: Mon., Feb 1 Location: DMP 110 Time: 11 am – 2 pm Events next week Location: Rm 255, ICICS/CS Finding a Summer Job or EADS Info Session Internship Info Session Date: Mon., Feb 1 Date: Wed., Feb 10 Time: 3:30 – 5:30 pm Time: 12 pm Location: CEME 1202 Location: X836 Job Interview Practice Session Masters of Digital Media (for non-coop students) Program Info Session Date: Tues., Feb 2 Date: Thurs., Feb 11 Time: 11 am – 1 pm Time: 12:30 – 1:30 pm Location: Rm 206, ICICS/CS Location: DMP 201 2
Project 1 Grading News • don’t forget to show up 5 min before your slot • see news item on top of course page for signup sheet scan • if you have not signed up or need to change your time, contact shailen AT cs.ubc.ca • you will lose marks if we have to hunt you down! 3
Review: Perspective Warp/Predistortion • perspective viewing frustum predistorted to cube • orthographic rendering of warped objects in cube produces same image as perspective rendering of original frustum x x 4
Review: Separate Warp and Homogenize 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 shows desired perspective projection • w is changed • clip after warp, before divide • division by w: homogenization 5
Review: Perspective to NDCS Derivation • shear • scale • projection-normalization VCS NDCS y=top (1,1,1) z x=left y y z (-1,-1,-1) x y=bottom z=-near z=-far x 6 x=right
Review: N2D Transformation NDCS DCS 0 500 x x y y 0 y y height -1 viewport viewport x x NDC NDC 1 width 1 -1 300 7
Review: Projective Rendering Pipeline glVertex3f(x,y,z) glVertex3f(x,y,z) object world viewing O2W W2V V2C alter w O2W W2V V2C alter w VCS WCS VCS WCS 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 8 DCS - device coordinate system
Perspective Example � 2 n r + l � 0 0 � � r � l r � l view volume � � 2 n t + b • left = -1, right = 1 0 0 � � t � b t � b • bot = -1, top = 1 � � � ( f + n ) � 2 fn • near = 1, far = 4 � � 0 0 f � n f � n � � � � 0 0 � 1 0 � � � � 1 0 0 0 � � 0 1 0 0 � � � 0 0 � 5/3 � 8/3 � � � 0 0 � 1 0 � � 9
Perspective Example view volume tracks in VCS: left = -1, right = 1 left x=-1, y=-1 bot = -1, top = 1 right x=1, y=-1 near = 1, far = 4 x=1 x=-1 1 ymax-1 z=-4 real midpoint -1 z=-1 1 xmax-1 -1 0 -1 0 x NDCS DCS (z not shown) (z not shown) z VCS top view 10
Perspective Example � � � � � � 1 1 1 � � � � � � � 1 1 � 1 � � � � � � = � � � � � � � 5 z VCS /3 � 8/3 � 5/3 � 8/3 z VCS � � � � � � � z VCS � 1 1 � � � � � � x NDCS = � 1/ z VCS / w / w y NDCS = 1/ z VCS z NDCS = 5 8 3 + 3 z VCS 11
OpenGL Example object world viewing clipping O2W W2V V2C O2W W2V V2C CCS VCS CCS VCS OCS WCS OCS WCS projection projection modeling viewing modeling viewing transformation transformation transformation transformation transformation transformation CCS CCS glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 45, 1.0, 0.1, 200.0 ); VCS VCS glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); • transformations that glTranslatef( 0.0, 0.0, -5.0 ); WCS WCS are applied to object glPushMatrix() W2O W2O glTranslate( 4, 4, 0 ); first are specified OCS1 OCS1 glutSolidTeapot(1); last glPopMatrix(); W2O W2O glTranslate( 2, 2, 0); 12 OCS2 glutSolidTeapot(1); OCS2
Viewing: More Camera Motion 13
Fly "Through The Lens": Roll/Pitch/Yaw 14
Viewing: Incremental Relative Motion • how to move relative to current camera coordinate system? • what you see in the window • computation in coordinate system used to draw previous frame is simple: • incremental change I to current C • at time k, want p' = I k I k-1 I k-2 I k-3 ... I 5 I 4 I 3 I 2 I 1 Cp • each time we just want to premultiply by new matrix • p’=ICp • but we know that OpenGL only supports postmultiply by new matrix • p’=CIp 15
Viewing: Incremental Relative Motion • sneaky trick: OpenGL modelview matrix has the info we want! • dump out modelview matrix with glGetDoublev() • C = current camera coordinate matrix • wipe the matrix stack with glIdentity() • apply incremental update matrix I • apply current camera coord matrix C • must leave the modelview matrix unchanged by object transformations after your display call • use push/pop • using OpenGL for storage and calculation • querying pipeline is expensive • but safe to do just once per frame 16
Caution: OpenGL Matrix Storage • OpenGL internal matrix storage is columnwise, not rowwise a e i m b f j n c g k o d h l p • opposite of standard C/C++/Java convention • possibly confusing if you look at the matrix from glGetDoublev()! 17
Viewing: Virtual Trackball • interface for spinning objects around • drag mouse to control rotation of view volume • orbit/spin metaphor • vs. flying/driving • rolling glass trackball • center at screen origin, surrounds world • hemisphere “sticks up” in z, out of screen • rotate ball = spin world 18
Virtual Trackball • know screen click: (x, 0, z) • want to infer point on trackball: (x,y,z) • ball is unit sphere, so ||x, y, z|| = 1.0 • solve for y eye image plane 19
Trackball Rotation • correspondence: • moving point on plane from (x, 0, z) to (a, 0, c) • moving point on ball from p 1 =(x, y, z) to p 2 =(a, b, c) • correspondence: • translating mouse from p 1 (mouse down) to p 2 (mouse up) • rotating about the axis n = p 1 x p 2 20
Trackball Computation • user defines two points • place where first clicked p 1 = (x, y, z) • place where released p 2 = (a, b, c) • create plane from vectors between points, origin • axis of rotation is plane normal: cross product • ( p 1 - o ) x ( p 2 - o ): p 1 x p 2 if origin = (0,0,0) • amount of rotation depends on angle between lines • p 1 • p 2 = | p 1 | | p 2 | cos θ • |p 1 x p 2 | = | p 1 | | p 2 | sin θ • compute rotation matrix, use to rotate world 21
Picking 22
Reading • Red Book • Selection and Feedback Chapter • all • Now That You Know Chapter • only Object Selection Using the Back Buffer 23
Interactive Object Selection • move cursor over object, click • how to decide what is below? • inverse of rendering pipeline flow • from pixel back up to object • ambiguity • many 3D world objects map to same 2D point • four common approaches • manual ray intersection • bounding extents • backbuffer color coding • selection region with hit list 24
Manual Ray Intersection • do all computation at application level • map selection point to a ray • intersect ray with all objects in scene. • advantages • no library dependence y • disadvantages VCS • difficult to program x • slow: work to do depends on total number and complexity of objects in scene 25
Bounding Extents • keep track of axis-aligned bounding rectangles • advantages • conceptually simple • easy to keep track of boxes in world space 26
Bounding Extents • disadvantages • low precision • must keep track of object-rectangle relationship • extensions • do more sophisticated bound bookkeeping • first level: box check. • second level: object check 27
Backbuffer Color Coding • use backbuffer for picking • create image as computational entity • never displayed to user • redraw all objects in backbuffer • turn off shading calculations • set unique color for each pickable object • store in table • read back pixel at cursor location • check against table 28
Recommend
More recommend