Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Outline: 3D to 2D Projection

• Projection in computer graphics. • Gets a bit mathematical (but not for a while).

• Types of projection. • Central to computer graphics.

• Viewing in OpenGL.
3D world
Project onto Transform to
coordinate Clip against 2D device
projection 2D device
output view volume coordinates
plane coordinates
primitives

• Already dealt with transformation to device coordinates.

General projections General projections

pro pro
jecti jecti
A on C
on
plan
e
plan
e • Convert an nD coordinate system into a mD coordinate system:
C*
in computer graphics n = 3 and m = 2.
A*
B D

s
• We consider planar geometric projections – we project onto a
rs B* tor
to jec
pr
o jec pro
D* plane.
to
inf

centre of projection
• Projections can be visualised using projectors which emanate
ini
ty

from the centre of the projection.

• Perspective foreshortening is important to realism but results in • The centre of projection is generally at a finite distance from the
distortion of angles, distances and parallel lines. projection plane but is sometimes defined at infinity.

• Parallel projections also distort angles, but maintain parallelism • Easy to implement (if not understand) using homogeneous
and distances. coordinates.

Defining a plane? Defining a plane?

• We need to define the projection plane – how can this be done? • Most simple is to define a point in the projection plane, and then
two vectors, one for up and one for across.
pro pro
jecti jecti
on A on C
plan plan
e e
• This allows us to define any (all) points in the plane.
C*
A*
B D
• For computer graphics we normal give a point, a vector to
to
rs B*
ec
tor
s
define up and a normal vector to the plane (which is the cross
o jec proj D*
pr product of the up and across vectors).
to
inf

centre of projection
ini

• Concept of normal vectors is very important in computer


ty

graphics.

Perspective projections 2 point perspective projections


y
y

Projection
plane

z
Projection plane
x x

Center of
projection
z x-axis vanishing point z-axis vanishing point

Projection
plane
Center of projection
normal

• The number of axis vanishing points will depend on the number


• In a perspective projection all parallel lines that are not parallel of axes cut by the projection plane – two point projections look
to the projection plane appear to go to a vanishing point. realistic.
Parallel projections Parallel projections

• Parallel orthographic projections have the direction of the • Axonometric orthographic projections are parallel projections
projection parallel to the normal to the projection plane: that use projection planes that are not normal to the principal
Projection
axes.
plane
(top view)
Projection
Projectors for plane
side view

Projectors y
for top view Projector

Projection
plane
Projectors for (side view) Projection-
front view plane x
Projection
normal
plane
(front view) z

Parallel projections Viewing in OpenGL

• In oblique projection the projection plane normal and direction of • OpenGL viewing definition uses the camera analogy.
projection differ.
• Two matrices define the total projection:
Projection y
plane
• GL PROJECTION defines the projection using the matrices:
M Sper Hpar as given in the notes.

• Use the command glFrustum to set the viewing parameters.

• Define the viewing window (xmin, ymin and xmax, ymax), and the
Projector x
z near and far clipping planes.

• Think of this like the lens of a camera.


Projection-plane
normal

Viewing in OpenGL Practical viewing in OpenGL

• The other matrix to set is the GL MODELVIEW matrix which • Easy to get lost in space: keep the far clipping plane to a large
controls both the objects and the view. value – changing the near clipping plane changes the degree of
perspective distortion.
• Use gluLookAt with the eye, location to look at and up vector to
define the view of the object. • Use asymmetric (xmin, ymin and xmax, ymax) to achieve false
perspective – make VPN non-parallel to DOP.
• This is like the matrices Spar Tpar as given in the notes.
• Start with a large front clipping plane: (xmin, ymin and
• Think of this like aiming the camera. xmax, ymax) – then focus in on the object.

• Set the viewport using glViewPort and give the origin and width
/ height (keep the same as the aspect ratio of the front clipping
plane.

• If it ain’t broke don’t fix it!

Viewing in OpenGL Viewing in OpenGL

• The OpenGL viewing pipeline looks like: • Can also use parallel projections: use glOrtho to set the
perspective projection matrix.
x division window x’
model
y projection to y’
view /w
z
matrix
matrix viewport • The model view matrix is set in the same way as before.
w Screen
Coordinates
Canonical
World Eye Clip
Coordinates Coordinates Coordinates
View • Use glLoadMatrix to define our own projection matrices
Volume
(masochists only).
• For both projection and model view matrices use glMatrixMode to
• Beware the difference between modelling and viewing
define which to use and then don’t forget to initialise them using
transformations.
glLoadIdentity.
• Viewing transformations are always set first in the code, since
they are applied last to the animated models.
Summary

• Having finished this lecture you should:

– understand what projection is in computer graphics;

– compare perspective and parallel projections;

– understand the applications of the different types of


projections;

– define appropriate projections in OpenGL.

• We will next look at how projection is handled mathematically!

You might also like