1
play

1 Outline Projections To lower dimensional space (here 3D -> - PDF document

To Do Computer Graphics Questions/concerns about assignment 1? Remember it is due tomorrow! (Jan 16). CSE 167 [Win 19], Lecture 5: Viewing Ask me or TAs re problems Ravi Ramamoorthi http://viscomp.ucsd.edu/classes/cse167/wi19


  1. To Do Computer Graphics § Questions/concerns about assignment 1? § Remember it is due tomorrow! (Jan 16). CSE 167 [Win 19], Lecture 5: Viewing § Ask me or TAs re problems Ravi Ramamoorthi http://viscomp.ucsd.edu/classes/cse167/wi19 Motivation Summary: The Whole Viewing Pipeline Eye coordinates § We have seen transforms (between coord systems) Model coordinates Perspective Transformation § But all that is in 3D (gluPerspective) Model § We still need to make a 2D picture transformation Screen coordinates § Project 3D to 2D. How do we do this? Viewport World coordinates transformation § This lecture is about viewing transformations Camera Transformation Window coordinates (gluLookAt) Raster Device coordinates transformation Slide courtesy Greg Humphreys Demo (Projection Tutorial) What we ’ ve seen so far § Transforms (translation, rotation, scale) as 4x4 § Nate Robbins OpenGL homogeneous matrices tutors § Projection tutorial § Last row always 0 0 0 1. Last w component always 1 § Download others § For viewing (perspective), we will use that last row and w component no longer 1 (must divide by it) 1

  2. Outline Projections § To lower dimensional space (here 3D -> 2D) § Orthographic projection (simpler) § Preserve straight lines § Perspective projection, basic idea § Trivial example: Drop one coordinate (Orthographic) § Derivation of gluPerspective (handout: glFrustum) § Brief discussion of nonlinear mapping in z Orthographic Projection Example § Characteristic: Parallel lines remain parallel § Simply project onto xy plane, drop z coordinate § Useful for technical drawings etc. Perspective Orthographic In general Orthographic Matrix § We have a cuboid that we want to map to the § First center cuboid by translating normalized or square cube from [-1, +1] in all axes § Then scale into unit cube § We have parameters of cuboid (l,r ; t,b; n,f) t t f f y y y y y y n n Translate Translate b Scale b Scale r r l l x x x x x x z z z z z z 2

  3. Transformation Matrix Caveats § Looking down –z, f and n are negative (n > f) Scale Translation (centering) § OpenGL convention: positive n, f, negate internally ⎛ ⎞ ⎛ ⎞ − 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 Scale b ⎜ ⎟ ⎜ ⎟ l r 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 Final Result Outline § Orthographic projection (simpler) ⎞ ⎛ ⎛ ⎞ − r + l 2 2 − r + l § Perspective projection, basic idea 0 0 0 0 ⎜ ⎟ ⎜ ⎟ r − l r − l r − l r − l ⎜ ⎟ ⎜ ⎟ ⎜ − t + b ⎟ ⎜ − t + b ⎟ § Derivation of gluPerspective (handout: glFrustum) 2 2 0 0 0 0 ⎜ ⎟ ⎜ ⎟ M = glOrtho = t − b t − b t − b t − b ⎜ ⎟ ⎜ ⎟ § Brief discussion of nonlinear mapping in z ⎜ 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 Perspective Projection Funny things happen … § Most common computer graphics, art, visual system § Further objects are smaller (size, inverse distance) § Parallel lines not parallel; converge to single point A Plane of Projection A ’ B B ’ Center of projection (camera/eye location) Slides inspired by Greg Humphreys 3

  4. 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 ′ − 1 x x y y y = d * y ⎜ ⎟ = ⇒ ′ 0 0 0 = ⇒ ′ ⎝ d ⎠ z d z z d z 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 4

  5. 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 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 ⎛ ⎞ ⎛ ⎞ ⎛ ⎞ ⎟ = − A − B Az + 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 5

  6. 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 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