Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
Graphics 2011/2012, 4th quarter
Lecture 7
Perspective projection
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Perspective
Windowing transforms
Parallel projection
Camera transformation
Perspective projection
Perspective transform
Wrap-up
Perspective
Goal: create 2D images of 3D scenes
Standard approach: linear perspective,
i.e. straight lines in the scene become straight lines in the image
(in contrast to, e.g., fisheye views)
Two important distinctions:
parallel projection
perspective projection
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Perspective
Windowing transforms
Parallel projection
Camera transformation
Perspective projection
Perspective transform
Wrap-up
Parallel projection
Maps 3D points to 2D by moving them along a projection direction
until they hit an image plane
image plane perpendicular to
viewing direction: orthographic
otherwise: oblique
(note: other definitions exist)
Characteristics:
keep parallel lines parallel
preserve size and shape of
planar objects
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Perspective
Windowing transforms
Parallel projection
Camera transformation
Perspective projection
Perspective transform
Wrap-up
Perspective projection
Maps 3D points to 2D by projecting them along lines that pass
trought a single viewpoint until they hit an image plane
distinction between oblique and
non-oblique based on projection
direction at the center of the
image
Characteristics:
objects farther from the
viewpoint naturally become
smaller
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Perspective
Windowing transforms
Parallel projection
Camera transformation
Perspective projection
Perspective transform
Wrap-up
Parallel vs. perspective projection
Perspective projection: more natural and realistic
Parallel: usage in mechanical and architectural drawings
How to get 3D objects perspectively correct on 2D screen?
Note: usually your API takes care of most of this, but it’s
good to know what’s going on behind those function calls
And it’s a good opportunity to improve your maths skills ;)
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
Perspective projection
How to get 3D objects perspectively correct on 2D screen?
This task is best solved by splitting it in subtasks
that in turn can be solved by matrix multiplication
Let’s start with what we got ...
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
World space
Our 3D scene is given in world
space, i.e. linear combinations
of the base vectors ~x, ~y , and ~z
Given an arbitrary camera
position, we want to display our
3D world in a 2D image using
perspective projection
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
Camera position
The camera position is specified by
the eye vector ~e
(it’s location)
the gaze vector ~g
(it’s direction)
the image plane
(it’s field of view (FOV) and
distance)
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
View frustum
The view frustum (aka view volume)
specifies everything that the camera
can see. It’s defined by
the left plane l
the right plane r
the top plane t
the bottom plane b
the near plane n
the far plane f
Note: for now, let’s assume all our
objects are completely within the
view frustum
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
Camera transformation
Hmm, it would be much easier if the
camera were at the origin . . .
We can do that by moving from
world space coordinates to camera
space coordinates.
This is just a simple matrix
multiplication (cf. later).
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
Camera transformation
Per convention, we look into the
direction of the negative Z-axis
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
Orthographic projection
Hmm, it would be much easier if we
could do parallel projection . . .
We can do that by transforming the
view frustum to the orthographic
view volume.
Again, this is just a matrix
multiplication (but this time, it’s not
that simple, cf. later).
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
The canonical view volume
Hmm, it would be much easier if our
values were between -1 and 1 . . .
We can do that by transforming the
orthographic view volume to the
canonical view volume.
Again, this is just a (simple) matrix
multiplication (cf. later).
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
Windowing transform
Now all that’s left is a parallel
projection along the Z-axis (every
easy) and . . .
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
Windowing transform
. . . a windowing transformation in
order to display the square [−1, 1]2
onto an nx × ny image.
Again, these are just some (simple)
matrix multiplications (cf. later).
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Introduction
Overview
Projecting from arbitrary camera positions
Windowing transforms
Camera transformation
Camera transformation
Orthographic projection and the canonical view volume
Perspective transform
Windowing transform
Wrap-up
The graphics pipeline (part I)
Notice that every step in this sequence can
be represented by a matrix operation, so
the whole process can be applied by
performing a single matrix operation!
(well, almost . . . )
We call this sequence a graphics pipeline
= a special software or hardware subsystem
that efficiently draws 3D primitives in
perspective.
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
The canonical view volume
Windowing transforms
The orthographic view volume
Camera transformation
The orthographic projection matrix
Perspective transform
Wrap-up
Overview
Let’s start with the easier stuff, e.g.
Windowing transformation
(aka viewport transformation)
How do we get the data from the canonical
view volume to the screen?
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
The canonical view volume
Windowing transforms
The orthographic view volume
Camera transformation
The orthographic projection matrix
Perspective transform
Wrap-up
The canonical view volume
The canonical view volume is a
2 × 2 × 2 box, centered at the origin.
(1, 1, −1)
y
The view frustum is transformed to
this box (and the objects within the −z
view frustum undergo the same x
transformation).
(1, −1, −1)
Vertices in the canonical view
(−1, −1, 1)
volume are orthographically
projected onto an nx × ny image.
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
The canonical view volume
Windowing transforms
The orthographic view volume
Camera transformation
The orthographic projection matrix
Perspective transform
Wrap-up
Mapping the canonical view volume
We need to map the square [−1, 1]2
onto a rectangle [0, nx ] × [0, ny ].
The following matrix takes care of
that:
nx nx
2 0 2
0 ny ny
2 2
0 0 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
The canonical view volume
Windowing transforms
The orthographic view volume
Camera transformation
The orthographic projection matrix
Perspective transform
Wrap-up
Mapping the canonical view volume
In practice, pixels represent unit
squares centered at integer
coordinates, so we actually have to
map to the rectangle
[− 12 , nx − 12 ] × [− 12 , ny − 21 ].
Hence, our matrix becomes:
nx nx
− 12
2 0 2
ny ny
0
2 2 − 12
0 0 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
The canonical view volume
Windowing transforms
The orthographic view volume
Camera transformation
The orthographic projection matrix
Perspective transform
Wrap-up
Mapping the canonical view volume
Notice that we did orthographic projection by “throwing away ”
the z-coordinate.
But since we want to combine all matrices in the end, we need a
4 × 4 matrix, so we add a row and colum that “doesn’t change z”.
Our final matrix for the windowing or viewport transformation is
nx nx
− 12
2 0 0 2
ny ny
0
2 0 2 − 12
Mvp =
0
0 1 0
0 0 0 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
The canonical view volume
Windowing transforms
The orthographic view volume
Camera transformation
The orthographic projection matrix
Perspective transform
Wrap-up
Overview
Hence, our last step will be
xscreen xcanonical
yscreen ycanonical
zcanonical = Mvp zcanonical
1 1
Ok, now let’s work our way up:
How do we get the data from the
orthographic view volume to the canonical
view volume, i.e. . . .
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
The canonical view volume
Windowing transforms
The orthographic view volume
Camera transformation
The orthographic projection matrix
Perspective transform
Wrap-up
The orthographic view volume
. . . how do we get the data
from the axis-aligned box
[l, r] × [b, t] × [n, f ] to a
2 × 2 × 2 box around the
origin?
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
The canonical view volume
Windowing transforms
The orthographic view volume
Camera transformation
The orthographic projection matrix
Perspective transform
Wrap-up
The orthographic view volume
First we need to move the
center to the origin:
0 − l+r
1 0 2
0
1 0 − b+t
2
n+f
0 0 1 − 2
0 0 0 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
The canonical view volume
Windowing transforms
The orthographic view volume
Camera transformation
The orthographic projection matrix
Perspective transform
Wrap-up
The orthographic view volume
Then we have to scale
everything to [−1, 1]:
2
0 0 0
r−l
0 2
t−b 0 0
0 2
0 n−f 0
0 0 0 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
The canonical view volume
Windowing transforms
The orthographic view volume
Camera transformation
The orthographic projection matrix
Perspective transform
Wrap-up
The orthographic view volume
Since these are just matrix multiplications (associative!), we can
combine them into one matrix:
2
− l+r
r−l 0 0 0 1 0 0 2
2
0
t−b 0 0 0 1 0 − b+t
2
Morth = 2
n+f
0 0 n−f 0 0 0 1 − 2
0 0 0 1 0 0 0 1
2 r+l
0 0 − r−l
r−l
2 t+b
0
t−b 0 − t−b
= 2
n+f
0 0 n−f − n−f
0 0 0 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms Aligning coordinate systems
Camera transformation Transformation matrix
Perspective transform
Wrap-up
Overview
Hence, our last step becomes
xpixel x
ypixel y
zcanonical = Mvp Morth z
1 1
Now, how do we get the data in the
orthographic view volume?
That’s more difficult, so let’s look at
camera transformation first.
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms Aligning coordinate systems
Camera transformation Transformation matrix
Perspective transform
Wrap-up
Aligning coordinate systems
How do we get the camera to the
origin, i.e. how do we move from
world space to camera space?
Remember:
world space is expressed by the
base vectors ~x, ~y , and ~z
the camera is specified by eye
vector ~e and gaze vector ~g
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms Aligning coordinate systems
Camera transformation Transformation matrix
Perspective transform
Wrap-up
Aligning coordinate systems
To map one space to another, we
need a coordinate system for both
spaces.
We can easily get that using a view
up vector ~t, i.e. a vector in the plane
bisecting the viewer’s head into left
and right halves and “pointing to the
sky”
This gives us an orthonormal base
(~u, ~v , w)
~ of our camera coordinate
system (how?)
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms Aligning coordinate systems
Camera transformation Transformation matrix
Perspective transform
Wrap-up
Aligning coordinate systems
How do we align the two coordinate
systems?
1 align the origins
2 align the base vectors
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms Aligning coordinate systems
Camera transformation Transformation matrix
Perspective transform
Wrap-up
Aligning coordinate systems
1 0 0 −xe
0 1 0 −ye
Aligning the origins is a simple translation:
0 0 1 −ze
0 0 0 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms Aligning coordinate systems
Camera transformation Transformation matrix
Perspective transform
Wrap-up
Aligning coordinate systems
Aligning the axes is a simple rotation, if you remember that the columns of our
matrix are just the images of the base vectors under the linear transformation.
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms Aligning coordinate systems
Camera transformation Transformation matrix
Perspective transform
Wrap-up
Aligning coordinate systems
xu xv xw 0
yu yv yw 0
These are easy to find for the reverse rotation:
zu
zv zw 0
0 0 0 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms Aligning coordinate systems
Camera transformation Transformation matrix
Perspective transform
Wrap-up
Aligning coordinate systems
xu yu zu 0
xv yv zv 0
Hence, our rotation matrix is:
xw
yw zw 0
0 0 0 1
(Remember: the inverse of an orthogonal matrix is always its transposed)
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms Aligning coordinate systems
Camera transformation Transformation matrix
Perspective transform
Wrap-up
Aligning coordinate systems
For the total transformation we get
xu yu zu 0 1 0 0 −xe
xv yv zv 0 0 1 0 −ye
Mcam =
xw yw zw 0 0 0 1 −ze
0 0 0 1 0 0 0 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Overview
If it wasn’t for perspective projection, we’d
be done:
xpixel x
ypixel y
zcanonical = Mvp Morth Mcam z
1 1
Now, let’s put things into perspective . . .
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Transforming the view frustum
cf. book, fig. 7.13 (3rd ed.) or 7.12 (2nd ed.)
View frustum Orthographic view volume
Perspective projection Parallel/orthographic projection
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Transforming the view frustum
cf. book, fig. 7.10 (2nd ed.; not in 3rd one)
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Transforming the view frustum
We have to transform the view
frustum into the orthographic view
volume. The transformation needs to
Map lines through the origin to
lines parallel to the z axis
Map points on the viewing
plane to themselves.
Map points on the far plane to
(other) points on the far plane.
Preserve the near-to-far order of
points on a line.
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Transforming the view frustum
How do we calculate this? (cf. book, fig. 7.8/7.9 (3rd/2nd ed.))
From basic geometry we know:
ys d
y = z and thus ys = dz y
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Transforming the view frustum
So we need a matrix that gives us
xs = dx
z
ys = dy
z
and a z-value that
stays the same for all points on the near and fare planes
does not change the order along the z-axis for all other points
Problem: we can’t do division with matrix multiplication
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Extending homogeneous coordinates
Remember: matrix multiplication is a linear transformation, i.e. it
can only produce values such as:
x0 = a1 x + b1 y + c1 z
Introducing homogeneous coordinates and representing points as
(x, y, z, 1), enables us to do affine transformations, i.e. create
values such as:
x0 = a1 x + b1 y + c1 z + d1
Now we introduce projective transformation (aka homography)
that allows us to create values such as:
a1 x+b1 y+c1 z+d1
x0 = ex+f y+gz+h
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Extending homogeneous coordinates
How can we transform
0 a1 x+b1 y+c1 z+d1
x x ex+f y+gz+h
a vector y to a vector y 0 = a2ex+f
x+b2 y+c2 z+d2
y+gz+h
z z 0 a3 x+b 3 y+c3 z+d3
ex+f y+gz+h
using matrix multiplication?
We do this by replacing “the one” in the 4th coordinate with a
value w that serves as denominator.
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Extending homogeneous coordinates
With homogeneous coordinates, the vector
(x, y, z, 1) represents the point (x, y, z).
Now we extend this in a way that the homogeneous vector
(x, y, z, w) represents the point (x/w, y/w, z/w).
And matrix transformation becomes:
x̃ a1 b1 c1 d1 x
ỹ a2 b2 c2 d2 y
=
z̃ a3 b3 c3 d3 z
w̃ e f g h 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Extending homogeneous coordinates
Notice that this doesn’t change our existing framework
(i.e. all affine transformations “still work”).
We just have to set
e = f = g = 0 and h = 1.
Then our resulting vector
(x̃, ỹ, z̃, w̃) becomes (x̃, ỹ, z̃, 1),
and it represents the point
(x̃/w̃, ỹ/w̃, z̃/w̃) = (x̃/1, ỹ/1, z̃/1)
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Extending homogeneous coordinates
With this extension, we do matrix multiplication:
a1 b1 c1 d1 x a1 x + b1 y + c1 z + d1 x̃
a2 b2 c2 d2 y a2 x + b2 y + c2 z + d2 ỹ
a3 b3 c3 d3 z = a3 x + b3 y + c3 z + d3 = z̃
e f g h 1 ex + f y + gz + h w̃
Followed by a step called homogenization:
a1 x+b1 y+c1 z+d1
a1 x + b1 y + c1 z + d1 ex+f y+gz+h
a2 x + b2 y + c2 z + d2 a2 x+b2 y+c2 z+d2
ex+f y+gz+h
a3 x + b3 y + c3 z + d3 homogenize
−−−−−−−−→ a3ex+f
x+b3 y+c3 z+d3
y+gz+h
ex + f y + gz + h ex+f y+gz+h
ex+f y+gz+h
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Perspective transform matrix
So, by multiplication with this matrix
Q: how do we chose the
a1 b1 c1 d1
ai , bi , ci , di and e, f, g, h
a2 b2 c2 d2 to get what we want for
perspective projection,
a3 b3 c3 d3
e f g h i.e. the vector
nx
and homogenization, z
ny
we can create this vector z
z∗
a1 x+b1 y+c1 z+d1
ex+f y+gz+h
1
a2 x+b2 y+c2 z+d2
ex+f y+gz+h
a3 x+b3 y+c3 z+d3 (z ∗ denotes a z-value
ex+f y+gz+h fulfilling the conditions
ex+f y+gz+h
ex+f y+gz+h that we specified)
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Perspective transform matrix
The following matrix will do the trick:
n 0 0 0
0
n 0 0
0 0 n+f −f n
0 0 1 0
Notice that
we are looking in negative Z-direction
n, f denote the near and far plane of the view frustum
n serves as projection plane
Let’s verify that . . .
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Perspective transform matrix
nx
n 0 0 0 x x z
ny
0
n 0 0 y y
= n+f
homogenize z
fn
0 0 n+f −f n z z n − f −−−−−−−−→ n + f − z
z
0 0 1 0 1 n
1
Indeed, that gives the correct values for xs and ys .
But what about z? Remember our requirements for z:
stays the same for all points on the near and fare planes
does not change the order along the z-axis for all other points
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Homogeneous coordinates and perspective transformation
fn
We have zs = n + f − z and need to prove that . . .
values on the near plane stay on the near plane,
i.e. if z = n, then zs = n:
zs = n + f − f = n = z
values on the far plane stay on the far plane,
i.e. if z = f , then zs = n:
zs = n + f − n = f = z
and . . .
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Homogeneous coordinates and perspective transformation
fn
We have zs = n + f − z and need to prove that . . .
values within the view frustum stay within the view frustum,
i.e. if z > n then zs > n:
fn fn
zs = n + f − z >n+f − n =n
and if z < f then zs < f :
fn fn
zs = n + f − z <n+f − f =f
and . . .
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Homogeneous coordinates and perspective transformation
fn
We have zs = n + f − z and need to prove that . . .
the order along the Z-axis is preserved,
i.e. if z1 > z2 then z1s > z2s :
fn fn
z1s = n + f − z1 >n+f − z2 = z2s
− z11 < − z12
z1 > z2
and we are done.
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Homogeneous coordinates and perspective transformation
Hence, the order is preserved. But how?
zs = n + f − fzn ,
so zs is proportional to − z1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Transforming the view frustum
Windowing transforms
Homogeneous coordinates
Camera transformation
Perspective transform matrix
Perspective transform
Wrap-up
Perspective transform matrix
With this, we got our final matrix P . To map the perspective view
frustum to the orthographic view volume, we need to combine it
with the orthographic projection matrix Morth , i.e. Mper =
2n l+r
0 0
n 0 0 0 r−l l−r
0 2n b+t
0 n 0 0 t−b b−t 0
Morth P = Morth = f +n
2f n
0 0 n+f −f n 0 0 n−f f −n
0 0 1 0 0 0 1 0
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
Overview
The following achieved parallel projection:
xpixel x
ypixel y
zcanonical = Mvp Morth Mcam z
1 1
And if we replace Morth with Mper we get
perspective projection:
xpixel x
ypixel y
zcanonical = Mvp Mper Mcam z
1 1
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
Wrap-up
To draw lines on the screen, we can use the
following pseudo code:
compute Mvp ///view port
compute Mper ///persp. proj.
compute Mcam ///camera space
M = Mvp Mper Mcam
for each line segment (ai , bi ) do
p = Mai
q = Mbi
drawline(xp /wp , yp /wp , xq /wq , yq /wq )
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
Other stages in the graphics pipeline
Now we can draw points and lines.
But there’s more . . .
Triangles that lie (partly)
outside the view frustum need
not be projected, and are
clipped.
The remaining triangles are
projected if they are front
facing.
Projected triangles have to be
shaded and/or textured.
We will talk about this in the
upcoming lectures.
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
Schedule
Schedule this week:
Today: tutorial 3 (room 61, and if necessary 79)
(solutions online tonight, next tutorial sheet online next week)
Thursday: no lecture, tutorial, or TA session
Friday: midterm exam (and P3 will go online in the evening)
Next week (herkansing exams):
“Officially” no events
Thursday: additional TA session (time TBA on website)
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
Schedule
First week after herkansing:
Monday:
Practical sessions with TA as usual
(maybe extended hours; check website!)
Tuesday:
Lecture: recap midterm exam (by Peter; no recording)
No tutorials
Practical sessions with TAs as usual
Deadline practicals P2, 15:00
Thursday:
No tutorials
Practical sessions with TAs as usual
Lecture: intro to P3 (by Bas and Marries, no recording)
Second week after herkansing:
Business as usual (lecture, tutorials, TA sessions)
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
Practicals and midterm exam
IMPORTANT INFORMATION!
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
Practicals
Considering the 2nd assignment:
We will offer additional TA sessions before the deadline!
Check the website for details!
Take advantage of this, but don’t rely on it!
Spaces in the room are limited and it will be crowded!
Bring your laptop if you have one, so you can also ask
questions to the TAs if all computers are blocked!
Take advantage of the forum!
Most importantly: plan ahead and don’t rely on last minute help!
We try our best, but we don’t guarantee anything!
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
Midterm exam
Time and date:
Friday, 25.5.11
9:00 - 12:00 h
Zaal: EDUC-GAMMA
Note: no responsibility is taken for the correctness of this
information. For final information about time and room see
http://www.cs.uu.nl/education/vak.php?vak=INFOGR
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
The midterm exam
What do I have to do?
Come in time
Bring a pen (no pencil)
Bring your student id
And know the answers ;)
Note: You may not use books, notes, or any electronic equipment
(including cell phones!).
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Introduction
Overview
Windowing transforms
Camera transformation
Perspective transform
Wrap-up
The midterm exam
The exam covers lectures 1-5 and tutorials 1-3.
If you ...
... followed the lectures
... read the textbook
... and actively did the
exercises
... you should be fine.
Graphics 2011/2012, 4th quarter Lecture 07: perspective projection