
Viewing and Projection Sheelagh Carpendale Camera metaphor 1. choose camera position 2. set up and organize objects 3. choose a lens 4. take the picture 1 View Volumes • what gets into the scene perspective view volume orthographic view volume y=top y=top x=left x=left y y z z x=right VCS VCS y=bottom z=-near x x z=-far z=-far x=right y=bottom z=-near Projective Rendering Pipeline object world viewing/camera OCS WCS VCS Projection matrix modeling viewing projection transformation transformation transformation clipping CCS Model view matrix clipping normalized OCS - object coordinate system device WCS - world coordinate system NDCS VCS - viewing coordinate system / w CCS - clipping coordinate system Viewport matrix NDCS - normalized device coordinate system viewport transformation DCS - device coordinate system device DCS 2 Viewing Transformation object world viewing OCS WCS VCS modeling viewing transformation transformation M mod M cam OpenGL ModelView matrix Arbitrary Viewing Position • General situation for camera • Keep view frame unchanged • Map object with the inverse of the frame transformation y v z n eye -n z u 3 Deriving the model view matrix • eye point P = (x, y, z, 1) • viewplane normal n = (nx, ny, nz, 0) • up vector v = (vx, vy, vz, 0) • u = v x n • unit vectors u’, v’, n’ y v z eye n -n z u Model view matrix details • Rotation matrix: M éu'x u'y u'z 0ù ê ú êv'x v'y v'z 0ú • Object rotations: R = M-1 = MT = ên' n' n' 0ú ê x y z ú ë0 0 0 1û é0 0 0 -xù • Translation T = ê ú ê0 0 0 -yú ê0 0 0 -zú ê ú • V = RT ë0 0 0 0 û 4 Arbitrary Viewing Position • rotate/translate/scale not intuitive • convenient formulation • eye point, lookat direction, up vector Look-at function • Input • p: eye point • q: look at point • v’: approximation of up vector • n = p – q • v = v’ – (v’. n) .n • u = v x n • Normalize • OpenGL utility function gluLookAt(ex, ey, ez, lx, ly, lz, ux, uy, uz) 5 Viewing Transformation • OpenGL • gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz) usually use as follows: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz) // now ok to do model transformations Field-of-View Formulation • FOV in one direction + aspect ratio (w/h) • determines FOV in other direction • also set near, far (reasonably intuitive) x w Frustum fovx/2 h a -z fovy/2 z=-n z=-f 6 Viewing and Projection • Standard situation • camera at origin, pointing in –z direction, orthogonal projection • Map camera to a general situation Or • Map all objects in to the standard situation of camera Canonical view volume • transform an arbitrary orthogonal to • canonical view volume x = +/- 1, y = +/- 1, z = +/- 1 • translate centre • scale • matrix? 7 Orthographic Derivation • scale, translate, reflect for new coord sys VCS NDCS y=top y x=left (1,1,1) y z z (-1,-1,-1) x=right x x z=-far y=bottom z=-near Orthographic Derivation y'= a × y + b y = top ® y'= 1 y = bot ® y'= -1 solving for a and b gives: 2 - (top + bot) a = b = top - bot top - bot same idea for right/left, far/near 8 Orthographic Derivation • scale, translate, reflect for new coord sys é 2 right +left ù 0 0 - ê - - ú êright left right left ú 2 top + bot ê 0 0 - ú P'= ê top -bot top - bot úP ê - 2 far + nearú ê 0 0 - ú ê far - near far - nearú ëê 0 0 0 1 ûú Perspective normalization • simple case • COP at origin • projection plane at z = -1 x = +/- 1, y = +/- 1 • matrix? 9 Projective Transformations • transformation of space • center of projection moves to infinity • viewing frustum transformed into a parallelepiped x x Frustum -z -z Projective Transformations • can express as homogeneous 4x4 matrices! • 16 matrix entries • multiples of same matrix all describe same transformation • 15 degrees of freedom • mapping of 5 points uniquely determines transformation 10 Projective Transformations • determining the matrix representation • need to observe 5 points in general position, e.g. • [left,0,0,1] T®[1,0,0,1] T • [0,top,0,1] T®[0,1,0,1] T • [0,0,-f,1] T®[0,0,1,1] T • [0,0,-n,1]T®[0,0,0,1] T • [left*f/n,top*f/n,-f,1]T®[1,1,1,1] T • solve resulting equation system to obtain matrix Perspective Derivation VCS y=top NDCS x=left y (1,1,1) y z (-1,-1,-1) z x y=bottom z=-near x z=-far x=right 11 Normalized Device Coordinates left/right x =+/- 1, top/bottom y =+/- 1, near/far z =+/- 1 Camera coordinates NDC x x x=1 right Frustum -z z left x= -1 z= -1 z=1 z=-n z=-f Perspective Derivation é x ù é1 0 0 0ùéxù earlier: ê y ú ê0 1 0 0úêyú ê ú = ê úê ú ê z ú ê0 0 1 0úêzú ê ú ê úê ú ëz / dû ë0 0 1/ d 0ûë1û complete: shear, scale, projection-normalization éx'ù éE 0 A 0 ùéxù êy'ú ê0 F B 0 úêyú ê ú = ê úê ú êz'ú ê0 0 C Dúêzú ê ú ê úê ú ëh'û ë0 0 -1 0 ûë1û 12 Perspective Derivation • similarly for other 5 planes • 6 planes, 6 unknowns é 2n r + l ù ê 0 0 ú r - l r - l ê 2n t + b ú ê 0 0 ú ê t - b t - b ú ê - ( f + n) - 2 fn ú 0 0 ê f - n f - n ú ê ú ë 0 0 -1 0 û 13 Perspective Example view volume • left = -1, right = 1 • bot = -1, top = 1 • near = 1, far = 4 é 2n r + l ù 0 0 é1 0 0 0 ù êr - l r - l ú ê 2n t + b ú ê ú ê 0 0 ú ê0 1 0 0 ú ê t - b t - b ú ê - ( f + n) - 2 fnú ê - - ú 0 0 0 0 5/ 3 8/ 3 ê f - n f - n ú ê ú ê ú - ë 0 0 - 1 0 û ë0 0 1 0 û 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 z=-1 midpoint -1 -1 1 0 xmax-1 x -1 0 NDCS DCS (z not shown) (z not shown) z VCS top view 14 Viewport Transformation • generate pixel coordinates • map x, y from range –1…1 (normalized device coordinates) to pixel coordinates on the display • involves 2D scaling and translation y display x viewport Holbein the younger 1497-1543 First discussed by da Vinci as ‘Anamorphosis’ From Greek word meaning to transform 15 Holbein the younger 1497-1543 No record or any mention of this skull until 1873 Portrait of Prince Edward VI William Scrots 1546 16 Portrait of Prince Edward VI William Scrots 1546 17.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages17 Page
-
File Size-