1
play

1 Projections Orthographic Projection To lower dimensional space - PDF document

To Do Computer Graphics Questions/concerns about assignment 1? Remember it is due Jan 30. Ask me or TAs re problems CSE 167 [Win 17], Lecture 5: Viewing Ravi Ramamoorthi http://viscomp.ucsd.edu/classes/cse167/wi17 Motivation Demo


  1. To Do Computer Graphics § Questions/concerns about assignment 1? § Remember it is due Jan 30. Ask me or TAs re problems CSE 167 [Win 17], Lecture 5: Viewing Ravi Ramamoorthi http://viscomp.ucsd.edu/classes/cse167/wi17 Motivation Demo (Projection Tutorial) § Nate Robbins OpenGL § We have seen transforms (between coord systems) tutors § Projection tutorial § 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 ’ ve seen so far 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) § 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) 1

  2. 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) Orthographic Perspective 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) t f y y y n Translate Scale b r l x x x z z z Orthographic Matrix Transformation Matrix § First center cuboid by translating Scale Translation (centering) § Then scale into unit cube ⎛ ⎞ ⎛ ⎞ − l + r 2 0 0 0 1 0 0 ⎜ ⎟ ⎜ ⎟ r − l 2 ⎜ ⎟ ⎜ ⎟ t f ⎜ ⎟ ⎜ − t + b ⎟ 2 y y y 0 0 0 0 1 0 n ⎜ ⎟ ⎜ ⎟ M = t − b 2 Translate b Scale ⎜ ⎟ ⎜ ⎟ r l x x x − f + n ⎜ 2 ⎟ ⎜ ⎟ 0 0 0 0 0 1 ⎜ ⎟ ⎜ ⎟ z z z f − n 2 ⎜ ⎟ ⎟ ⎜ ⎝ ⎠ ⎝ ⎠ 0 0 0 1 0 0 0 1 2

  3. Caveats Final Result § Looking down –z, f and n are negative (n > f) § OpenGL convention: positive n, f, negate internally ⎛ ⎞ ⎛ ⎞ − r + l − r + l 2 2 ⎜ 0 0 ⎟ 0 0 ⎟ ⎜ r − l r − l r − l r − l ⎜ ⎟ ⎜ ⎟ ⎜ 2 − t + b ⎟ ⎜ 2 − t + b ⎟ 0 0 t 0 0 f ⎜ ⎟ ⎜ ⎟ M = glOrtho = t − b t − b t − b t − b y y ⎜ ⎟ ⎜ ⎟ y n − f + n − 2 − f + n ⎜ 2 ⎟ ⎜ ⎟ 0 0 0 0 Translate Scale ⎜ ⎟ ⎜ ⎟ b f − n f − n f − n f − n l r x x x ⎜ ⎟ ⎜ ⎟ ⎝ ⎠ ⎝ ⎠ 0 0 0 1 0 0 0 1 z z z 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 § Brief discussion of nonlinear mapping in z Plane of Projection A ’ B B ’ Center of projection (camera/eye location) Slides inspired by Greg Humphreys 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 ⎜ ⎟ Looks like we ’ ve got some nice similar triangles here? P = ⎜ ⎟ 0 0 1 0 ⎜ ⎟ x = d ∗ x x x ′ ′ − 1 y y y = d * y ⎜ ⎟ = ⇒ ′ = ⇒ ′ 0 0 0 ⎝ ⎠ d z d z z d z 3

  4. Verify Outline § Orthographic projection (simpler) ⎛ ⎞ − d * x ⎛ ⎞ ⎛ ⎞ x § Perspective projection, basic idea ⎜ ⎟ 1 0 0 0 ⎛ ⎞ ⎜ ⎟ x z ⎜ ⎟ ⎟ ⎜ y 0 1 0 0 ⎜ ⎟ ⎜ ⎟ § Derivation of gluPerspective (handout: glFrustum) ⎜ ⎟ ⎜ ⎟ y − d * y ⎜ ⎟ = ⎜ ⎟ = ? ⎜ ⎟ z 0 0 1 0 ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ z § Brief discussion of nonlinear mapping in z z ⎜ ⎟ ⎜ ⎟ − z − 1 ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ − d 0 0 0 ⎜ ⎟ ⎝ ⎠ 1 ⎜ ⎟ ⎝ d ⎠ ⎝ d ⎠ ⎜ ⎟ ⎝ 1 ⎠ Remember projection tutorial Viewing Frustum Far plane Near plane 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 4

  5. Overhead View of Our Screen In Matrices ⎛ ⎞ ( ) § Simplest form: 1 x , y , z ( ) 0 0 0 ⎜ ⎟ ′ x , ′ y , d ( ) aspect ⎜ ⎟ 0,0,0 ⎜ ⎟ 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) In Matrices Z mapping derivation ⎛ ⎞ 1 ⎛ ⎞ 0 0 0 ⎜ ⎟ d ⎛ ⎞ ⎛ ⎞ ⎛ ⎞ Az + B ⎟ = − A − B aspect ⎜ 0 0 0 ⎟ A B z ⎜ ⎟ ⎟ = ? aspect ⎜ ⎟ ⎜ ⎜ ⎜ ⎟ ⎜ ⎟ ⎝ − 1 ⎠ ⎝ ⎠ ⎝ − z ⎠ z 0 1 0 0 0 1 P = → ⎜ ⎟ ⎜ ⎟ 0 d 0 0 0 0 1 0 ⎜ ⎟ ⎜ ⎟ 0 0 A B ⎜ ⎟ ⎜ ⎟ § Simultaneous equations? − 1 ⎜ ⎟ 0 0 0 ⎝ − 1 ⎠ ⎜ ⎟ 0 0 0 ⎝ ⎠ d A = − f + n − A + B n = − 1 § A and B selected to map n and f to -1, +1 respectively f − n − A + B B = − 2 fn f = + 1 f − n Outline Mapping of Z is nonlinear ⎛ ⎞ Az + B ⎟ = − A − B ⎜ § 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 5

  6. Summary: The Whole Viewing Pipeline Eye coordinates Model coordinates Perspective Transformation (gluPerspective) Model transformation Screen coordinates Viewport World coordinates transformation Camera Transformation Window coordinates (gluLookAt) Raster Device coordinates transformation Slide courtesy Greg Humphreys 6

Recommend


More recommend