Projection Projection Overview o Orthographic projection o Perspective projection o Projection in OpenGL o We know how to transform objects to View space o We now want to ‘take a photo’ of the objects in View space - mapping from 3D to 2D is called projection: o Parallel projection maps objects directly onto the screen without affecting their relative size, often used in architectural and CAD applications o Perspective projection gives realistic views, but does not preserve proportions - projections of distant objects are smaller than those near objects of the same size. This is called foreshortening. Projection View Volume/Frustum Different Types of Projections o In Orthographic parallel projection, view plane is perpendicular to the direction of projection (think about a torch casting parallel rays on the view plane) o In Perspective projection, objects are projected onto the view plane along lines which converge at the observer, or Centre of Projection (CoP) Q P Q Viewing Frustum zv P1 P1 P2 yv P2 view plane Perspective view volume is defined by field of view or planes (near, far, left, right, top and bottom) xv Image Plane yv Eye Position P P1’ P2’ CoP/ Eye/ Camera view plane Orthographic view volume is a rectangular block defined by near, far, left, right, top and bottom planes zv xv Eye Position Field of view Orthographic Projection Image Plane Viewing Frustum Perspective Projection o Looking along X axis, similar triangles gives: Looking along z-axis we can see point P on the image plane, which is the 2D projection of a 3D point Q in camera space, and xP = xQ, yP = yQ (which means P and Q have the same x, y values) P(xp,yp) y P(x,y,z) y d dy y y z z p p yV yv d Q P(xp, yp) P Viewing Frustum zv xv Image Plane xV -z Similarly, looking along Y axis x x d dx x x z z p p Eye Position 1 Projection in OpenGL Projection in OpenGL o An OpenGL projection matrix takes points in view space and converts them to points in normalised device space or canonical space o The canonical space is a 2x2x2 cube, centered at the coordinate origin of the view space, with X, Y, Z each ranging from -1 to 1 o Thus only parallel orthographic projection is needed to obtain 2D images of a 3D scene Object Coordinate Space View Space Canonical Space OpenGL transforms all objects to a canonical space, e.g., the perspective viewing frustum is transformed to the canonical space – note all the objects undergo the same transformations Screen Space Canonical to Screen Transform Canonical to Screen Transform y o The last step is to position the 2D image on the display screen by calling glViewport() in OpenGL, to transform canonical coordinates to display coordinates o Parameters of glViewport() describe position of screen space within the window and the width and height of the screen, measured in pixels on the screen y x screen (1,1) x y (xmax,ymax) (xmin,ymin) x (-1,-1) x pixel y pixel z pixel 1 xmax xmin 2 0 0 0 0 0 0 y y 2 0 0 max min 0 1 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 xmax xmin ymax ymin 0 1 2 xcanonical 2 ycanonical zcanonical 1 Projections in OpenGL o glMatrixMode(GL_PROJECTION); o glLoadIdentity(); o o //glOrtho(‐windowWidth/2, windowWidth/2, ‐windowHeight/2, windowHeight/2, 1.0, 1000.0); o o o o o gluPerspective(60.0, windowWidth/windowHeight, 1, 1000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } 2
© Copyright 2026 Paperzz