Computer Graphics CSE 67 [Win 9], Lecture 5: Viewing Ravi Ramamoorthi http://viscomp.ucsd.edu/classes/cse67/wi9 To Do Questions/concerns about assignment? Remember it is due tomorrow! (Jan 6). Ask me or TAs re problems Motivation Summar: The Whole Viewing Pipeline We have seen transforms (between coord sstems) But all that is in 3D We still need to make a D picture Project 3D to D. How do we do this? This lecture is about viewing s Model coordinates Model World coordinates Camera (glulookat) Slide courtes Greg Humphres Ee coordinates Perspective (gluperspective) Screen coordinates Viewport Window coordinates Raster Device coordinates Demo (Projection Tutorial) Nate Robbins OpenGL tutors Projection tutorial Download others What we ve seen so far Transforms (translation, rotation, scale) as 44 homogeneous matrices Last row alwas 0. Last w component alwas For viewing (perspective), we will use that last row and w component no longer (must divide b it)
Projections To lower dimensional space (here 3D -> D) Preserve straight lines Trivial eample: Drop one coordinate (Orthographic) Orthographic Projection Characteristic: Parallel lines remain parallel Useful for technical drawings etc. Eample Simpl project onto plane, drop coordinate Orthographic Perspective In general We have a cuboid that we want to map to the normalied or square cube from [-, +] in all aes We have parameters of cuboid (l,r ; t,b; n,f) Orthographic Matri First center cuboid b translating Then scale into unit cube n l t f r b Translate n l t f r b Translate
M = 0 Matri 0 t b 0 0 Translation (centering) l + r 0 0 t + b f + n 0 Caveats Looking down, f and n are negative (n > f) OpenGL convention: positive n, f, negate internall t n l f r b Translate Final Result M = r + l 0 0 t + b t b t b f + n 0 glortho = r + l 0 0 t + b t b t b f + n 0 Perspective Projection Funn things happen Most common computer graphics, art, visual sstem Further objects are smaller (sie, inverse distance) Parallel lines not parallel; converge to single point A Plane of Projection A Center of projection (camera/ee location) B B Slides inspired b Greg Humphres 3
Overhead View of Our Screen In Matrices ( 0,0,0) ( ) (,,d ),, d Note negation of coord (focal plane d) (Onl) last row affected (no longer 0 ) w coord will no longer =. Must divide at end Looks like we ve got some nice similar triangles here? = d = d = d = d * 0 0 P = 0 d 0 Verif 0 0 0 d 0 =? d = d * d * d Remember projection tutorial Viewing Frustum Far plane Near plane 4
Screen (Projection Plane) gluperspective Field of view (fov) width height gluperspective(fov, aspect, Near > 0, Far > 0) Fov, aspect control fov in, directions Near, Far control viewing frustum Aspect ratio = width / height Overhead View of Our Screen ( 0,0,0) θ =? d =? θ = fov ( ) (,,d ),, d d = cotθ Simplest form: In Matrices P = aspect Aspect ratio taken into account 0 0 0 d 0 Homogeneous, simpler to multipl through b d Must map vals based on near, far planes (not et) In Matrices Z mapping derivation P = 0 0 0 d 0 aspect d aspect 0 0 d A B 0 A and B selected to map n and f to -, + respectivel A B 0 =? Simultaneous equations? A + B n = A + B f = + A + B A = f + n B = fn = A B 5
Mapping of Z is nonlinear A + B = A B Man mappings proposed: all have nonlinearities Advantage: handles range of depths (0cm 00m) Disadvantage: depth resolution not uniform More close to near plane, less further awa Common mistake: set near = 0, far = inft. Don t do this. Can t set near = 0; lose depth resolution. We discuss this more in review session Summar: The Whole Viewing Pipeline Model coordinates Model World coordinates Camera (glulookat) Slide courtes Greg Humphres Ee coordinates Perspective (gluperspective) Screen coordinates Viewport Window coordinates Raster Device coordinates 6