Math of Projectios:Overview Math of perspective projectio, stadard cofiguratio OpeGL perspective projectios Math of orthographic projectio OpeGL orthographic projectios Viewport trasformatios ad settig them i OpeGL Perspective Viewig Viewig trasformatios Orthographic projectio caoical viewig volume Perspective projectio caoical viewig volume Hidde surface removal Viewig, projectios Hofstra Uiversity 3 Viewig, projectios Perspective Projectios -z Viewig, projectios The graphics system applies a 4 x 4 projectio matrix after the model-view matrix Gearal perspective: Viewig directio is ot orthogoal to projectio plae Hofstra Uiversity 33 Viewig, projectios Math of perspective projectio Let O be COP Projectio plae has equatio z=d, d < 3D poit P has homogeeous coordiates (x,y,z,) It is mapped to poit Q (xp,yp,d) i the projectio plae Hofstra Uiversity 34 Stadard cofiguratio: COP=VRP Projectio plae is orthogoal to z-axis, at z=d Viewig, projectios Hofstra Uiversity Math of perspective projectio The discussio here is carried out with respect to the camera (view) referece frame, (VRP,u,v,) The projectio trasformatio maps 3D poits to D poits i the projectio plae Stadard cofiguratio: 3 Perspective Projectios -z Viewig directio orthogoal To projectio plae Hofstra Uiversity 35 Q is o the segmet PO, thus Q=cP+(-c)O, where <c< Thus, xp = c.x, yp = c.y, d = c.z è c = d/z Thus, xp = (d/z).x, yp = (d/z).y, i affie coordiates Note that projectio is ot liear i affie coordates. Viewig, projectios Hofstra Uiversity 36
Math of perspective projectio Clippig P=p(x,y,z,) è Q=q(d.x/z, d.y/z, d, ), i homogeeous coordiates. Perspective projectio is ot liear i affie coord. Perspective projectio is liear i homogeeous M per = / d q = M per p = / d x x y y = z z z / d From homogeeous to affie coordiates: (a,b,c,w) è (a/w, b/w,c/w) Thus (x,y,z,d/z) i homogeeous becomes (x/(z/d), y/(z/d),d,) ==> (d.x/z, d.y/z,) i proj. plae Viewig, projectios Hofstra Uiversity 37 Object parts outside of the of the view volume are clipped First we will discuss the opegl fuctios that set up the projectio trasformatios Next we will discuss the viewport trasformatio ad settig the viewport i OpeGL Last, we will go back to projectio, ad see how the graphics systems carry out efficietly the more geeral perspective projectio by reducig it to the stadard perspective, ad the to the caoical orthographic You ca set up ay projectio you wat (parallel or perspective) by settig up the the projectio matrix directly Although, more ofte we use affie trasformatios to reduce more geeral projectios to the caoical oes Viewig, projectios Hofstra Uiversity 38 Perspective Viewig i OpeGL Projectios i OpeGL frustum Depth of projectio plae (size of clippig widow) iside the pyramid does ot matter. All that matters is object size relative to the widow. The projectio plae depth does ot affect relative size. Thus i CG systems usually far or ear plae is selected to be the projectio plae. Near i opegl. opegl. Viewig, projectios Hofstra Uiversity 39 oly fixed poit Objects ot i the view volume are clipped. View (projectio) plae is frot clippig plae. Viewig, projectios OpeGL Perspective Hofstra Uiversity 4 OpeGL Perspective glfrustum(left, glfrustum(left, right, bottom, top, ear, far); gluperspective( gluperspective(fovy, fovy, aspect, ear, far); glmatrixmode(gl_projection); glloadidetity( ); fov is the agle betwee the top ad bottom plaes glfrustum(left, right, bottom, top, ear, far); The relatioship betwee frot(ear) plae ad COP(origi) defie the steepess of the frustum Viewig, projectios Hofstra Uiversity 4 Viewig, projectios Hofstra Uiversity 4
OpeGL Orthographic Projectio Stadard Orthographic Projectio glortho(left, right, bottom, top, ear, far); x p y p = z p x y z Viewig, projectios Hofstra Uiversity 43 Viewig, projectios Hofstra Uiversity 44 Viewport Trasformatio Viewport Trasformatio viewport trasformatio correspods to the stage where the size of the developed photograph is chose The viewport is measured i pixels, i scree widow coordiates, which reflect the positio of pixels o the scree relative to the lower left corer of the widow vertices outside the viewig volume have bee clipped viewport is the rectagular regio of the widow where the image is draw Viewig, projectios Hofstra Uiversity 45 Viewig, projectios Hofstra Uiversity 46 Defiig the Viewport The widow maager, ot OpeGL, is resposible for opeig a widow o the scree By default the viewport is set to the etire pixel rectagle of the widow that's opeed Use the glviewport() commad to choose a smaller drawig regio Defiig The Viewport By default, the iitial viewport parameters are (,, wiwidth, wiheight), where wiwidth ad wiheight are the widow dimesios. The aspect ratio of a viewport should geerally equal the aspect ratio of the viewig volume If the two ratios are differet, the projected image will be distorted as it's mapped to the viewport void glviewport(glit x, GLit y, GLsizei width, GLsizei height); lower left corer size of viewport rectagle Viewig, projectios Hofstra Uiversity 47 Viewig, projectios Hofstra Uiversity 48 3
Viewport Distortio World to View coordiates Camera positio: VRP Viewig trasformatio Traslate VRP to origi: T(-VRP) Rotate, aligig view frame (u,v,) with world frame The composite trasformatio R.T will have the effect of trasformig the coordiates of vertices from world to view coordiates Viewig, projectios Hofstra Uiversity 49 Viewig, projectios Hofstra Uiversity 5 Caoical view orthographic projectio VRP at the origi Lookig i egative z directio (COP does ot matter) View-up vector is (,,) View volume is a cube of side ceter at origi, (left, right, bottom, top, ear, far)=(-,,-,,,-) Perspective projectio stadard viewig VRP at origi Lookig i egative z-directio, look at is (,,-) COP coicides with VRP, viewig directio is orthogoal to view plae View-up vector is (,,) View volume is a regular frustum (left, right, top, bottom, ear, far)=(-,,-,,,z_far), The ear plae is at, the far is at -z. Side clippig plaes make 45 deg agles with z axis (,,-) Viewig, projectios (-,-,) Hofstra Uiversity 5 Viewig, projectios Hofstra Uiversity 5 Caoical Viewig for Perspective Hidde Surface Removal z-buffer algorithm as the polygos are rasterized we keep track of the distace from the VRP to the closest poit o each projector. We display oly the closest poit Requires a depth or z buffer to store the ecessary depth iformatio Viewig, projectios Hofstra Uiversity 53 glutiitdisplaymode(glut_double GLUT_RGB GLUT_DEPTH); gleable(gl_depth_test); glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); Viewig, projectios Hofstra Uiversity 54 4
Hidde Surface Removal Perspective Normalizatio Display oly visible surfaces (remove hidde) Paiter s algorithm: sort polygos accordig to z, project i order of decreasig depth Pixel based: back track rays from pixels to first itersectio How ca we apply geeral perspective projectio? Derive the perspective projectio matrix (geeral 4x4 matrix), load that as a PROJECTION matrix Trick: Usig series of affie trasformatios to alter the world, so that the image of the distorted world uder stadard (caoical) projectio is the same as the image of the udistorted world uder the origial geeral projectio Graphics systems go eve farther: perspective projectios are implemeted iterally as orthographic projectios (of the distorted world) with respect to the caoical view volume (xx cube). This way the clippig is very efficiet, ad z-buffer algorithm is supported by preservig relative depth i the process of trasformig objects. Z-buffer algorithm: based o relative depth after projectio Viewig, projectios Hofstra Uiversity 55 Viewig, projectios Hofstra Uiversity 56 Projectio Normalizatio Idea Projectio Normalizatio The distortio is described by a homogeeouscoordiate matrix Cocateate this matrix with a orthogoalprojectio matrix to yield a resultig projectio matrix Viewig, projectios Hofstra Uiversity 57 Viewig, projectios Hofstra Uiversity 58 Geeral Perspective Projectio Projectio coverts poits i 3-D space to poits o the projectio plae Three steps (the graphics system implemets them): Coverts the viewig volume (geeral frustum) to the caoical perspective view volume Next coverts the caoical perspective view volume to the caoical orthographic view volume Applys orthographic projectio matrix The most caoical view volume Orthographic projectio with respect to most caoical view volume Caoical view volume is a xx cube whose ceter is at the origi (default view volume) How to clip?: simple How to project?: o divisio (,,-) (-,-,) Viewig, projectios Hofstra Uiversity 59 Viewig, projectios Hofstra Uiversity 6 5
Geeral Orthogoal Projectio glmatrixmode(gl_projection); glloadidetity( ); glortho(-.,., -.,., -.,.); Projectio Matrix determie which objects are clipped out P = ST x = max x mi max y y mi zmax z mi xmax + x xmax x ymax + y ymax y zmax + z zmax z mi mi mi mi mi mi Projectio Matrix maps a view volume to the caoical view volume Viewig, projectios Hofstra Uiversity 6 Viewig, projectios Hofstra Uiversity 6 Oblique Projectio Oblique Projectio degree of obliqueess shearig Viewig, projectios Hofstra Uiversity 63 Viewig, projectios Hofstra Uiversity 64 Perspective Projectio Matrices Perspective Projectio Matrices Look for a trasformatio allows a simple caoical projectio by distortig the vertices of a object Three steps: ) select caoical viewig volume, ) itroduce the perspective ormalizatio trasformatio ad 3) derive the perspective projectio matrix Viewig, projectios Hofstra Uiversity 65 Viewig, projectios Hofstra Uiversity 66 6
Perspective Projectio Matrices N is called the perspective ormalizatio matrix. It coverts a perspective projectio to a orthogoal projectio N Projectio ad Shadows Shadows are ot geometric objects but importat for realism A poit is i a shadow if it is ot illumiated by ay light source A shadow polygo is a flat shadow that results from projectig the origial polygo oto a surface Viewig, projectios Hofstra Uiversity 67 Viewig, projectios Hofstra Uiversity 68 Projectio ad Shadows use a modelview matrix Viewig, projectios Hofstra Uiversity 69 7