Upload
nirdosh-singh
View
12
Download
0
Embed Size (px)
Citation preview
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Perspective projection (outline)
1 The graphics pipeline: part I
2 Windowing transforms
3 Perspective transform
4 Camera transformation
5 Wrap-up
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Projecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform
The graphics pipeline: part I
Given an arbitrary cameraposition, we want to displaythe objects in the model in animage
The projection should beperspective projection.
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Projecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform
Camera transformation
We simplify by moving thecamera viewpoint to theorigin, such that we look intothe direction of the negativez-axis.
−Z
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Projecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform
Orthographic projection
Orthographic projection is alot simpler than perspectiveprojection, so we transform theclipped view frustum to anaxis-parallel box
−Z
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Projecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform
The canonical view volume
To simplify our calculations,we transform to the canonicalview volume
(−1,−1)
(1, 1)
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Projecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform
Windowing transform
We apply a windowingtransform to display the square[−1, 1]× [−1, 1] onto anm× n image.
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Projecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform
The graphics pipeline: part I
Every step in the sequence canbe represented by a matrixoperation, so the whole processcan be applied by performing asingle matrix operation!
(Well: almost.)
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
The canonical view volumeThe orthographic view volumeThe orthographic projection matrix
The canonical view volume
The canonical view volume is a2× 2× 2 box, centered at theorigin.
The clipped view frustum istransformed to this box (andthe objects within the viewfrustum undergo the sametransformation).
Vertices in the canonical viewvolume are orthographicallyprojected onto an m× nimage.
−z
x
y
(−1,−1, 1)
(1, 1,−1)
(1,−1,−1)
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
The canonical view volumeThe orthographic view volumeThe orthographic projection matrix
Mapping the canonical view volume
We need to map the square[−1, 1]2 onto a rectangle[−1
2 , m− 12 ]× [−1
2 , n− 12 ].
The following matrix takescare of that:m
2 0 m2 − 1
20 n
2n2 − 1
20 0 1
(−1,−1)
(1, 1)
m
n
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
The canonical view volumeThe orthographic view volumeThe orthographic projection matrix
The orthographic view volume
The orthographic view volumeis an axis-aligned box[l, r]× [b, t]× [n, f ].
Transforming it to thecanonical view volume is doneby
2r−l 0 0 00 2
t−b 0 00 0 2
n−f 00 0 0 1
1 0 0 − l+r2
0 1 0 − b+t2
0 0 1 −n+f2
0 0 0 1
−z
x
y
(−1,−1, 1)
(1, 1,−1)
(1,−1,−1)
(l, b, n)
(r, t, f)
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
The canonical view volumeThe orthographic view volumeThe orthographic projection matrix
The orthographic projection matrix
We can combine the matrices into one:
Mo =m2 0 0 m
2 − 12
0 n2 0 n
2 − 12
0 0 1 00 0 0 1
2r−l 0 0 00 2
t−b 0 00 0 2
n−f 00 0 0 1
1 0 0 − l+r2
0 1 0 − b+t2
0 0 1 −n+f2
0 0 0 1
Given a point p in the orthographic view volume, we map it to apixel [i, j] as follows:
ij
zcanonical
1
= Mo
xp
yp
zp
1
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Transforming the view frustumPerspective transform matrixHomogeneous coordinates
Transforming the view frustum
We have to transform the viewfrustum into the orthographic viewvolume. The transformation needs to
Map lines through the origin tolines parallel to the z axis
Map points on the viewingplane to themselves.
Map points on the far plane to(other) points on the far plane.
Preserve the near-to-far order ofpoints on a line.
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Transforming the view frustumPerspective transform matrixHomogeneous coordinates
Transforming the view frustum
(cf. book, fig. 7.12)
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Transforming the view frustumPerspective transform matrixHomogeneous coordinates
Transforming the view frustum
(cf. book, fig. 7.10)
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Transforming the view frustumPerspective transform matrixHomogeneous coordinates
Perspective transform matrix
The following matrix does the trick:
Mp =
1 0 0 00 1 0 00 0 n+f
n −f0 0 1
n 0
We have Mp
xyz1
=
xy
z n+fn − f
zn
Hmmmm. . . is that what wewant. . . ?
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Transforming the view frustumPerspective transform matrixHomogeneous coordinates
Homogeneous coordinates
We have seen homogeneous coordinates before, but so far, thefourth coordinate of a 3D point has alway been 1.
In general, however, the homogeneous representation of a point(x, y, z) in 3D is (hx, hy, hz, h). Choosing h = 1 has just been aconvenience.
So we have:
Mp
xyz1
=
xy
z n+fn − f
zn
homogenize−−−−−−−−→
nxz
nyz
n + f − fnz
1
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Transforming the view frustumPerspective transform matrixHomogeneous coordinates
Transforming the view frustum
(cf. book, fig. 7.9)
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Transforming the view frustumPerspective transform matrixHomogeneous coordinates
Homogeneous coordinates
Note: moving and scaling still work properly
For example: translation1 0 0 tx0 1 0 ty0 0 1 tz0 0 0 1
hxhyhzh
=
hx + htxhy + htyhz + htz
h
homogenize−−−−−−−−→
x + txy + tyz + tz
1
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Aligning coordinate systemsTransformation matrix
Aligning coordinate systems
Given a camera coordinate systemwith origin e and orthonormal base(u, v, w), we need to tranformobjects in world space coordinatesinto objects in camera coordinates.
This can alternatively be consideredas aligning the canonical coordinatesystem with the camera coordinatesystem.
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Aligning coordinate systemsTransformation matrix
Camera transformation
The required transformation is takencare of by Mv =
xu yu zu 0xv yv zv 0xw yw zw 00 0 0 1
1 0 0 −xe
0 1 0 −ye
0 0 1 −ze
0 0 0 1
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection
The graphics pipeline: part IWindowing transformsPerspective transform
Camera transformationWrap-up
Wrap-up
If we combine all steps, we get:
compute Mo
compute Mv
compute Mp
M = MoMpMv
for each line segment (ai,bi) dop = Mai
q = Mbi
drawline(xp/hp, yp/hp, xq/hq, yq/hq)
Graphics, 1st period 2006/2007 Lecture 6: Orthographic and perspective projection