Viewing and Projection Sheelagh Carpendale Camera metaphor. choose camera position 2. set up and organie objects 3. choose a lens 4. take the picture
View Volumes what gets into the scene perspective view volume VCS =left =top =bottom =-near =right orthographic view volume =left VCS =-far =bottom =top =right =-near =-far Projective Rendering Pipeline object OCS modeling world WCS OCS - object coordinate sstem WCS - world coordinate sstem VCS - viewing coordinate sstem CCS - clipping coordinate sstem NDCS - normalied device coordinate sstem DCS - device coordinate sstem viewing/camera VCS viewing Model view matri Projection matri projection clipping / w viewport clipping CCS normalied device NDCS Viewport matri device DCS 2
Viewing Transformation object world viewing OCS modeling M mod WCS viewing M cam OpenGL ModelView matri VCS Arbitrar Viewing Position General situation for camera Keep view frame unchanged Map object with the inverse of the frame v n ee -n u 3
Deriving the model view matri ee point P = (,,, ) viewplane normal n = (n, n, n, ) up vector v = (v, v, v, ) u = v n unit vectors u, v, n v n ee -n u Model view matri details Rotation matri: M Object rotations: R = M- = MT = Ø Œ Œ Œ Œ º u' u' u' v' v' v' n' n' n' ø œ œ œ œ ß Translation T = V = RT Ø Œ Œ Œ Œ º -ø - œ œ -œ œ ß 4
Arbitrar Viewing Position rotate/translate/scale not intuitive convenient formulation ee point, lookat direction, up vector Look-at function Input p: ee point q: look at point v : approimation of up vector n = p q v = v (v. n).n u = v n Normalie OpenGL utilit function glulookat(e, e, e, l, l, l, u, u, u) 5
Viewing Transformation OpenGL glulookat(e,e,e,l,l,l,u,u,u) usuall use as follows: glmatrimode(gl_modelview); glloadidentit(); glulookat(e,e,e,l,l,l,u,u,u) // now ok to do model s Field-of-View Formulation FOV in one direction + aspect ratio (w/h) determines FOV in other direction also set near, far (reasonabl intuitive) w a Frustum - fov/2 fov/2 h =-n =-f 6
Viewing and Projection Standard situation camera at origin, pointing in 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 arbitrar orthogonal to canonical view volume = +/-, = +/-, = +/- translate centre scale matri? 7
Orthographic Derivation scale, translate, reflect for new coord ss VCS NDCS =left =top =right (-,-,-) (,,) =bottom =-near =-far Orthographic Derivation ' = a + b solving for a and b gives: a = 2 top bot = top = bot b = ' = ' = ( top + bot) top bot same idea for right/left, far/near 8
Orthographic Derivation scale, translate, reflect for new coord ss 2 right left P = ' 2 top bot 2 far near right + left right left top + bot top bot P far + near far near Perspective normaliation simple case COP at origin projection plane at = - = +/-, = +/- matri? 9
Projective Transformations of space center of projection moves to infinit viewing frustum transformed into a parallelepiped Frustum - - Projective Transformations can epress as homogeneous 44 matrices! 6 matri entries multiples of same matri all describe same 5 degrees of freedom mapping of 5 points uniquel determines
Projective Transformations determining the matri representation need to observe 5 points in general position, e.g. [left,,,] T [,,,] T [,top,,] T [,,,] T [,,-f,] T [,,,] T [,,-n,] T [,,,] T [left*f/n,top*f/n,-f,] T [,,,] T solve resulting equation sstem to obtain matri Perspective Derivation VCS =top NDCS =left (,,) =bottom =-near =right =-far (-,-,-)
2 Normalied Device Coordinates left/right =+/-, top/bottom =+/-, near/far =+/- - Frustum Frustum = =-n = =-f right right left left = = - = = = = Camera coordinates Camera coordinates NDC NDC = = - Perspective Derivation earlier: earlier: complete: shear, scale, projection complete: shear, scale, projection-normaliation normaliation = / / d d = ' ' ' ' D C B F A E h
3 Perspective Derivation similarl for other 5 planes 6 planes, 6 unknowns + + + 2 ) ( 2 2 n f fn n f n f b t b t b t n l r l r l r n
Perspective Eample view volume left = -, right = bot = -, top = near =, far = 4 2n r l 2n t b r + l r l t + b t ( b f + n) f n 2 fn f n 5/ 3 8/ 3 Perspective Eample tracks in VCS: left =-, =- right =, =- view volume left = -, right = bot = -, top = near =, far = 4 =- = ma- =-4 =- real midpoint - - - NDCS DCS ma- VCS top view ( not shown) ( not shown) 4
Viewport Transformation generate piel coordinates map, from range (normalied device coordinates) to piel coordinates on the displa involves 2D scaling and translation displa viewport Holbein the ounger 497-543 First discussed b da Vinci as Anamorphosis From Greek word meaning to transform 5
Holbein the ounger 497-543 No record or an mention of this skull until 873 Portrait of Prince Edward VI William Scrots 546 6
Portrait of Prince Edward VI William Scrots 546 7