You are on page 1of 15

COSC4328/5327 Computer Graphics 2

Objectives
• Introduce the classical views
• Compare and contrast image formation by computer with
how images have been formed by architects, artists, and
CLASSICAL VIEWING engineers
• Learn the benefits and drawbacks of each type of view
Slides modified from Angel book 6e

COSC4328/5327 Computer Graphics 4

Introduction
A painting [the projection plane] is the intersection of a visual pyramid
Classical Viewing
[view volume] at a given distance, with a fixed center [center of
projection] and a defined position of light, represented by art with lines • Viewing requires three basic elements
and colors on a given surface [the rendering]. (Alberti, 1435) • One or more objects
• A viewer with a projection surface
• Projectors that go from the object(s) to the projection surface
• Classical views are based on the relationship among these
elements
• The viewer picks up the object and orients it how she would
like to see it
• Each object is assumed to constructed from flat principal
faces
• Buildings, polyhedra, manufactured objects

Hans Vredeman de Vries: Perspektiv 1604

COSC4328/5327 Computer Graphics 5 COSC4328/5327 Computer Graphics 6

Planar Geometric Projections Classical Projections


• Standard projections project onto a plane
• Projectors are lines that either
• converge at a center of projection
• are parallel
• Such projections preserve lines
• but not necessarily angles
• Nonplanar projections are needed for applications such as
map construction
projection
surface/
view plane

center of
projection rays/
projection
projectors
COSC4328/5327 Computer Graphics 7 8 COSC4328/5327 Computer Graphics

Taxonomy of Planar Geometric Projections


Perspective vs Parallel
• Classical viewing developed
planar geometric projections
different techniques for drawing
each type of projection
• For graphics all projections done
same way using a single pipeline parallel perspective
• Fundamental distinction between
parallel and perspective viewing
• even though mathematically parallel
viewing is the limit of perspective 1 point 2 point 3 point
viewing multiview axonometric oblique
orthographic

isometric dimetric trimetric

COSC4328/5327 Computer Graphics 10

Classification of Planar Projections Parallel Projections


planar projections
• cop at infinity
parallel perspective • projectors are parallel
• no foreshortening
orthographic oblique one-point • distant objects do not look smaller

axonometric cabinet two-point • parallel lines remain parallel


top
• parallel projection subtypes
front isometric other cavalier other three-point
• depending on angles between vpn and dop
side • depending on dop and coordinate axes

• many historical names…


• same math in the end 

11 COSC4328/5327 Computer Graphics 12 COSC4328/5327 Computer Graphics

Orthographic Projection Multiview Orthographic Projection


Projectors are orthogonal to projection • Projection plane parallel to
surface principal face
Special Cases
top/side/front projections: • Usually form front, top, side
view plane is views isometric (not multiview
perpendicular to one of orthographic view)
front
the X,Y,Z axes
dop is identical to one
of the X,Y,Z axes CAD & architecture
angles are maintained often display 3
used in architecture & civil views plus isometric
engineering
top side
13 COSC4328/5327 Computer Graphics 14 COSC4328/5327 Computer Graphics

Advantages and Disadvantages Axonometric Projections


• Preserves both distances and angles Allow projection plane to move relative to object
• Shapes preserved
• Can be used for measurements
• Building plans
• Manuals
• Cannot see what object really looks like because many
surfaces hidden from view classify by how many angles of
• Often we add the isometric a corner of a projected cube are
the same
q1
none: trimetric q2 q3
two: dimetric
three: isometric

15 COSC4328/5327 Computer Graphics 16 COSC4328/5327 Computer Graphics

Types of Axonometric Projections


Oblique Projection
Arbitrary relationship between projectors and
projection plane

• Lines are scaled (foreshortened) but can find scaling factors


• Lines preserved but angles are not
• Projection of a circle in a plane not parallel to the projection plane is an ellipse
• Can see three principal faces of a box-like object
• Some optical illusions possible
• Parallel lines appear to diverge
• Does not look real because far objects are scaled the same as
near objects
• Used in CAD applications

18 COSC4328/5327 Computer Graphics

Oblique Parallel Projections Subtypes Advantages and Disadvantages


• Cavalier projection: 45° angle between dop and vpn • Can pick the angles to emphasize a particular face
• Cabinet projection: 63.4° (=arctan(2)) angle between dop • Architecture: plan oblique, elevation oblique
and vpn; z-lengths shorter by ½ • Angles in faces parallel to projection plane are
• these are not perspective projections! preserved while we can still see “around” side

• In physical world, cannot create with simple


camera; possible with bellows camera or special
lens (architectural)

Cavalier projection Cabinet projection


COSC4328/5327 Computer Graphics 19 20 COSC4328/5327 Computer Graphics

Perspective Projection Three-Point Perspective


• Projectors converge at center of projection (camera) • No principal face parallel to projection plane
• COP not at infinity
• Three vanishing points for cube
• Parallel lines are not preserved
• The meet at vanishing points
• Drawing simple perspectives by hand uses these vanishing
point(s)

vanishing point

21 COSC4328/5327 Computer Graphics 22 COSC4328/5327 Computer Graphics

Two-Point Perspective One-Point Perspective


• On principal direction parallel to projection plane • One principal face parallel to projection plane
• Two vanishing points for cube • One vanishing point for cube

23 COSC4328/5327 Computer Graphics

Advantages and Disadvantages Perspective Projection: Vanishing Points


• Objects further from viewer are projected smaller • how many vanishing points maximum?
than the same sized objects closer to the viewer
(diminution)
• Looks realistic

• Equal distances along a line are not projected into


equal distances (nonuniform foreshortening)
• Angles preserved only in planes parallel to the
projection plane
• More difficult to construct by hand than parallel
projections (but not more difficult by computer)
Perspective Projection: Vanishing Points Perspective Projections
• consider a simple object: cube with three sets of • for our cube example:
parallel lines • three vanishing points if view plane intersects all coordinate axes

• consider the view plane position w.r.t. X,Y,Z axes • two if only two axes are intersected
• one if only one axis is intersected

• for a general object


• as many vanishing points as sets of parallel lines (for a natural
scene, infinitely many)

COSC4328/5327 Computer Graphics 27 COSC4328/5327 Computer Graphics 28

Objectives
• Introduce the mathematics of projection
• Introduce viewing in OpenGL
• Look at alternate viewing APIs

COMPUTER VIEWING

COSC4328/5327 Computer Graphics 29

Computer Viewing Model-View Transformation


• Rendering pipeline takes us from model to final image • input:
• Viewing • object definitions
 cos  0 sin  0
(including lights etc.)  
• model-view matrix  0
  sin 
1 0 0
0 cos  0
• Positioning the camera or arrange model w.r.t camera • object transformations 
 0

1 
 0 0

• Need a camera coordinate system (eye/camera space) • camera position & parameters
• projection matrix • problem:
• Selecting a lens • how to arrange objects in space,
• Need a complete camera model where we want them to be?
• Clipping
• Setting the view volume
Model-View Transformation Model-View Transformation
• 1st idea: transform all objects and camera into one world • 2nd idea: transform objects directly into camera (also called
coordinate system y eye) coordinates
y y
(½√2, ½√2)
(5+½√2, 1+½√2)
y (½√2, ½√2)
(7+½√2, ½√2)

x
x x
(-2, 1) z object (0, 0)
x coordinate z camera (eye) z object
world system coordinate coordinate
z coordinate system system
system
• combine model and view transformation in a single model-
view transformation

Perspective Projections: Camera Model Perspective Projections: Camera Model


• mimics real cameras • simplified camera model in CG
• real camera parameters • position: 3D point (= cop)
• position, orientation
• view direction: 3D vector (= vpn)
• aperture
• shutter time • image area on view plane: viewport
• focal length • clipping planes for removing near and far objects
• type of lens (zoom vs. wide)
y
• depth of field COP
• size of resulting image -z = vpn
• aspect ratio (4:3, 16:9, 1.85:1, 2.35:1, 2.39:1)
• resolution (digital cameras) x view
plane near
clipping far
plane clipping
plane

35 COSC4328/5327 Computer Graphics 36 COSC4328/5327 Computer Graphics

The OpenGL Camera Default Projection


• In OpenGL, initially the object and camera frames are Default projection is orthogonal
the same
• Default model-view matrix is an identity
• The camera is located at origin and points in the clipped out
negative z direction 2
• OpenGL also specifies a default view volume that is a
cube with sides of length 2 centered at the origin
• Default projection matrix is an identity
z=0
COSC4328/5327 Computer Graphics 37 38 COSC4328/5327 Computer Graphics

Moving the Camera Frame Moving Camera back from Origin


• If we want to visualize object with both positive and frames after translation by –d
d>0
negative z values we can either
• Move the camera in the positive z direction default frames
• Translate the camera frame
• Move the objects in the negative z direction
• Translate the world frame
• Both of these views are equivalent and are determined by
the model-view matrix
• Want a translation (Translate(0.0,0.0,-d);)
• d > 0

39 COSC4328/5327 Computer Graphics 40 COSC4328/5327 Computer Graphics

Moving the Camera OpenGL code


• We can move the camera to any desired position by a • Remember that last transformation specified is first to
sequence of rotations and translations be applied
• Example: side view
• Rotate the camera // Using mat.h
// gets passed to shader
• Move it away from origin
• Model-view matrix C = TR
mat4 t = Translate (0.0, 0.0, -d);
mat4 ry = RotateY(90.0);
mat4 m = t*ry;

COSC4328/5327 Computer Graphics 41 42 COSC4328/5327 Computer Graphics

LookAt Other Viewing APIs


LookAt(eye, at, up) • The LookAt function is only one possible API for
positioning the camera
• Others include
• View reference point, view plane normal, view up (PHIGS, GKS-
3D)
• Yaw, pitch, roll
• Elevation, azimuth, twist
• Direction angles

mat4 mv = LookAt(vec4 eye, vec4 at, vec4 up);

glm::vec4 currentPos, direction, up = vec4(0.,1.,0.f,0.);


glm::mat4 model = glm::lookAt(currentPos, currentPos+direction, up);
43 COSC4328/5327 Computer Graphics 44 COSC4328/5327 Computer Graphics

Projections and Normalization Homogeneous Coordinate Representation


• The default projection in the eye (camera) frame is orthogonal default orthographic projection
• For points within the default view volume
xp = x pp = Mp
xp = x yp = y
yp = y zp = 0
zp = 0 wp = 1 1 0 0 0
0 1 0 0
• Most graphics systems use view normalization M= 
• All other views are converted to the default view by transformations 0 0 0 0
that determine the projection matrix  
• Allows use of the same pipeline for all views 0 0 0 1

In practice, we can let M = I and set


the z term to zero later

45 COSC4328/5327 Computer Graphics 46 COSC4328/5327 Computer Graphics

Simple Perspective Perspective Equations


Consider top and side views
• Center of projection at the origin
• Projection plane z = d, d < 0
• d is focal distance

• Projection is:
• Given a point (x, y, z) to be projected
• Find projected point (xp, yp, d)
y (x, y, z)
image x z x
plane Similar triangles    xp  Same for y
xp d z/d
(xp, yp, d)
 x y 
COP
(x p , y p , z p )   , ,d 
 z/d z/d 
(0, 0, 0)
z
focal distance d

Perspective Projections: Math Parallel Projections: Math


• take the projection formulas… • view plane placed into XY plane
• projectors are parallel to Z axis
 x y 
(x p , y p , z p )   , ,d  • hence, z values project to 0
 z/d z/d 
• parallel projection matrix is thus:
• write them as matrix in homogeneous coordinates
1 0 0 0  x   x   x ' 
1 0 0 0  x   x   xp        
       0 1 0 0  y   y   y ' 
NEVER set the
0 1 0 0  y   y 
 y  distance of front
0  
0 0 0  z   0   0 
0      p clipping plane to
0 1 0 z z d
       camera position
      
0 0 1/ d 0  1   z / d  1 to zero!!!
0 0 0 1  1   1   1 
w≠1
divide by w to return from homogenous form
called perspective divide
Other Parallel Projections Other Parallel Projections
• oblique projection matrix • Cavalier projection:  = 45º
 1 0  cos( ) 0  no foreshortening of
 
  cos( )   0 1 sin( ) 0 
1 0 0   cos( )  P lengths in z-direction
1 0 0 0  tan(  )  
1 0
tan(  )
0 0 0 0 0
  sin( )    0 0 
1 
since cos²α + sin²α = 1
0   sin( ) 
0 
0 1 0 0 0 1 0
P  tan(  )  0 1
0 0 0 0 
1   tan(  )
 0  0
 0 0  0
 0 0 0 • Cabinet projection:  = 63.4º
 0 0 1
 sin(  )   
0 1 
1  
0 0 0
 0 0   cos( ) 
1 0 0 foreshortening by 2 of
 2 
sin( ) lengths in z-direction
P  0 1 0
 2 
0 0 0 0 since
 
0 0 0 1 cos²(α/2)+sin²(α/2) = 1/2

52 COSC4328/5327 Computer Graphics

Projections Summary OpenGL Orthogonal Viewing


• encode all projection types as matrices M Ortho(left,right,bottom,top,near,far)
• given a
• camera specification (location, focal distance d)
• 3D point p in the eye coordinate system
• compute the projection p’ = M p
• obtain the final 2D coordinates (x, y) of the projected
point by dividing by the 4th element of the
near and far measured from camera
homogeneous vector p’
• can merge projection and modelview seamlessly
(matrix multiplication) glm::mat4 glm::ortho(
float left, float right,
• extra elements float bottom, float top,
• clipping, hidden surface removal float zNear, float zFar);
glm::mat4 projMat = glm::ortho<GLfloat>( 0.0, w, h, 0.0, 1.0, -1.0 ) );

53 COSC4328/5327 Computer Graphics 54 COSC4328/5327 Computer Graphics

OpenGL Perspective Viewing Using Field of View


Frustum(left,right,bottom,top,near,far) • With Frustum it is often difficult to get the desired view
• Perpective(fovy, aspect, near, far)
often provides a better interface

front plane

aspect = w/h

glm::mat4 glm::frustum( float left, float right,


float bottom, float top, float zNear, float zFar);
glm::mat4 perspective(
float fovy, float aspect, float zNear, float zFar);
COSC4328/5327 Computer Graphics 55 COSC4328/5327 Computer Graphics 56

Example (Similar to rotating Cube) Example (Similar to rotating Cube)


#include "Angel.h" // Viewing transformation parameters
typedef Angel::vec4 color4;
typedef Angel::vec4 point4; GLfloat radius = 1.0;
const int NumVertices = 36; //(6 faces)(2 triangles/face)(3 vertices/triangle) GLfloat theta = 0.0;
point4 points[NumVertices];
color4 colors[NumVertices];
GLfloat phi = 0.0;
point4 vertices[8] = { // axes aligned unit cube centered at origin const GLfloat dr = 5.0 * DegreesToRadians;
point4(-0.5, -0.5, 0.5, 1.0 ), point4(-0.5, 0.5, 0.5, 1.0 ),
point4( 0.5, 0.5, 0.5, 1.0 ), point4( 0.5,-0.5, 0.5, 1.0 ),
point4(-0.5, -0.5, -0.5, 1.0 ), point4(-0.5, 0.5, -0.5, 1.0 ), // model-view matrix uniform shader variable location
point4( 0.5, 0.5, -0.5, 1.0 ), point4( 0.5,-0.5, -0.5, 1.0 ) GLuint model_view;
} // RGBA olors
color4 vertex_colors[8] = {
color4( 0.0, 0.0, 0.0, 1.0 ), // black // Projection transformation parameters
color4( 1.0, 0.0, 0.0, 1.0 ), // red
color4( 1.0, 1.0, 0.0, 1.0 ), // yellow
GLfloat left = -1.0, right = 1.0;
color4( 0.0, 1.0, 0.0, 1.0 ), // green GLfloat bottom = -1.0, top = 1.0;
color4( 0.0, 0.0, 1.0, 1.0 ), // blue GLfloat zNear = 0.5, zFar = 3.0;
color4( 1.0, 0.0, 1.0, 1.0 ), // magenta
color4( 1.0, 1.0, 1.0, 1.0 ), // white
color4( 0.0, 1.0, 1.0, 1.0 ) // cyan // projection matrix uniform shader variable location
};
GLuint projection;

COSC4328/5327 Computer Graphics 57 COSC4328/5327 Computer Graphics 58

Example (Similar to rotating Cube) Example (Similar to rotating Cube)


int Index = 0; // generate 12 tris 36 verts & 36 colors
Void quad( int a, int b, int c, int d ) { void
colors[Index] = vertex_colors[a]; points[Index] colorcube()
= vertices[a]; Index++;
colors[Index] = vertex_colors[b]; points[Index] {
= vertices[b]; Index++; quad( 1, 0, 3, 2 );
colors[Index] = vertex_colors[c]; points[Index]
= vertices[c]; Index++; quad( 2, 3, 7, 6 );
colors[Index] = vertex_colors[a]; points[Index] quad( 3, 0, 4, 7 );
= vertices[a]; Index++;
colors[Index] = vertex_colors[c]; points[Index] quad( 6, 5, 1, 2 );
= vertices[c]; Index++;
colors[Index] = vertex_colors[d]; points[Index] quad( 4, 5, 6, 7 );
= vertices[d]; Index++; quad( 5, 4, 0, 1 );
}
}

COSC4328/5327 Computer Graphics 59 COSC4328/5327 Computer Graphics 60

Init - Setup OpenGL Init - Setup OpenGL - cont


void init() { // Load shaders and use the resulting shader program
colorcube(); GLuint program = InitShader( "vshader41.glsl",
GLuint vao; "fshader41.glsl" );
// Create a vertex array object glUseProgram( program );
// set up vertex arrays
glGenVertexArrays( 1, &vao );
GLuint vPosition =glGetAttribLocation(program,"vPosition" );
glBindVertexArray( vao ); glEnableVertexAttribArray( vPosition );
GLuint buffer; glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE,
0, BUFFER_OFFSET(0) );
// Create and initialize a buffer object GLuint vColor = glGetAttribLocation( program, "vColor" );
glGenBuffers( 1, &buffer ); glEnableVertexAttribArray( vColor );
glBindBuffer( GL_ARRAY_BUFFER, buffer ); glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0,
glBufferData( GL_ARRAY_BUFFER, sizeof(points) + BUFFER_OFFSET(sizeof(points)) );
sizeof(colors), NULL, GL_STATIC_DRAW ); model_view = glGetUniformLocation( program, "model_view" );
glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), projection = glGetUniformLocation( program, "projection" );
points ); glEnable( GL_DEPTH_TEST );
glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), glClearColor( 1.0, 1.0, 1.0, 1.0 );
sizeof(colors), colors ); }
COSC4328/5327 Computer Graphics 61 COSC4328/5327 Computer Graphics 62

Display function Keyboard func – camera interaction


void display( void ) void keyboard( unsigned char key, int x, int y ) {
{ switch( key ) {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); case 033: // Escape Key
case 'q': case 'Q': exit( EXIT_SUCCESS ); break;
case 'x': left *= 1.1; right *= 1.1; break;
point4 eye( radius*sin(theta)*cos(phi),
case 'X': left *= 0.9; right *= 0.9; break;
radius*sin(theta)*sin(phi), The reshape case 'y': bottom *= 1.1; top *= 1.1; break;
radius*cos(theta), function is a really case 'Y': bottom *= 0.9; top *= 0.9; break;
1.0 ); case 'z': zNear *= 1.1; zFar *= 1.1; break;
point4 at( 0.0, 0.0, 0.0, 1.0 );
good place to put
case 'Z': zNear *= 0.9; zFar *= 0.9; break;
vec4 up( 0.0, 1.0, 0.0, 0.0 ); this, unless want case 'r': radius *= 2.0; break;
user interaction as case 'R': radius *= 0.5; break;
mat4 mv = LookAt( eye, at, up ); case 'o': theta += dr; break;
in this program. case 'O': theta -= dr; break;
glUniformMatrix4fv( model_view, 1, GL_TRUE, mv );
case 'p': phi += dr; break;
case 'P': phi -= dr; break;
mat4 p = Ortho( left, right, bottom, top, zNear, zFar ); case ' ': // reset values to their defaults
glUniformMatrix4fv( projection, 1, GL_TRUE, p ); left = -1.0; right = 1.0;
bottom = -1.0; top = 1.0;
glDrawArrays( GL_TRIANGLES, 0, NumVertices ); zNear = 0.5; zFar = 3.0;
radius = 1.0;theta = 0.0; phi = 0.0;
glutSwapBuffers(); break;
} }
glutPostRedisplay();
}

COSC4328/5327 Computer Graphics 63 COSC4328/5327 Computer Graphics 64

Reshape function main


int main( int argc, char **argv ) {
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
void glutInitWindowSize( 512, 512 );
glutInitContextVersion( 3, 2 );
reshape( int width, int height ) glutInitContextProfile( GLUT_CORE_PROFILE );
{ glutCreateWindow( "Color Cube" );

glViewport( 0, 0, width, height ); glewInit();

} init();

glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glutReshapeFunc( reshape );

glutMainLoop();
return 0;
}

COSC4328/5327 Computer Graphics 65 COSC4328/5327 Computer Graphics 66

Vertex Shader Pixel Shader


#version 150
#version 150

in vec4 vPosition; in vec4 color;


in vec4 vColor;
out vec4 color;
out vec4 fColor;

uniform mat4 model_view; void main()


uniform mat4 projection;
{
void main() fColor = color;
{
gl_Position = }
projection*model_view*vPosition/vPosition.w;
color = vColor;
}
COSC4328/5327 Computer Graphics 67 68 COSC4328/5327 Computer Graphics

Objectives

• Derive the projection matrices used for standard


OpenGL projections
• Introduce oblique projections
• Introduce projection normalization

PROJECTION MATRICES

69 COSC4328/5327 Computer Graphics 70 COSC4328/5327 Computer Graphics

Normalization Pipeline View


• Rather than derive a different projection matrix for each
type of projection, we can convert all projections to
orthogonal projections with the default view volume modelview projection perspective
transformation transformation division
• This strategy allows us to use standard transformations in
the pipeline and makes for efficient clipping 4D  3D
nonsingular
(invertable)

clipping projection

3D  2D
against default cube

71 COSC4328/5327 Computer Graphics 72 COSC4328/5327 Computer Graphics

Orthogonal Normalization
Notes
• We stay in four-dimensional homogeneous coordinates Ortho(left,right,bottom,top,near,far)
through both the modelview and projection
transformations
normalization  find transformation to convert
• Both these transformations are nonsingular
specified clipping volume to default
• Default to identity matrices (orthogonal view)
• Normalization lets us clip against simple cube regardless
of type of projection
• Delay final projection until end
• Important for hidden-surface removal to retain depth information
as long as possible
73 COSC4328/5327 Computer Graphics 74 COSC4328/5327 Computer Graphics

Orthogonal Matrix Final Projection


• Two steps • Set z =0
• Move center to origin
• Equivalent to the homogeneous coordinate
T(-(left+right)/2, -(bottom+top)/2,(near+far)/2))
transformation
• Scale to have sides of length 2
1 0 0 0
S(2/(left-right),2/(top-bottom),2/(near-far)) 0 1 0 0
Morth = 
0 0 0 0
 2 right  left   
 right  left 0 0 
right  left  0 0 0 1
 
 2 top  bottom 
0 0 
P = ST =  top  bottom top  bottom 
 far  near 
 0 0
2
 • Hence, general orthogonal projection in 4D is
 near  far far  near 
P = MorthST
 0 0 0 1 

75 COSC4328/5327 Computer Graphics 76 COSC4328/5327 Computer Graphics

Oblique Projections General Shear


• The OpenGL projection functions cannot
produce general parallel projections such as

• However if we look at the example of the


cube it appears that the cube has been
sheared
• Oblique Projection = Shear + Orthogonal top view
Projection side view

77 COSC4328/5327 Computer Graphics 78 COSC4328/5327 Computer Graphics

Shear Matrix Equivalency


xy shear (z values unchanged)

1 0  cot θ 0
 1  cot φ 0
H(q,f) = 0
0 0 1 0
 
Projection matrix 0 0 0 1

General case:
P = Morth H(q,f)

P = Morth STH(q,f)
79 COSC4328/5327 Computer Graphics 80 COSC4328/5327 Computer Graphics

Effect on Clipping Simple Perspective


• The projection matrix P = STH transforms the original Consider a simple perspective with the COP at the
clipping volume to the default clipping volume origin, the near clipping plane at z = -1, and a 90
degree field of view determined by the planes
object top view z= 1 x = z, y = z

DOP
DOP
x = -1
x=1
far plane
z = -1
clipping near plane
volume distorted object
(projects correctly)

81 COSC4328/5327 Computer Graphics 82 COSC4328/5327 Computer Graphics

Perspective Matrices Generalization


Simple projection matrix in homogeneous coordinates 1 0 0
0
0 1 0
0
N= 
1 0 0
0 0 0 α β
0  
M=  1 0 0 0 0  1 0
0 0 1 0
  after perspective division, the point (x, y, z, 1) goes to
0 0  1 0
x’’ = x/z
Note that this matrix is independent of the far clipping plane y’’ = y/z
Z’’ = -(+/z)
which projects orthogonally to the desired point
regardless of  and 

83 COSC4328/5327 Computer Graphics 84 COSC4328/5327 Computer Graphics

Picking  and  Normalization Transformation


If we pick
distorted object
near  far
= projects correctly
far  near
2near  far
=
near  far

the near plane is mapped to z = -1


the far plane is mapped to z =1 original clipping
and the sides are mapped to x =  1, y =  1 volume
original object new clipping
volume
Hence the new clipping volume is the default clipping volume
COSC4328/5327 Computer Graphics 85 86 COSC4328/5327 Computer Graphics

Normalization and Hidden-Surface


OpenGL Perspective
Removal
• Although our selection of the form of the • glFrustum allows for an unsymmetric viewing frustum
perspective matrices may appear somewhat (although Perspective does not)
arbitrary, it was chosen so that if z1 > z2 in the
original clipping volume then for the transformed
points z1’ > z2’
• Thus hidden surface removal works if we first apply
the normalization transformation
• However, the formula z’’ = -(+/z) implies that the
distances are distorted by the normalization which
can cause numerical problems especially if the
near distance is small

87 COSC4328/5327 Computer Graphics 88 COSC4328/5327 Computer Graphics

OpenGL Perspective Matrix


Why do we do it this way?
• The normalization in Frustum requires an initial shear • Normalization allows for a single pipeline for both
to form a right viewing pyramid, followed by a scaling to get perspective and orthogonal viewing
the normalized perspective volume. Finally, the perspective • We stay in four dimensional homogeneous coordinates as
matrix results in needing only a final orthogonal long as possible to retain three-dimensional information
transformation needed for hidden-surface removal and shading
• We simplify clipping

P = NSH

our previously defined shear and scale


perspective matrix

You might also like