Download presentation
Presentation is loading. Please wait.
1
CSC461: Lecture 19 Computer Viewing
Objectives Introduce computer views and positioning camera Look at alternate viewing APIs Introduce the mathematics of projection
2
Computer Viewing There are three aspects of the viewing process, all of which are implemented in the pipeline, Positioning the camera Setting the model-view matrix Selecting a lens Setting the projection matrix Clipping Setting the view volume
3
The OpenGL Camera In OpenGL, initially the world and camera frames are the same Default model-view matrix is an identity The camera is located at origin and points in the negative z direction OpenGL also specifies a default view volume that is a cube with sides of length 2 centered at the origin Default projection matrix is an identity
4
Default Projection Default projection is orthogonal clipped out 2 z=0
5
Moving the Camera Frame
If we want to visualize object with both positive and negative z values we can either 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 of these views are equivalent and are determined by the model-view matrix A translation: glTranslatef(0.0,0.0,-d); d > 0
6
Moving Camera back from Origin
default frames frames after translation by –d d > 0
7
Moving the Camera We can 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 Model-view matrix Concatenation of rotation and translation: C = TR OpenGL code: last transformation specified is first applied glMatrixMode(GL_MODELVIEW) glLoadIdentity(); glTranslatef(0.0, 0.0, -d); glRotatef(90.0, 0.0, 1.0, 0.0);
8
Camera Positioning Where the camera is How the camera is oriented
View-reference point (VRP) in the world system How the camera is oriented View-plane normal (VPN): specifying the orientation of the projection plan View-up vector (VUP): specifying the up direction With VRP, VPN and VUP, can build a frame The origin: VRP Three independent vectors: VPN, VUP, and VRN×VUP
9
The LookAt Function Syntax: glLookAt(
The function glLookAt to form the required model-view matrix through a simple interface Syntax: glLookAt( eyex,eyey,eyez, atx,aty,atz, upx,upy,upz) VRP = eye, VPN = at-eye, VUP=up 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.0, 1.0, 0.0)
10
Constructing LookAt View
Create an isometric view of the cube Start with default setting Transformations Rotate about the y-axis -45 degrees Rotate about the x-axis degrees Translate along the z-axis by the distance d Result: C = T(0,0,-d)Rx(35.26)Ry(-45) Equivalent to gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
11
Other Viewing APIs The LookAt function is only one possible API for positioning the camera in OpenGL Others include – not provided by OpenGL View reference point, view plane normal, view up (PHIGS, GKS-3D) Yaw, pitch, roll – flight simulation Elevation, azimuth, twist – rotation about other objects instead of points Direction angles All these viewing can be constructed by specifying concatenation of translation and rotations
12
Orthogonal Projections
The default projection in the eye (camera) frame is orthogonal A special case of parallel projections in which the projectors are perpendicular to the view plane For points within the default view volume xp = x, yp = y, zp = 0
13
Homogeneous Coordinate Representation
pp = Mp xp = x yp = y zp = 0 wp = 1 M = In practice, we can let M = I and set the z term to zero later Normalization 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
14
Simple Perspective Projection
Center of projection at the origin All projectors pass through the origin Simple projection: Projection plane z = d, d < 0 General projection: Projection plane can have any orientation w.r.t. the front
15
Simple Perspective Equations
Consider top and side views xp = yp = zp = d
16
Characteristics Nonlinear equations
Non-uniform foreshortening: the images of objects from the COP are reduced in size compared to the images of objects closer to the COP Can be considered as a transformation of from (x, y, z) to (xp, yp, zp) Preserves lines but not affine Irreversible: because all points along a projector project into the same point
17
Homogeneous Coordinate Form
Consider q = Mp where M transforms p to q M = p = q = Represent points (x, y, z) as (wx, wy, wz, w), w≠0 The difference is the coefficient w When w=1, homogeneous coordinates Can represent a broader class of transformations
18
Perspective Division However w 1, so we must divide by w to return to homogeneous coordinates This perspective division yields the desired perspective equations d/z is the foreshortening factor We will consider the corresponding clipping volume with the OpenGL functions xp = yp = zp = d
19
Projection Pipeline Set the model-view matrix
Apply the projection matrix Perform a perspective division
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.