Sanjeev Sridharan Université de Toronto Politique, gestion ...
Computer Viewing CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward...
-
Upload
verity-hoover -
Category
Documents
-
view
213 -
download
0
Transcript of Computer Viewing CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward...
Computer Viewing
CS4395: Computer Graphics 1
Mohan SridharanBased on slides created by Edward Angel
Objectives
• Introduce the mathematics of projection.
• Introduce OpenGL viewing functions.
• Look at alternate viewing APIs.
CS4395: Computer Graphics 2
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 3
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 4
Default Projection
• Default projection is orthogonal:
CS4395: Computer Graphics 5
clipped out
z=0
2
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 6
Moving Camera back from Origin
CS4395: Computer Graphics 7
frames after translation by –d d > 0
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 8
OpenGL code
• Remember that last transformation specified is first to be applied!
CS4395: Computer Graphics 9
glMatrixMode(GL_MODELVIEW)glLoadIdentity();glTranslatef(0.0, 0.0, -d);glRotatef(90.0, 0.0, 1.0, 0.0);
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.
CS4395: Computer Graphics 10
glMatrixMode(GL_MODELVIEW):glLoadIdentity();gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0., 1.0. 0.0);
Function: gluLookAt()
glLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz)
CS4395: Computer Graphics 11
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 12
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.
CS4395: Computer Graphics 13
xp xyp y zp = 0
Homogeneous Coordinate Representation
xp = xyp = yzp = 0wp = 1
CS4395: Computer Graphics 14
pp = Mp
M =
1000
0000
0010
0001
• Default orthographic projection:
• In practice, can let M=I and set z term to zero later.
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 15
Simple Perspective Projection
• Center of projection at the origin.• Projection plane z = d, d < 0
CS4395: Computer Graphics 16
Simple Perspective Equations
• Consider top and side views:
CS4395: Computer Graphics 17
xp =
dz
x
/
dz
x
/yp =
dz
y
/zp = d
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 18
w
wz
wy
wx
p
Perspective Projection Example
consider q = Mp where
CS4395: Computer Graphics 19
M =
0/100
0100
0010
0001
d
dz
z
y
x
1
z
y
x
p = q =
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 20
dzdz
yy
dz
xx ppp ,
/,
/
11
/
/
'p
p
p
z
y
x
ddz
ydz
x
q
OpenGL Orthogonal Viewing
glOrtho(left,right,bottom,top,near,far)
CS4395: Computer Graphics 21
near and far measured from camera
OpenGL Perspective
glFrustum(left,right,bottom,top,near,far)
CS4395: Computer Graphics 22
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.
CS4395: Computer Graphics 23
aspect = w/h
front plane
Other Issues
• Hidden surface removal: Section 5.6.
• Interactive mesh displays: Section 5.7.
CS4395: Computer Graphics 24