Docsity

Projection - Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Projection - Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Computer Graphics Projection

3D Viewing and View Volume

n Recall: 3D viewing set up

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

projection plane

camera

Projection?

VRP

COP

Object in 3 space

Projectors

Projected image

Field of View

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

n Larger field of view = smaller object projection size

x

y z

y z θ

field of view (view angle)

center of projection

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

x

y z

Near plane (^) Far plane

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

x

y z

y z fovy eye Aspect = w / h near far

w h

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

n For orthographic projection

x

y z

left

bottom right

top

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

Projection Transformation

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

screen

x

y z x

y z

Perspective: gluPerspective() Parallel: glOrtho()

Parallel Projection

n n After transforming the object to the eye space, parallelAfter transforming the object to the eye space, parallel

projection is relatively easy –projection is relatively easy – we could just drop the Zwe could just drop the Z

n Xp = x n Yp = y n Zp = -d

n We actually want to keep Z

  • why?

x

y z (x,y,z)

(Xp, Yp)

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)/

n Thus translation factors:

-(xmax+xmin)/2, -(ymax+ymin)/2, -(far+near)/

n And translation matrix M1:

0 0 1 ( max min) / 2

0 1 0 ( max min) / 2

1 0 0 ( max min) / 2

z z

y y

x x