6. 3D Perspective
Brock University
COSC 3P98 Computer Graphics
Instructor: Brian Ross
Viewing 3D graphics: Terms
- world coordinates: coordinate system used by application model
-
- world coordinate window: area of world coordinates to draw
-
- screen (device) coordinates: pixel coordinates used by terminal,
plotter, ...
-
- viewport: area of graphics window to map world coordinate window into
- note: also have "window coordinates" in windowing GUI; we'll
assume that device screen is our OpenGL window we're drawing into
- viewport is an area of your OpenGL window
- can specify such using OpenGL's "glViewport" command
- clipping: drawing images that reside within viewport, and ignoring
images outside the viewport
Viewing 3D
- to draw 3D objects, we need to project them onto a 2D surface, which
can be displayed by our 2D graphics hardware
- (when holographic displays are created, this topic won't be required!)
- planar geometric projection: transforming a point in 3D space onto
a 2D plane
- can also transform points in 4D, 5D etc (eg. fractals )
- eg. projecting a line segment from 3D space to 2D plane:
- 1. project its 2 endpoints to 2D points that lie on some plane
- 2. draw a line between these two projected endpoints
- technique: project rays from each point in object towards a centre
of projection; (a point in space), and in which there is an intervening
projection plane between object and centre of projection
- where rays pass through projection plane defines the projected image
- different projections are derined by putting plane and centre of proj.
at different locations
Viewing 3D
- centre of projection is often the viewer's eye, camera eye, etc.
- projection plane is the CRT screen
- non-planar projections possible: project onto spheres, etc.
- 3D drawing steps:
- clip objects in a 3D viewing volume
- defines the extent of coordinate system of interest
- project viewing volume onto a viewing plane (world coord. window)
- transform plane to viewport
- draw viewport on graphics window
![](process.gif)
Main types of planar projections:
- 1. parallel projections: centre of projection is an infinitely far
from object
- preserves lines, distances, angles
- however, unrealistic: lose all depth information (human's don't see
this way)
- 2. perspective projections: centre of projection is a finite distance
from object
- reflects how we see
- yields perspective foreshortening: objects farther away look smaller
- note: approximates what the human eye sees; eyeball is actually spherical,
but brain compensates
![](projections.gif)
Parallel projections
- also called orthographic projections: all projecting rays are parallel
to each other, and orthogonal (perpendicular) to projecting plane
- simple to implement: discard one coordinate from all points
(x, y, z) --> drop z coordinate --> (x, y) : projects onto x-y
plane
- do this with all coordinates in your figure
- straight lines are preserved:
- line seg. (x1, y1, z1), (x2, y2, z2) ---> line seg' (x1, y1), (x2,
y2)
- To get different view, discard different coordinates: simply maps to
x-y, x-z, y-z planes as appropriate (see below)
Parallel projection
![](par_views.gif)
- orientation of axes based on right-handed coordinate conventions
- all sense of depth is lost:
- if you took a 3D object and interactively rotated it on a computer
using orthographic projection, it would look odd
Parallel projection: OpenGL
- Important: make sure you do glMatrixMode(GL_PROJECTION)
before setting up your viewing environment. This permits you to use translations
(glRotate, etc) to help move the camera if desired. Go back to GL_MODELVIEW
before manipulating the model.
- You should first do a glLoadIdentity() to initialize viewing
matrix. Then use glOrtho and others to set up projection scheme.
glOrtho(GLdouble Xmin, Xmax, Ymin, Ymax, Zmin, Zmax)
- intuitively: glOrtho(left, right, bottom, top, near, far)
- this defines a 3D volume: objects (or portions) outside these extents
are clipped, and remaining objects projected to X-Y plane
- Z values (near, far) are taken as being negative: projection plane
is X-Y plane, and we are looking at it from positive Z axis towards negative
Z axis
- gluOrtho2D(GLdouble left, right, top, bottom): 2D equivalent
![](para_proj.gif)
Perspective projection
![](persp_proj.gif)
- This example: eye is on Z axis, and we project onto X-Y plane
- (can do this on any arbitrary eye position and projection plane however)
Perspective
- eye no longer at infinity; we assume object is on opposite side of viewing (XY) plane
- By default in OpenGL, if eye at at (0,0,0), looking down -z, distance d from proj plane, then z < d for all z's in object
- In the following, we simplify setup so that viewing plane is distance d from eye, and P is distance z from eye.
![](persp2b.gif)
y'/d = y/z
or
y' = d*y/z = y*(d/z)
t = d/z <-- perspective factor: multiply it to y's, x's
So... y'= y*t = y*(d/z), x' = x*t = x*(d/z)
| 1 0 0 0 |
Mper = | 0 1 0 0 |
| 0 0 1 0 |
| 0 0 1/d 0 |
ie. P' = Mper * P = (x*(d/z), y*(d/z), d) (d = posn of proj plane on z axis)
- notice:
- (1) when object far from eye, z gets large, perspective factor t=(d/z) approaches 0 --> object coordinates get reduced
- (2) when object close to eye, z approaches d, (d/z) approaches 1,
and t has less effect --> object projected larger on viewing plane
- (3) when eye close to proj plane, d approaches 0, (d/z) gets small,
and t perspective effect is exaggerated (like wide angle lens)
- (4) when eye far from proj plane, d is large, (d/z) is large, z-effect not as relevant, and t
perspective effect is not as pronounced (like telephoto lens); approaches
orthographic projection (t has no effect)
Perspective
- when point is far from eye, (large "-Z"), then t is a small
fraction, and this creates small y', x' (approach a vanishing point
in the distance)
- Net effect is that object coordinates are 'shrunk', and object appears small
- points near the plane (Z=0) project onto the plane fairly directly
- points near the eye ("+X"), then t' gets large, and Y, X
get large as well
- OpenGL: as above, projects onto XY plane, and we look towards negative
Z axis
- note that, if the eye moves farther away towards infinity, z/E approaches
0, and t' approaches 1: this is orthographic projection
![](persp3.gif)
Projection example
- Let eye be at (0, 0, 0), proj plane at (0, 0, -1), ie. d=-1, and eye looking down -Z axis
Point |
World coords |
Orthographic coords |
Perspective factor t |
Perspective coords |
A |
(2,1,-1) |
(2,1) |
1.0 |
(2,1) |
B |
(2,1,-10) |
(2,1) |
0.1 |
(0.2, 0.1) |
C |
(2,1,-100) |
(2,1) |
0.01 |
(0.02, 0.01) |
D |
(2,-5,-100) |
(2,-5) |
0.01 |
(0.02, -0.05) |
E |
(-50,-50,-100) |
(-50,-50) |
0.01 |
(-0.5, -0.5) |
- Vanishing point: Lim(z -> -inf) (d/z) = 0
- therefore: x' = x*t = x*0 = 0, y' = 0 --> vanishing point is (0,0)
- Example animation showing effect of changing distance between eye/camera and projection plane (from Wikipedia
![](Contra-zoom_aka_dolly_zoom_animation.gif)
- Another example using a zoom lens.
Perspective: OpenGL
![](GL_persp1.gif)
![](fustrum.gif)
- 4 planes: left, right, top, bottom, near, far
- defines a pyramid with its top shaved off: "frustum"
Perspective: OpenGL
gluPerspective(GLdouble fovy, aspect, zNear, zFar)
- fovy: field of view - angle made by top and bottom of clipping
glass
- aspect ratio: ratio of glasses X dimension to Y dimension (XD / YD)
- typically same as window dimension ratio: use glutGet(GLUT_WINDOW_WIDTH/HEIGHT) to find
it
- (same as what you set with prefsize)
- eg. square window --> aspect=1.0
- znear, zfar - distance to near and far clipping planes
- bigger fovy: movie eye close to plane, so effects of perspective increase
Moving the eye in OpenGL
1. Move the camera manually
- instead of manipulating your graphics image, you can move your eye
around it
- use glRotate, glTranslate, and other transformations
to manually move your eye to desired location.
- both operations use same transformation matrix operations (but opposite
directions)
- Do such transformations while in glMatrixMode(GL_MODELVIEW)
and initialize with glLoadIdentity()
Moving eye in OpenGL
2. gluLookAt(GLdouble eyeX, eyeY, eyeZ, centerX, centerY, centerZ,
upX, upY, upZ)
- eyeX, eyeY, eyeZ: eye coordinate (viewing position)
- centerX, centerY, centerZ: a point along line of sight
- upX, upY, upZ: direction of "up" (normal from bottom to top
of viewing volume)
![](local/lookat.gif)
Example OpenGL Program
- Click here.
- Note how cube's far corner is clipped within viewing volume...
![](cube_persp.gif)
References
- OpenGL Programming Guide, OpenGL ARB, Addison-Wesley 1993,
ISBN 0-201-63274-8. (chapter 3)
Back
to COSC 3P98 index
COSC 3P98 Computer Graphics
Brock University
Dept of Computer Science
Copyright © 2023 Brian J. Ross
(Except noted figures).
http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/3d_perspective/
Last updated: March 9, 2023