Viewing Transform
1
Viewing Transform
2
Intended Learning Outcomes
Able to set up a camera coordinate system
Understand the properties of different projection
methods
Able to set up the required projection matrices and use
appropriate OpenGL commands to realize the projection
Describe the operation and function of clipping
3
Image generation process
A camera has its own coordinate system X(VC)-Y(VC)-Z(VC),
called the viewer coordinate system
viewer coordinate system is alternatively called camera
coordinate system
To generate an image, we first need to define a camera,
then transforming the 3D scene from world coordinate
system (WC) to viewing coordinate system (VC)
X(WC)-Y(WC)-Z(WC) → X(VC)-Y(VC)-Z(VC)
Then projecting each point to a view plane
4
To specify a viewer coordinate system, we
need to specify three vectors
View Reference Point (VRP): origin of the viewing
coordinate system (i.e. physical location of the camera)
View Plane Normal (VPN): a vector giving the pointing
direction of the camera (i.e. +ve Z(VC) axis of the camera
X(VC)-Y(VC)-Z(VC))
View UP Vector (VUP) : a vector defining what is the
upward direction for the film (image)
Note 1: These vectors do not need to be unit vector
Note 2: These vectors are in WC
5
ZVC = |VPN| (unit vector in WC)
XVC = | VUP X VPN | (unit vector in WC)
YVC = ZVC × XVC (unit vector in WC)
XVC
VRP
VPN
VUP
VUP lies on the
upper ZVC – YVC plane
ZVC
YVC
Note: | | is used in the notes to denote normalization to unit vector
6
Transformation from WC to VC
P(VC) = MVC←WC P(WC)
Applying coordinate system transformation method 1:
Note: XVC, YVC, ZVC are unit column vector in WC
1
1000
−
←
=
VRPZYX
M VCVCVCWCVC
7
OpenGL commands
glMatrixMode (GL_MODELVIEW);
gluLookAt (x0, y0, z0, xref, yref, zref, Vx, Vy, Vz);
VRP = (x0, y0, z0)
VPN = (x0, y0, z0) – (xref, yref, zref)
VUP = (Vx, Vy, Vz)
To remember this, it is convenient to remember (x0, y0,
z0) as where the camera is placed, (xref, yref, zref) as
where the center of the scene is, and (Vx, Vy, Vz) as a
vector that tells where it’s up for the camera
8
View Plane
Also called projection plane or image plane
It is usually a plane defined by ZVC = constant, i.e.,
parallel to the XVC – YVC plane
As the name implies, a 3D point (X, Y, Z) in viewer
coordinates is projected to a 2D point lying on the view
plane
i.e. 3D becomes 2D
9
Projections : project (X, Y, Z)(VC) to (x,
y)(VC)
Two general types: Parallel and Perspective Projections
all light rays are parallel
Parallel projection Perspective projection
all light rays converge on a common point
called projection reference point (PRP)
Parallel projection can be considered as the special case of perspective
projection when PRP = ∞
10
Different properties
Parallel projection
Perspective Projection
coordinate positions are transformed to the
projection plane along // lines
i.e. center of projection at infinity
coordinate positions are transformed to the
projection plane along lines that converge
to a point called the center of projection
(Projection Reference Point)
preserves relative proportions does not preserve
use in engineering drafting use in realistic views
11
Parallel Projections
Specify a projection vector – a direction vector
Two types:
Orthographic projection – projection vector ⊥ projection
plane
Oblique projection – projection vector not ⊥ to
projection plane
12
Orthographic Projection (α = 90o)
Two types:
Front elevation, side elevation, rear elevation,
plan view – only X-Y, X-Z or Y-Z is shown
Isometric projection – projection vector = (±1,
±1, ±1)
For a cube, each side will be displayed equally
The 8 possibilities corresponds to viewing in the 8
octants
13
Front elevation, side elevation, rear
elevation, plan view
front elevation view
14
Isometric projection
15
Oblique Projection (α ≠ 90o)
Two types:
Cavalier projection – projection vector makes an angle α
of tan-11 with projection plane
for a cube, length of X axis, Y axis and Z axis will remain the
same
Cabinet projection – projection vector makes an angle α
of tan-12 with projection plane
for a cube, length of X axis, Y axis will remain the same; length of
Z axis will be halved.
16
Cavalier Projection
Cabinet Projection
17
Projection
Parallel Perspective
Orthographic Oblique
Front elevation,
side elevation, …
Isometric Cavalier Cabinet
18
4 x 4 Transform for Parallel Projection
α
(X, Y, Z)
View plane
Z = zvp
(x, y, zVP)
(xp, yp, zVP)
Projection Vector
Vp=(Vpx, Vpy, Vpz)
α = 90o Orthographic projection α ≠ 90o Oblique projection
P(VC) = (X, Y, Z) P(im) = (xp, yp, zvp)
All quantities in this slide are already in VC
(X, Y) = (x, y)
zvp is a constant
19
By similar triangles,
pz
px
vp
p
V
V
Zz
Xx
=
−
−
pz
py
vp
p
V
V
Zz
Yy
=
−
−
Rearranging,
pz
py
vpp
pz
px
vpp
V
V
ZzYy
V
V
ZzXx
)(
)(
−+=
−+=
(1)
20
P(im) = (xp, yp, zvp, 1) P(VC) = (X, Y, Z, 1)
P(im) = Mparallel P(VC)
−
−
=
1000
000
10
01
vp
pz
py
vp
pz
py
pz
px
vp
pz
px
parallel
z
V
V
z
V
V
V
V
z
V
V
M
21
Verify that the first two rows implement eqn (1) above
The third row is such that the projected point is at Z =
zvp. However, this is not maintained; in OpenGL, p(im) =
(xp, yp, Z), i.e. the original Z is kept for depth tests
Third row of eqn (10-13), pg. 350 of text is set to
0 0 1 0, which achieves the same effect as maintaining
the original Z.
22
Perspective Projection
ALL light rays goes through the Projection
Reference Point (PRP), also called center of
projection.
23
(X, Y, Z)
View plane
Z = zvp
(xp, yp, zVP)
PRP
24
Example:
i) PRP = VRP
ii) Z = zvp is the view plane
By similar triangles,
Z
X
z
x
vp
p =
Z
Y
z
y
vp
p =
Multiplying each side by zvp yields
vp
vp
p zZ
X
Z
Xz
x
/
=
⋅
= (2)
vp
vp
p zZ
Y
Z
Yz
y
/
=
⋅
=
25
P(VC) = (X, Y, Z, 1)
P(im) = Mperspective P(VC)
=
0/100
0100
0010
0001
vp
eperspectiv
z
M
26
Verify that the first two rows and the fourth row
implements eqn (2) above using homogeneous
coordinates operation
Note that the fourth row is not 0 0 0 1 anymore
The third row is such that the projected point is at Z =
zvp. However, this is not maintained; in OpenGL, p(im) =
(xp, yp, Z), i.e. the original Z is kept for depth tests
27
Clipping
Any object not within the clipping volume does not need
to be processed – this eliminates most of the objects at
one go
For a convex clipping volume bounded by planes, one
can check whether a point is inside by checking the
signs of the plane equations (see Lecture 2).
28
OpenGL – first set matrix mode
glMatrixMode (GL_PROJECTION);
Note: GL_PROJECTION is used as it deals with
projection
There are two 4 x 4 composite transformation matrices:
GL_MODELVIEW and GL_PROJECTION
A point is pre-multiplied by
[GL_PROJECTION] [GL_MODELVIEW]
glOrtho and gluPerspective commands may be used
29
OpenGL – Orthographic projection
glOrtho (xwmin, xwmax, ywmin, ywmax, dnear, dfar)
Projection vector Vp = (0, 0, 1)
Clipping planes: Z = -dnear Z = -dfar
Near clipping plane Z = -dnear also serve as the view
plane
Only points whose X and Y are in |xwmin, xwmax| and
|ywmin, ywmax| respestively are displayed
Clipping volume is a rectangular box
30
Only objects inside the rectangular shaped clipping volume is further processed
Z = -dnear
(xwmin, ywmin, -dnear)
(xwmax – xwmin)
(ywmax – ywmin)
Z = -dfar
31
OpenGL – Perspective projection
gluPerspective (theta, aspect, dnear, dfar)
PRP = VRP
Z = -dnear is the view plane (note the –ve sign)
dnear and dfar define the near and far clipping planes
Z = -dnear and Z = -dfar respectively
theta is the angle of view
aspect = (width /height)
theta and aspect together determines size of image
window
clipping volume is a frustum
32
θ
VRP
Z = -dnear Z = -dfar
aspect = width /height of the blue plane
Only objects inside the frustum shaped clipping volume is further processed
33
References
Text : Ch. 10.2–10.7 discusses the viewing transform
and the various types of projection
Text : Ch. 10.8 discusses general perspective projection
and then discusses the special case. We only discuss
the special case here
Text : Ch. 10.9–10.10 discusses the OpenGL commands
Viewing Transform
Intended Learning Outcomes
Image generation process
To specify a viewer coordinate system, we need to specify three vectors
Slide Number 5
Transformation from WC to VC
OpenGL commands
View Plane
Projections : project (X, Y, Z)(VC) to (x, y)(VC)
Different properties
Parallel Projections
Orthographic Projection ( = 90o)
Front elevation, side elevation, rear elevation, plan view
Isometric projection
Oblique Projection ( ≠ 90o)
Slide Number 16
Slide Number 17
4 x 4 Transform for Parallel Projection
Slide Number 19
Slide Number 20
Slide Number 21
Perspective Projection
Slide Number 23
Slide Number 24
Slide Number 25
Slide Number 26
Clipping
OpenGL – first set matrix mode
OpenGL – Orthographic projection
Slide Number 30
OpenGL – Perspective projection
Slide Number 32
References
Parallel projection
Perspective Projection
coordinate positions are transformed to the projection plane along // lines
i.e. center of projection at infinity
coordinate positions are transformed to the projection plane along lines that converge to a point called the center of projection (Projection Reference Point)
preserves relative proportions
does not preserve
use in engineering drafting
use in realistic views
pz
px
vp
p
V
V
Z
z
X
x
=
–
–
pz
py
vp
p
V
V
Z
z
Y
y
=
–
–
pz
py
vp
p
pz
px
vp
p
V
V
Z
z
Y
y
V
V
Z
z
X
x
)
(
)
(
–
+
=
–
+
=
By similar triangles,
Rearranging,
(1)
_1347113679.unknown
_1347113810.unknown
_1347113553.unknown
Z
X
z
x
vp
p
=
Z
Y
z
y
vp
p
=
vp
vp
p
z
Z
X
Z
X
z
x
/
=
×
=
vp
vp
p
z
Z
Y
Z
Y
z
y
/
=
×
=
Example:
i) PRP = VRP
ii) Z = zvp is the view plane
By similar triangles,
Multiplying each side by zvp yields
(2)
_1347115978.unknown
_1347115991.unknown
_1347116016.unknown
_1347115960.unknown