Presentation is loading. Please wait.

Presentation is loading. Please wait.

Based on slides created by Edward Angel

Similar presentations


Presentation on theme: "Based on slides created by Edward Angel"— Presentation transcript:

1 Based on slides created by Edward Angel
Computer Viewing Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics

2 Objectives Introduce the mathematics of projection.
Introduce OpenGL viewing functions. Look at alternate viewing APIs. CS4395: Computer Graphics

3 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

4 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

5 Default Projection Default projection is orthogonal: clipped out 2 z=0
CS4395: Computer Graphics

6 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

7 Moving Camera back from Origin
frames after translation by –d d > 0 CS4395: Computer Graphics

8 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

9 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

10 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., ); CS4395: Computer Graphics

11 Function: gluLookAt()
glLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz) CS4395: Computer Graphics

12 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

13 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

14 Homogeneous Coordinate Representation
Default orthographic projection: In practice, can let M=I and set z term to zero later. pp = Mp xp = x yp = y zp = 0 wp = 1 M = CS4395: Computer Graphics

15 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

16 Simple Perspective Projection
Center of projection at the origin. Projection plane z = d, d < 0 CS4395: Computer Graphics

17 Simple Perspective Equations
Consider top and side views: xp = yp = zp = d CS4395: Computer Graphics

18 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

19 Perspective Projection Example
consider q = Mp where M =  q = p = CS4395: Computer Graphics

20 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

21 OpenGL Orthogonal Viewing
glOrtho(left,right,bottom,top,near,far) near and far measured from camera CS4395: Computer Graphics

22 OpenGL Perspective glFrustum(left,right,bottom,top,near,far)
CS4395: Computer Graphics

23 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

24 Other Issues Hidden surface removal: Section 5.6.
Interactive mesh displays: Section 5.7. CS4395: Computer Graphics


Download ppt "Based on slides created by Edward Angel"

Similar presentations


Ads by Google