0% found this document useful (0 votes)
35 views

Lecture07 p1

This document summarizes key concepts about 3D projection covered in Lecture 7 of CS 543: Computer Graphics. It discusses different types of projection like perspective, orthographic, and parallel projection. It explains important projection parameters like field of view, near and far clipping planes. It provides details on how to implement perspective and orthographic projections using OpenGL functions like gluPerspective, glFrustum, and glOrtho.

Uploaded by

Bonie Labadan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Lecture07 p1

This document summarizes key concepts about 3D projection covered in Lecture 7 of CS 543: Computer Graphics. It discusses different types of projection like perspective, orthographic, and parallel projection. It explains important projection parameters like field of view, near and far clipping planes. It provides details on how to implement perspective and orthographic projections using OpenGL functions like gluPerspective, glFrustum, and glOrtho.

Uploaded by

Bonie Labadan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

CS 543: Computer Graphics

Lecture 7 (Part I): Projection

Emmanuel Agu
3D Viewing and View Volume

n Recall: 3D viewing set up


Projection Transformation

n View volume can have different shapes (different looks)


n Different types of projection: parallel, perspective,
orthographic, etc
n Important to control
n Projection type: perspective or orthographic, etc.
n Field of view and image aspect ratio
n Near and far clipping planes
Perspective Projection

n Similar to real world


n Characterized by object foreshortening
n Objects appear larger if they are closer to camera
n Need:
n Projection center
n Projection plane
n Projection: Connecting the object
to the projection center
camera

projection plane
Projection?

Projectors

Object in 3 space

Projected image

VRP
COP
Orthographic Projection

n No foreshortening effect – distance from camera does not


matter
n The projection center is at infinite
n Projection calculation – just drop z coordinates
Field of View

n Determine how much of the world is taken into the picture


n Larger field of view = smaller object projection size

center of projection
field of view
(view angle)
y y

z θ z

x
Near and Far Clipping Planes

n Only objects between near and far planes are drawn


n Near plane + far plane + field of view = Viewing Frustum

Near plane Far plane


y

x
Viewing Frustrum

n 3D counterpart of 2D world clip window


n Objects outside the frustum are clipped

Near plane Far plane


y

Viewing Frustum
Projection Transformation

n In OpenGL:
n Set the matrix mode to GL_PROJECTION
n Perspective projection: use
• gluPerspective(fovy, aspect, near, far) or
• glFrustum(left, right, bottom, top, near, far)
n Orthographic:
• glOrtho(left, right, bottom, top, near, far)
gluPerspective(fovy, aspect, near, far)

n Aspect ratio is used to calculate the window width

y y w
fovy
z
z
h
eye
x
Aspect = w / h near far
glFrustum(left, right, bottom, top, near, far)

n Can use this function in place of gluPerspective()

left top

x
right
bottom

near far
glOrtho(left, right, bottom, top, near, far)

n For orthographic projection

top
left
y

bottom right

near
far
Example: Projection Transformation

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fovy, aspect, near, far);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,1,0,0,0,0,1,0);
display_all(); // your display routine
}
Demo

n Nate Robbins demo on projection


Projection Transformation

n Projection – map the object from 3D space to 2D


screen

y y

z z

x x

Perspective: gluPerspective() Parallel: glOrtho()


Parallel Projection

n After transforming the object to the eye space, parallel


projection is relatively easy – we could just drop the Z
n Xp = x
n Yp = y
n Zp = -d
(Xp, Yp)

n We actually want to keep Z


– why?
y
(x,y,z)
z
x
Parallel Projection

n OpenGL maps (projects) everything in the visible


volume into a canonical view volume

(xmax, ymax, far)


(1, 1, -1)

(xmin, ymin, near) (-1, -1, 1)

Canonical View Volume


glOrtho(xmin, xmax, ymin,
ymax,near, far)
Projection: Need to build 4x4 matrix to do
mapping from actual view volume to CVV
Parallel Projection: glOrtho

n Parallel projection can be broken down into two parts


n Translation which centers view volume at origin
n Scaling which reduces cuboid of arbitrary dimensions to
canonical cube (dimension 2, centered at origin)
Parallel Projection: glOrtho

n Translation sequence moves midpoint of view volume to


coincide with origin:
n E.g. midpoint of x = (xmax + xmin)/2
n Thus translation factors:
-(xmax+xmin)/2, -(ymax+ymin)/2, -(far+near)/2
n And translation matrix M1:

1 0 0 − ( x max + x min) / 2 
 
0 1 0 − ( y max + y min) / 2 
0 0 1 − ( z max + z min) / 2 
 
0 
 0 0 1 
Parallel Projection: glOrtho

n Scaling factor is ratio of cube dimension to Ortho view


volume dimension
n Scaling factors:
2/(xmax-xmin), 2/(ymax-ymin), 2/(zmax-zmin)
n Scaling Matrix M2:

 2 
 0 0 0
 x max − x min 
 0
2
0 0
 y max − y min 
 2 
 0 0 0
 z max − z min 
 0 0 0 1
Parallel Projection: glOrtho

Concatenating M1xM2, we get transform matrix used by glOrtho

 2  1 0 0 − ( x max + x min) / 2 
 0 0 0
 x max − x min   
 2
0 0 1 0 − ( y max + y min) / 2 


0
y max − y min
0


X 0 0 1 − ( z max + z min) / 2 

2
0  
0 0
z max − z min 0 
 
1   0 0 1 
 0 0 0

 2 /( x max − x min) 0 0 − ( x max + x min) /( x max − x min) 


 
 0 2 /( y max − y min) 0 − ( y max + min) /( y max − min) 
M 2 × M1 = 
0 0 2 /( z max − z min) − ( z max + z min) /( z max − z min) 
 
 
 0 0 0 1 

Refer: Hill, 7.6.2


Perspective Projection: Classical

n Side view: y
z
x
Projection plane
y (x,y,z)
Based on similar triangle:
(x’,y’,z’)
(0,0,0) y -z
=
z y’ d
d
d
-z y’ = y x
-z
Eye (projection center)
Perspective Projection: Classical

n So (x*,y*) the projection of point, (x,y,z) unto the near


plane N is given as:
 Px Py 
(x*, y *) =  N ,N 
 − Pz − Pz 

n Numerical example:
Q. Where on the viewplane does P = (1, 0.5, -1.5) lie for a
near plane at N = 1?

n (x*, y*) = (1 x 1/1.5, 1 x 0.5/1.5) = (0.666, 0.333)


Pseudodepth

n Classical perspective projection projects (x,y) coordinates,


drops z coordinates
n But we need z to find closest object (depth testing)
n Keeping actual distance of P from eye is cumbersome and
slow
dis tan ce = (P
x
2
+ Py + Pz
2 2
)
n Introduce pseudodepth: all we need is measure of which
objects are further if two points project to same (x,y)
 Px Py aPz + b 
(x*, y*, z *) =  N ,N , 
 − Pz − Pz − Pz 

n Choose a, b so that pseudodepth varies from –1 to 1


(canonical cube)
Pseudodepth

n Solving: aPz + b
z* =
− Pz

n For two conditions, z* = -1 when Pz = -N and z* = 1 when


Pz = -F, we can set up two simultaneuous equations
n Solving:

− (F + N ) − 2 FN
a= b=
F−N F−N
Homogenous Coordinates

n Would like to express projection as 4x4 transform matrix


n Previously, homogeneous coordinates of the point P =
(Px,Py,Pz) was (Px,Py,Pz,1)
n Introduce arbitrary scaling factor, w, so that P = (wPx,
wPy, wPz, w) (Note: w is non-zero)
n For example, the point P = (2,4,6) can be expressed as
n (2,4,6,1)
n or (4,8,12,2) where w=2
n or (6,12,18,3) where w = 3
n So, to convert from homogeneous back to ordinary
coordinates, divide all four terms by last component and
discard 4th term
Perspective Projection

n Same for x. So we have:


x’ = x x d / -z
y’ = y x d / - z
z’ = -d
n Put in a matrix form:

1

0 0 0  x  
  
x' 
 −d x
 ( ) 
z
 
0 1 0 0  y   y'  − d  y  
0 0 1 0  z  
=
z'  ⇒   z 


0

0 (1 − d )   
1   1   −
 z/d






−d
1


OpenGL assumes d = 1, i.e. the image plane is at z = -1


Perspective Projection

n We are not done yet.

n Need to modify the projection matrix to include a and b

x’ 1 0 0 0 x
y’ = 0 1 0 0 y
z’ 0 0 a b z y
w 0 0 (1/-d) 0 1 z
x
We have already solved a and b Z=1 z = -1
Perspective Projection

n Not done yet. OpenGL also normalizes the x and y


ranges of the viewing frustum to [-1, 1] (translate and
scale)
n So, as in ortho to arrive at final projection matrix
n we translate by
n –(xmax + xmin)/2 in x
n -(ymax + ymin)/2 in y
n Scale by:
n 2/(xmax – xmin) in x
n 2/(ymax – ymin) in y
Perspective Projection

n Final Projection Matrix:


 2N x max + x min 
 0 0 
 x max − x min x max − x min 
 y max + y min
0 
2N
0
 y max − y min y max − y min 
 − (F + N ) − 2 FN 
 0 0 
 F−N F−N 
 0 0 −1 0 

glFrustum(xmin, xmax, ymin, ymax, N, F) N = near plane, F = far plane


Perspective Projection

n After perspective projection, viewing frustum is also


projected into a canonical view volume (like in parallel
projection)

(1, 1, -1)
y

x (-1, -1, 1)

Canonical View Volume


References

n Hill, chapter 7

You might also like