320 likes | 438 Views
CAP 4703 Computer Graphic Methods. Prof. Roy Levow Chapter 5. Viewing. Classical viewing Need to be able to reproduce classical views for a variety of applications Isometric Preserves measurements Elevation View a face of object Perspective Reflects size change of distant objects.
E N D
CAP 4703Computer Graphic Methods Prof. Roy Levow Chapter 5
Viewing • Classical viewing • Need to be able to reproduce classical views for a variety of applications • Isometric • Preserves measurements • Elevation • View a face of object • Perspective • Reflects size change of distant objects
Viewing Terminology • Center of Projection (COP) • Point where all projectors meet • Center of camera or eye lens • Origin of synthetic camera frame • Direction of Projection (DOP) • Direction of projectors when COP is moved to infinity
Types of Viewing • Classical (many) • Orthographic • One-, two-, and 3-point perspectives • Computer • Orthographic • Perspective
Classical Viewing Concepts • Principal face • Primary surface of view • Based on rectangular solid structures • Orthographic Projection • Single view • Multiview • Show three orthogonal views
Axonometric Projections • Projectors are orthogonal to the projection plane but plane can be at angle to principal face • Isometric – symmetric with all three axes • Dimetric – symmetric with two axes • Trimetric – general case • Produces foreshortening of distances
Oblique Projection • Most general parallel view • Projectors make arbitrary angle with projection plane • In computer graphics system, isometric, axonometric and oblique projections are all variations on one case
Perspective • Characterized by diminution of size of more distant objects • Classically, viewer is symmetrical with respect to the projection plane • One-, two-, and three-point perspectives depending on number of vanishing points
Computer Viewing • Choose parallel or perspective view • No separation of perspective degrees • Two key elements • Position camera • Apply projection transformaton
OpenGL Camera • Default • Camera at origin • Pointing in negative z direction • Orthogonal view • Viewing volume is cube • Centered at origin • Side of length 2
Positioning Camera Frame • Can construct camera frame through translation and rotation of model view to get camera to desired viewing position from default position • For orthographic view, this does not change clipping volume set by glOrtho() • Size is unchanged • What is seen will change
View as Change of Frames • Set View-Reference Point (VRP) • Center of camera • View plane defined by • View-plane normal (VPN) • View-up vector (VUP) • Project VUP onto projection plane to get up direction (vup) • Construct new frame with basis for view plane, u-v and normal n; u-v-n
OpenGL Look-At • OpenGL simplifies camera positioning as follows • e = eye point • a = look-at point • Determines vpn as e – a glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz); /* define objects here */
Perspective Projection • Note: x/z = xp/d or xp= x/(z/d) • Similarly for y • Provides non-uniform foreshortening • Perspective Transformation • (x, y, z) -> (xp, yp, zp)
Perspective Projection (cont) • Moving to 4 dimensions, consider (wx, wy, wz, w)T • Perspective transformation matrix • 0 0 0 takes 0 1 0 0 (x, y, z, 1) T 0 0 1 0 to 0 0 1/d 0 (x, y, z, z/d) T • Division by last coordinate gives (xp, yp, d, 1), the projection
Orthogonal Projection in OpenGL • Simply map z into zero
Projection in OpenGL • Clipping region is a frustum, a truncated pyramid
OpenGL Frustum • glFrustum(xmin, xmax, ymin, ymax, near, far); // left, right, top, bottom, near, far
Parallel Viewing in OpenGL • glOrtho(xmin, xmax, ymin, ymax, near, far);
Hidden Surface Removal • Remove hidden surfaces • Different view • Visible-surface algoritims • Identify visible surfaces • Work in either • Object space • Image space
Z-Buffer Algorithm • Image Space • Requires depth buffer, called z-buffer to store depth • Depth resolution usually 16, 24, or 32 bits • As polygon is rasterized, depth is computed and compared with current z-buffer value; only nearer values update • Very efficient
OpenGL Implementation • Enable with • glutInitDisplayMode(GLUT_DEPTH…); • glEnabel(GL_DEPTH_TEST); • Clear with • glClear(GL_DEPTH_BUFFER_BIT);
Scene Walkthrough • Move camera to view color cube from different locations • cubeview.c
Parallel-Projection Matrices • Previous projection matrices do not cover all possibilities • Projection Normalization • convert all projections to orthogonal • by distorting objects • distortion is called normalization • Map viewing volume into 2x2x2 cube at origin; translate and then scale
Oblique Projection • Projectors do not need to be orthogonal to projection plane as in standard OpenGL projection • Equivalent to a shear transformation of the objects
Perspective-Projection Matrices • Again, distort object • Skipping details • OpenGL Perspective Transformations 2z/(X-x) 0 (X+x)/(X-x) 0 0 2z/(Y-y) (Y+y)/(Y-y) 0 0 0 -(f+n)/(f-n) -2fn/(f-n) 0 0 -1 0
Projections and Shadows • Shadow • projection of original polygon onto surface • center of projection is light source • shadow-polygon • shadow.c