250 likes | 485 Views
Computer Viewing. Mohan Sridharan Based on slides created by Edward Angel. Objectives. Introduce the mathematics of projection. Introduce OpenGL viewing functions. Look at alternate viewing APIs. Computer Viewing.
E N D
Computer Viewing Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics
Objectives • Introduce the mathematics of projection. • Introduce OpenGL viewing functions. • Look at alternate viewing APIs. CS4395: Computer Graphics
Computer Viewing • There are three aspects of the viewing process, all implemented in the pipeline: • Positioning the camera: • Setting the model-view matrix. • Selecting a lens: • Setting the projection matrix. • Clipping: • Setting the view volume. CS4395: Computer Graphics
The OpenGL Camera • Initially, object and camera frames are the same: • Default model-view matrix is identity. • The camera located at origin and points in the negative z direction. • OpenGL also specifies default view volume that is a cube with side of length 2 centered at the origin. • Default projection matrix is identity. CS4395: Computer Graphics
DefaultProjection • Default projection is orthogonal: clipped out 2 z=0 CS4395: Computer Graphics
Moving the Camera Frame • To visualize objects with both positive and negative z values: • Move the camera in the positive z direction. • Translate the camera frame. • Move the objects in the negative z direction. • Translate the world frame. • Both views are equivalent and determined by the model-view matrix: • Need a translation: glTranslatef(0.0,0.0,-d) • d > 0 CS4395: Computer Graphics
Moving Camera back from Origin frames after translation by –d d > 0 CS4395: Computer Graphics
Moving the Camera • Move the camera to any desired position by a sequence of rotations and translations. • Example: side view. • Rotate the camera. • Move it away from origin. • Modelview matrix: C = TR CS4395: Computer Graphics
OpenGL code • Remember that last transformation specified is first to be applied! glMatrixMode(GL_MODELVIEW) glLoadIdentity(); glTranslatef(0.0, 0.0, -d); glRotatef(90.0, 0.0, 1.0, 0.0); CS4395: Computer Graphics
The LookAt Function • GLU library contains the function (gluLookAt) to form the modelview matrix through a simple interface. • Need to set up a direction and initialize: • Concatenate with modeling transformations. • Example: isometric view of cube aligned with axes. glMatrixMode(GL_MODELVIEW): glLoadIdentity(); gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0., 1.0. 0.0); CS4395: Computer Graphics
Function: gluLookAt() glLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz) CS4395: Computer Graphics
Other Viewing APIs • The LookAt function is only one possible API for positioning the camera. • Others include (Sections 5.3.2, 5.3.4): • View reference point, view plane normal, view up (PHIGS, GKS-3D). • Yaw, pitch, roll. • Elevation, azimuth, twist. • Direction angles. CS4395: Computer Graphics
Projections and Normalization • The default projection in the eye (camera) frame is orthogonal. • For points within the default view volume: • Most graphics systems use view normalization: • All other views are converted to the default view by transformations that determine the projection matrix. • Allows use of the same pipeline for all views. xp x yp y zp = 0 CS4395: Computer Graphics
Homogeneous Coordinate Representation xp = x yp = y zp = 0 wp = 1 • Default orthographic projection: • In practice, can let M=I and set z term to zero later. pp = Mp M = CS4395: Computer Graphics
Perspective Projection • Preserves lines but not affine. • Irreversible: all points along a projector project to the same point. • Later: invertible variant of projection transformation that preserves distances (hidden-surface removal). CS4395: Computer Graphics
Simple Perspective Projection • Center of projection at the origin. • Projection plane z = d, d < 0 CS4395: Computer Graphics
Simple Perspective Equations • Consider top and side views: xp = yp = zp = d CS4395: Computer Graphics
Simple Perspective Projection • Representation in 4D for a 3D point: • Recover 3D point by dividing first three components by the fourth component. • Points in 3D become lines through the origin in 4D. • Large class of transformations using 4x4 matrices with the last row altered. CS4395: Computer Graphics
Perspective Projection Example consider q = Mp where M = q = p = CS4395: Computer Graphics
Perspective Division • However w 1, so divide by w to return from homogeneous coordinates to 3D space. • This perspective division yields: • In homogeneous coordinates: • Apply projection matrix after model-view matrix, then perform perspective division. CS4395: Computer Graphics
OpenGL Orthogonal Viewing glOrtho(left,right,bottom,top,near,far) nearandfarmeasured from camera CS4395: Computer Graphics
OpenGL Perspective glFrustum(left,right,bottom,top,near,far) CS4395: Computer Graphics
Using Field of View • With glFrustum it is often difficult to get the desired view. • gluPerpective(fovy, aspect, near, far) often provides a better interface. front plane aspect = w/h CS4395: Computer Graphics
Other Issues • Hidden surface removal: Section 5.6. • Interactive mesh displays: Section 5.7. CS4395: Computer Graphics