1
play

1 Projections Orthographic Projection Projections Orthographic - PDF document

To Do To Do Foundations of Computer Graphics Foundations of Computer Graphics Questions/concerns about assignment 1? (Spring 2012) (Spring 2012) Remember it is due next Thu. Ask me or TAs re problems CS 184, Lecture 5: Viewing


  1. To Do To Do Foundations of Computer Graphics Foundations of Computer Graphics  Questions/concerns about assignment 1? (Spring 2012) (Spring 2012)  Remember it is due next Thu. Ask me or TAs re problems CS 184, Lecture 5: Viewing http://inst.eecs.berkeley.edu/~cs184 Motivation Demo (Projection Tutorial) Motivation Demo (Projection Tutorial)  Nate Robbins OpenGL  We have seen transforms (between coord systems) tutors  Projection.exe  But all that is in 3D  Download others  We still need to make a 2D picture  Project 3D to 2D. How do we do this?  This lecture is about viewing transformations What we’ What we ’ve seen so far ve seen so far Outline Outline  Transforms (translation, rotation, scale) as 4x4 homogeneous matrices  Orthographic projection (simpler)  Last row always 0 0 0 1. Last w component always 1  Perspective projection, basic idea  Derivation of gluPerspective (handout: glFrustum)  In new OpenGL, glm macro glm::lookAt glm::Perspective  For viewing (perspective), we will use that last row  Brief discussion of nonlinear mapping in z and w component no longer 1 (must divide by it) Not well covered in textbook chapter 7. We follow section 3.5 of real-time rendering most closely. Handouts on this will be given out. 1

  2. Projections Orthographic Projection Projections Orthographic Projection  To lower dimensional space (here 3D -> 2D)  Characteristic: Parallel lines remain parallel  Preserve straight lines  Useful for technical drawings etc.  Trivial example: Drop one coordinate (Orthographic) Fig 7.1 in text Perspective Orthographic Example In general Example In general  We have a cuboid that we want to map to the  Simply project onto xy plane, drop z coordinate normalized or square cube from [-1, +1] in all axes  We have parameters of cuboid (l,r ; t,b; n,f) Orthographic Matrix Orthographic Matrix Transformation Matrix Transformation Matrix  First center cuboid by translating Scale Translation (centering)  Then scale into unit cube      2 l r  0 0 0 1 0 0      r l 2       2   t b   0 0 0 0 1 0       M t b 2      2 f n      0 0 0 0 0 1      f n 2         0 0 0 1 0 0 0 1 2

  3. Caveats Final Result Caveats Final Result  Looking down –z, f and n are negative (n > f)  OpenGL convention: positive n, f, negate internally       2 r l 2 r l   0 0    0 0      r l r l r l r l           2 t b 2 t b   0 0 0 0           M glm :: ortho t b t b t b t b        2 f n 2 f n       0 0 0 0         f n f n f n f n      0 0 0 1   0 0 0 1  Outline Perspective Projection Outline Perspective Projection  Most common computer graphics, art, visual system  Orthographic projection (simpler)  Further objects are smaller (size, inverse distance)  Perspective projection, basic idea  Parallel lines not parallel; converge to single point  Derivation of gluPerspective (handout: glFrustum) A  In modern OpenGL, glm::perspective Plane of Projection  Brief discussion of nonlinear mapping in z A’ B B’ Center of projection (camera/eye location) Pinhole Camera Pinhole Camera Perspective Projection Perspective Projection  Center of Projection (one point)  Foreshortening: Distant objects appear smaller  Very common model in graphics (but real cameras use lenses; a bit more complicated) 3

  4. Overhead View of Our Screen In Matrices Overhead View of Our Screen In Matrices  Note negation of z coord (focal plane –d)   x y z , ,     x y d , ,  (Only) last row affected (no longer 0 0 0 1)   0,0,0  w coord will no longer = 1. Must divide at end d   1 0 0 0   0 1 0 0      P 0 0 1 0 Looks like we’ve got some nice similar triangles here?      x x d x y y d * y 1           x y    0 0 0 z d z z d z   d Verify Vanishing Points Verify Vanishing Points  Parallel lines “meet” at vanishing point   d * x  (x,y) ~ (d x , d y ) [directions]       1 0 0 0 x    x      z    Every pixel vanishing pt for  0 1 0 0 y        y d * y    some dirn (lines parallel to       ? z   0 0 1 0  z image plane vanish infinity)    z       1   z     d    Horizon       0 0 0 1       d d  1  Perspective Distortions Perspective Distortions Outline Outline  Perspective can distort; artists often correct  Orthographic projection (simpler)  Computers can too (Zorin and Barr 95)  Perspective projection, basic idea  Derivation of gluPerspective (handout: glFrustum)  Brief discussion of nonlinear mapping in z 4

  5. Remember projection tutorial Viewing Frustum Remember projection tutorial Viewing Frustum Far plane Near plane Screen (Projection Plane) gluPerspective Screen (Projection Plane) gluPerspective  gluPerspective(fovy, aspect, zNear > 0, zFar > 0) width  Fovy, aspect control fov in x, y directions  zNear, zFar control viewing frustum Field of view (fovy) height Aspect ratio = width / height Overhead View of Our Screen Overhead View of Our Screen In Matrices In Matrices   1  Simplest form:   0 0 0   x y z , ,     aspect x y d , ,     0,0,0 1    0 1 0 0   P  d 0 0 1 0        1 ? d ?    0 0 0   d  Aspect ratio taken into account fovy     d cot  Homogeneous, simpler to multiply through by d 2  Must map z vals based on near, far planes (not yet) 5

  6. In Matrices Z mapping derivation In Matrices Z mapping derivation   1   0 0 0 d    0 0 0   aspect         A B z Az B B   aspec t         A ?     0 1 0 0     z  z 1 0 1     0 d 0 0 P     0 0 1 0   0 0 A B  Simultaneous equations?     1         0 0 0 0 0 1 0    d B f n       A A 1  A and B selected to map n and f to -1, +1 respectively  f n n 2 fn B       A 1 B  f f n Outline Mapping of Z is nonlinear Outline Mapping of Z is nonlinear      Az B B    A  Orthographic projection (simpler)    z z  Perspective projection, basic idea  Many mappings proposed: all have nonlinearities  Derivation of gluPerspective (handout: glFrustum)  Advantage: handles range of depths (10cm – 100m)  Brief discussion of nonlinear mapping in z  Disadvantage: depth resolution not uniform  More close to near plane, less further away  Common mistake: set near = 0, far = infty. Don’t do this. Can’t set near = 0; lose depth resolution.  We discuss this more in review session Summary: The Whole Viewing Pipeline Summary: The Whole Viewing Pipeline Eye coordinates Model coordinates Perspective Transformation (glm::perspective) Model transformation Screen coordinates World coordinates Viewport transformation Camera Transformation Window coordinates (glm::lookAt) Raster Device coordinates transformation Slide courtesy Greg Humphreys 6

Recommend


More recommend