University of British Columbia Review: Camera Motion Review: World to View Coordinates CPSC 314 Computer Graphics • rotate/translate/scale difficult to control • translate eye to origin Jan-Apr 2008 • arbitrary viewing position • rotate view vector ( lookat – eye ) to w axis Tamara Munzner • eye point, gaze/lookat direction, up vector • rotate around w to bring up into vw -plane Projections I y y lookat lookat Viewing/Projections I x Pref x Pref WCS WCS view view v VCS up up u u u u e z z � � • � Week 3, Fri Jan 25 x y z eye eye � � v v v v e � • x y z M � � = w 2 v w w w w e � � • � Peye Peye x y z � � http://www.ugrad.cs.ubc.ca/~cs314/Vjan2008 u 0 0 0 1 w � � 2 3 4 Pinhole Camera Pinhole Camera Pinhole Camera Real Cameras • ingredients • theoretical perfect pinhole • non-zero sized hole • pinhole camera has small aperture (lens opening) • box, film, hole punch • light shining through tiny hole into dark space • blur: rays hit multiple points on film plane • minimize blur aperture aperture yields upside-down picture • result • problem: hard to get enough light to expose the film • picture one ray multiple rays www.kodak.com of projection of projection actual • solution: lens perfect www.pinhole.org pinhole • permits larger apertures pinhole www.debevec.org/Pinhole • permits changing distance to film lens lens plane without actually moving it depth depth of of • cost: limited depth of field where field field image is in focus film plane film plane 5 6 7 8 http://en.wikipedia.org/wiki/Image:DOF-ShallowDepthofField.jpg Graphics Cameras General Projection Perspective Projection Perspective Projection • image plane need not be perpendicular to • our camera must model perspective • our camera must model perspective • real pinhole camera: image inverted view plane eye eye point point image image eye eye plane plane point point image image plane plane computer graphics camera: convenient equivalent eye eye eye eye point point point point center of center of projection projection image image image image plane plane plane plane 9 10 11 12 Projective Transformations Projective Transformations Perspective Projection Perspective Projection • planar geometric projections • properties • project all geometry • lines mapped to lines and triangles to triangles • planar: onto a plane • through common center of projection (eye point) • parallel lines do NOT remain parallel projection • geometric: using straight lines • onto an image plane plane • e.g. rails vanishing at infinity • projections: 3D -> 2D x x • aka projective mappings center of projection (eye point) • affine combinations are NOT preserved how tall should y y this bunny be? • counterexamples? • e.g. center of a line does not map to center of -z -z projected line (perspective foreshortening) z z z z x x x x 13 14 15 16
Basic Perspective Projection Perspective Projection Simple Perspective Projection Matrix Simple Perspective Projection Matrix • desired result for a point [x, y, z, 1] T projected x similar triangles similar triangles x x � � � � � � onto the view plane: � � P(x,y,z) P(x,y,z) y y � � � � y z / d z / d is homogenized version of � � � � � � z � � y ' d = y z � y ' = y � d y y P(x P( x’ ’, ,y y’ ’, ,z z’ ’) ) � � � � x ' x y ' y � � , � � � � z = = z / d z / d z / d where w = z/d z z � � d z d z � � � � z’ z ’= =d d � � � � d d � � � � x ' d = x z � x ' = x � d x d x y d y � � � � � � but but z ' = d x ' , y ' , z ' d = = = = = z z z d z z d • nonuniform foreshortening • what could a matrix look like to do this? • not affine 17 18 19 20 Simple Perspective Projection Matrix Perspective Projection Moving COP to Infinity Orthographic Camera Projection • expressible with 4x4 homogeneous matrix • as COP moves away, lines approach parallel • camera’s back plane x x � � � � x x � � � � parallel to lens p � � • use previously untouched bottom row • when COP at infinity, orthographic view � � y � � � � z / d y y = is homogenized version of � � • infinite focal length � p � � � � � • perspective projection is irreversible z z 0 � � � � � � y � � • no perspective � � � p � � � • many 3D points can be mapped to same � � convergence z / d z / d where w = z/d � � x 1 0 0 0 x � � (x, y, d) on the projection plane � � � � � � p � � � � � � � � • just throw away z values d • no way to retrieve the unique z values y 0 1 0 0 y � � � p � � � � � x 1 0 0 0 x � � = � � � � � � z 0 0 0 0 z � � � � � � � � � � � � y 0 1 0 0 y p � � � � � � � � � � � � = 1 0 0 0 1 1 z 0 0 1 0 z � � � � � � � � � � � � � � � � � � z / d 0 0 1 d 0 1 � � � � � � 21 22 23 24 Perspective to Orthographic View Volumes Canonical View Volumes Why Canonical View Volumes? • transformation of space • specifies field-of-view, used for clipping • standardized viewing volume representation • permits standardization • center of projection moves to infinity • restricts domain of z stored for visibility test • clipping perspective orthographic • view volume transformed • easier to determine if an arbitrary point is orthogonal enclosed in volume with canonical view • from frustum (truncated pyramid) to perspective view volume orthographic view volume orthographic view volume perspective view volume parallel volume vs. clipping to six arbitrary planes parallelepiped (box) y=top y=top x x x x • rendering x=left x=left y x or y = +/- z x or y x or y back y • projection and rasterization algorithms can be z plane x=right back 1 reused z front VCS plane front y=bottom z=-near x Frustum Frustum Parallelepiped Parallelepiped VCS -z z=-far plane z=-far -z -1 -z -z plane -z -z x y=bottom x=right z=-near -1 25 26 27 28 Normalized Device Coordinates Normalized Device Coordinates Understanding Z Understanding Z • convention near, far always positive in OpenGL calls • z axis flip changes coord system handedness left/right x =+/- 1, top/bottom y =+/- 1, near/far z =+/- 1 • viewing frustum mapped to specific glOrtho glOrtho(left,right, (left,right,bot bot,top,near,far); ,top,near,far); • RHS before projection (eye/view coords) glFrustum glFrustum(left,right, (left,right,bot bot,top,near,far); ,top,near,far); Camera coordinates NDC NDC parallelepiped Camera coordinates glPerspective glPerspective( (fovy fovy,aspect,near,far); ,aspect,near,far); • LHS after projection (clip, norm device coords) • Normalized Device Coordinates (NDC) x x x x • same as clipping coords VCS perspective view volume perspective view volume orthographic view volume orthographic view volume x=1 x=1 NDCS y=top • only objects inside the parallelepiped get right right y=top y (1,1,1) y=top x=left Frustum x=left rendered Frustum x=left y -z -z z y z z left left y • which parallelepiped? (-1,-1,-1) z z x= -1 x= -1 x x=right x=right • depends on rendering system z= -1 z=1 z=1 VCS z= -1 x y=bottom z=-near x z=-far VCS z=-far z=-far x y=bottom y=bottom z=-near z=-n x=right z=-near z=-n z=-f z=-f 29 30 31 32
Recommend
More recommend