You are on page 1of 51

3D Viewing – 3D Viewing

Projection Transformations
and
Vi i Pi li Viewing Pipeline
I mpl ement at i on of 3D Vi ew i ng I mpl ement at i on of 3D Vi ew i ng
Apply
li i
3-D world
coordinate
Clip against
canonical
normalizing
transformation
output
primitives
View
Volume p
Project
onto
Transform into
viewport in
onto
Projection
plane
p
2D device
coordinates
2D device
coordinates
plane
for display
Canonical view volume for parallel p
proj ection is defined by six planes:
X = 1; Y = 1; Z = -1.
X = -1; Y = -1; Z = 0;
X or Y
1
FP FP
BP
-Z
-1
-1 -1
Canonical view volume for perspective p p
proj ection is defined by six planes:
X Z; Y Z; Z Z ;
X = -Z; Y = Z; Z = -1.
X = Z; Y = -Z; Z = -Z
min
;
X or Y
1
FP
-Z
-1
-1
BP
View Specifications: View Specifications:
VP, VRP, VUP, VPN, PRP, DOP, CW, VRC
v
VUP VUP
(u
max
, v
max
)
VP
VRP
CW
VP
u
VRP
u
VPN
(u
min
, v
min
)
nn
v
VUP VUP
(u
max
, v
max
)
VP
(
max
,
max
)
VRP
CW
VP
uu
VPN
(u
min
, v
min
)
v
n
VRP
CW
VP
Diagrams for an
u
VPN
Diagrams for an
arbitrary 3D view
n
COP/PRP
Spec i f yi ng an Ar bi t r ar y 3D Vi ew
Viewing
Parameter
Example Values
Set 1 Set 2 Set 3
Parameter
Set 1 Set 2 Set 3
VRP (WC) (0, 0, 54) (16, 0, 54) (0, 0, 0) ( ) ( , , ) ( , , ) ( , , )
VPN (WC) (0, 0, 1) (0, 1, 0) (0, 0, 1)
VUP (WC) (0, 1, 0) (-1, 0, 0) (0, 1, 0)
PRP (VRC) (8, 6, 30) (12, 8, 30) (8, 6, 84) PRP (VRC) (8, 6, 30) (12, 8, 30) (8, 6, 84)
Window
(VRC)
(-1, 17,
1 17)
(-1, 25,
5 21)
(-50, 50,
50 50)
(VRC)
-1, 17) -5, 21) -50, 50)
Projection
Perspective Parallel Perspective
Type
Perspective Parallel Perspective
F & B
+1 23
(VRC)
+1, -23
- -
St eps f or i mpl ement i ng nor mal i zi ng
t r ansf or mat i on mat r i x f or
par al l el pr oj ec t i on p p j
• Translate the VRP to origin
• Rotate VRC such that VPN (n-axis) aligns
with Z-axis (also u with X and v with Y-axis) with Z-axis (also, u with X and v with Y-axis)
• Shear (not necessary for pure orthographic) • Shear (not necessary for pure orthographic)
such that DOP is parallel to the Z-axis
• Translate and scale into parallel-projection
canonical view volume (CVV) canonical view volume (CVV)
VRP) T( R SH T S N
par par par par
÷ =
p p p p
Step 2 in normalizing transformations:
Rotate VRC such that VPN (n-axis) aligns
with Z-axis (also, u with X and v with Y)
v
( , )
VUP
(u v ) (u
max
, v
max
)
CW
VP
VRP
CW
u
(u
i
v
i
)
VPN
(u
min
, v
min
)
n
Expressions for Step 2 must be derived.
Implement using the concept of combined
transformation (rotation).
(
0 0 0 1
Take R
x
=
(
(
(
(

÷ 0 ) sin( ) cos( 0
0 0 0 1
o o
x
(
(
¸

¸
1 0 0 0
0 ) cos( ) sin( 0 o o
• Rows are unit vectors, when rotated by R
x
,
ill li ith th Y d Z i ti l
¸ ¸
will align with the Y and Z axis respectively.
• When unit vectors along the principle axes • When unit vectors along the principle axes
are rotated by R
x
, they form the column
vectors. vectors.
(
(

0 0 0 1
R
x
=
(
(
(

÷
0 ) cos( ) sin( 0
0 ) sin( ) cos( 0
o o
o o
(
(
¸

¸
1 0 0 0
0 ) cos( ) sin( 0 o o
Row Vectors: [ 1 0 0 ]
[ 0 cos(o) -sin(o) ]
o
Z
[ 0 cos(o) -sin(o) ]
[ 0 sin(o) cos(o) ]
Column Vectors {consider R
x
(-o),
i hi }
Y
in this case}:
[ 1 0 0 ]
T
[ 0 ( ) i ( ) ]
T
o
Y [ 0 cos(o) -sin(o) ]
T
[ 0 sin(o) cos(o) ]
T
Consider a general
Y
scenario of combined
rotations and use the
d i d b d
P
3
property derived based
on the orthogonality
f th R t i
P
2
P
1
of the R matrix.
X
1
Y
X
P
n
P
Z
P
3
Before
Transformation
X
P
1
P
n
X
P
2
After
Transformation
Z
2
Transformation
Let the effective
(
3 2 1
r r r
rotation matrix be
a combination
(
(
(

3y 2y 1y
3x 2x 1x
r r r
r r r
Y
P
of three rows as:
(
(
¸

¸ 3z 2z 1z
3y 2y 1y
r r r
P
3
P
2 P
1 ¸ ¸ 3z 2z 1z
where,
X
P
1
| |
T
1 2
z 1z 2z 3z
1 2
PP
R =r r r =
PP
Z
P
n
Y
| |
1 2
T
1 2 1 3
1 2 3
PP
PP X PP
R =r r r =
Z
Y
P
| |
x 1x 2x 3x
1 2 1 3
R r r r
PP X PP
and
P
3
P
n
T
and
R = r r r =R X R (
¸ ¸
X
P
P
1
y 1y 2y 3y z x
R r r r R X R (
¸ ¸
Z
P
2
Y
P
Y
P
3
P
2 P
1
P
3
P
X
P
1
X
P
1
P
n
Z
P
n
Z
P
2
P
1
Z
Thus the rotation matrix of step 2 in
normalizing transformations, can be normalizing transformations, can be
formulated as:
(
(

0 r r r
3x 2x 1x
(
(
(

=
0 r r r
3y 2y 1y
R
(
(
¸

¸
1 0 0 0
0 r r r
3z 2z 1z
R
¸ ¸
1 0 0 0
Step 2 in normalizing transformations:
Rotate VRC such that VPN (n-axis) aligns
with Z-axis (also, u with X and v with Y)
v
( , )
VUP
(u v ) (u
max
, v
max
)
CW
VP
VRP
CW
u
(u
i
v
i
)
VPN
(u
min
, v
min
)
n
VPN
z
;
VPN
VPN
R =
where,
R VUP
R
×
,
z
z
x
;
R VUP
R VUP
R
×
=
x z y
z
R R R and × =
x z y
The overall combined transformation matrix The overall combined transformation matrix
for parallel projection (WCSVV - > PPCVV), is:
VRP) T( R SH T S N
par par par par
÷ =
The overall combined transformation matrix
f ll l j ti (WCSVV PPCVV) i for parallel projection (WCSVV - > PPCVV), is:
VRP) T( R SH T S N ÷ = VRP) T( R SH T S N
par par par par
where,
d
(
(
(

0 1 0
0 0 1
par
shy
shx
;
x
par
dop
shx
dop
= ÷
(
(
(

=
0 1 0 0
0 1 0
par
par
shy
SH
z
y
dop
dop
h
(
¸

¸
1 0 0 0
y
par
z
p
shy
dop
= ÷
y
DOP
y
DOP
y
-z
VPN
y
VPN Side view of
shearing of the VV
z
-z
shearing of the VV
The overall combined transformation matrix
f ll l j ti (WCSVV PPCVV) i for parallel projection (WCSVV - > PPCVV), is:
VRP) T( R SH T S N = VRP) T( R SH T S N
par par par par
÷ =
(
;
2 2
min max min max
FP
v v u u
T
par
(
¸
(

¸

+
÷
+
÷ =
2 2
¸ ¸
)
1
,
2
,
2
( S S = ) , , (
min max min max
BP FP v v u u
S S
par
÷ ÷ ÷
Implementing normalizing Implementing normalizing
transformation matrix
for perspective projection
v
CW
VRP
CW
VP
u
VPN
n
COP/PRP COP/PRP
Canonical view volume for perspective
proj ection is defined by six planes:
X Z; Y Z; Z Z ;
X = -Z; Y = Z; Z = -1.
X = Z; Y = -Z; Z = -Z
min
;
X or Y
1
FP
-Z
-1
-1
BP
Steps for implementing normalizing Steps o p e e t g o a g
transformation matrix for
perspective projection perspective projection
T l t th VRP t i i • Translate the VRP to origin
• Rotate VRC such that VPN (n-axis) aligns Rotate VRC such that VPN (n axis) aligns
with Z-axis (also, u with X- and v with Y-axis)
T l t h th t COP ( PRP) i t th • Translate such that COP (or PRP) is at the
origin
• Shear such that center line of view volume
(VVCL) becomes z-axis
• Scale such that VV becomes the canonical
view volume (CVV) view volume (CVV)
Scenario of the cross-section of the VV
ft fi t th t f ti after first three transformations.
X or Y
CW
-Z
VRP
VPN
VRP
VRP) T R PRP T SH S N
par per per
÷ ÷ = ( ) (
p p p
Comparison the overall combined p
transformation matrices for:
PARALLEL PROJECTION:
VRP) T( R SH T S N
par par par par
÷ =
PERSPECTIVE PROJECTION:
VRP) T( R PRP) T( SH S N
par per per
÷ ÷ =
I mpl ement at i on of 3D Vi ew i ng I mpl ement at i on of 3D Vi ew i ng
Apply
li i
3-D world
coordinate
Clip against
canonical
normalizing
transformation
output
primitives
View
Volume p
Project
onto
Transform into
viewport in
onto
Projection
plane
p
2D device
coordinates
2D device
coordinates
plane
for display
(
(

d
z
d
0 1
x x
G li d
(
(
(

÷
d d
d
z
d
0 1
z
x
p
z
x
Generalized
formula
f ti
(
(
(

÷
=
d
d
z
d
d
1 0
M
2
z
y
p
z
y
of perspective
projection matrix:
(
(
(
(

+ ÷ Z
Qd
Z
Qd
Z
0 0
M
p
z
2
p
z
p
gen
(
(
(
¸

¸
+ ÷ 1
Qd
Z
Qd
1
0 0
Q Q
p
z z
(
¸

¸
Qd Qd
z z
(COP) X or Y
PP
(COP) X or Y
P´(x
p
, y
p,
Z
p
)
Q
L
Z O
Q
P(X,Y,Z)
(d
x
, d
y
, d
z
)
Z O
(0, 0, Z
p
)
Coor di nat e Syst ems and Mat r i c es
Perspective
y
p
Parallel
3-D modeling
(object)
Modeling
Transformation
(object)
coordinates
Transformation
i
3D W ld
View
Orientation
t i
3D World
Coordinates
R.T(-VRP)
R T(-VRP)
matrix
R.T( VRP)
Cont…
Vi
View
Orientation
View
Mapping
View
reference
Coordinates
Orientation
matrix
pp g
matrix
Coordinates
N li d
Clip, transform
into 2D screen
Normalized
projection
Coordinates
coordinates
Coordinates
2D d i
M
CVV3DVP
2D device
coordinates
M . S
per
. SH
par
. T(-PRP)
S
par
. T
par
. SH
par par par par
where after clipping, use
M
CVV3DVP
=
. ) Z , Y , T(X
vmin vmin vmin
) Z Z ,
Y Y
,
X X
S(
vmin vmax
vmin vmax vmin vmax
÷
÷ ÷
T(111)
) ,
2
,
2
(
vmin vmax
T(1,1,1) .
The 3D Vi ew i ng Pi pel i ne
• Objects are modeled in object (modeling)
space.
• Transformations are applied to the objects
to position them in world space.
• View parameters are specified to define
th i l f th ld j ti the view volume of the world, a projection
plane, and the viewport on the screen.
Obj t li d t thi Vi l • Objects are clipped to this View volume.
The results are projected onto the • The results are projected onto the
projection plane (window) and
finally mapped into the 3D viewport finally mapped into the 3D viewport.
Hidd bj t th d • Hidden objects are then removed.
• The objects are scan converted and
then shaded if necessary.
Fl owchar t of t he 3D Vi ew i ng Pi pel i ne
Model
Scale,Rotate,
Object
Space
g p
Model
Object
Scale,Rotate,
Translate
Objects
Space
Objects
World
Space
World
Space
Specify View,
Calculate Normal,
Apply Normalizing
Transformation
p
Calculate Normal,
Illumination,
Backface
Transformation
Clip
Cont
Eye
Cont…
Eye
Space
Perspective
Eye
Image
Perspective
Transformation
/Projection
Remove
Hidden
S f
Space
Space
/Projection
Surfaces
M t
Shade,
Texture
Map to
Viewport/
Draw to
Device
C di
Texture
Draw to
screen
Coordinates
The Comput er
Gr aphi c s Pi pel i ne
Vi ew i ng Pr oc ess Vi ew i ng Pr oc ess
The Camer a Model
We specify our initial camera model by
identifying the following parameters. identifying the following parameters.
1. A scene, consisting of polygonal elements sce e, co s st g o po ygo a e e e ts
each represented by their vertices;
2 A i t th t t th 2. A point that represents the camera
position: C = [C
x
, C
y
, C
z
];
3. A point that represents the “center-of
attention” of the camera (i.e. where the (
camera is looking): A = [A
x
, A
y
, A
z
];
4 A field of ie angle ep esenting the 4. A field-of-view angle, o ,representing the
angle subtended at the apex of the viewing
pyramid pyramid.
The specification of “near”
d “f ” b di l and “far” bounding planes.
These planes considered
di l t th perpendicular to the
direction-of-view vector
are at a distance of
A
are at a distance of
‘n’ and ‘f’ from the
camera
A
camera,
respectively.
F
a
rr

P
l
a
nn
e
o
C
The Viewing Pyramid
3D view of the
g y
A
3D view of the
viewing space
A

F
a
r

v

P
l
a
n
e
C
e
C
o
w

u

w
The image space
volume:
u
1 w v, u, 1 s s ÷
Side view of the viewing space
F
a
Nea
o
r

P
l
a
Near
Plane
n
a
n
e
n
f
Der i vat i on of t he vi ew i ng t r ansf or mat i on g
mat r i x , i n t er ms of c amer a par amet er s:
d.u d.v d.u d.v d.w
(u,v,w) ( , , d) ( , , ) ÷ ÷ =
w w w w w
Thus,
÷ ÷ ÷ ÷ ÷
,
(u, v, w, 1) (d.u, d.v, d.w, w) ÷ ÷
P(u, v, w)
u or v
(u´, v´, w´)
PP
O (COP)
-w 
(u , v , w )
dd
Express as transformation:
0 0 0 1
0 0 0 d
(
(
)
1
0 0 1 0
0 0 0 1
or ( ;
0 0 d 0
0 0 0 d
(
(
(
(

(
(
(
(

= P )
0 0 0 0
d
1
1 0 0
or ( ;
0 0 0 0
1 d 0 0
(
(
(
¸

¸
÷
(
(
(
¸

¸
÷
=
d
P
0 0 0 d
0 0 0 0
0 0 0 0
(
(

(
¸

¸
¸ ¸
| | | | w d.w d.v d.u
1 d 0 0
0 0 d 0
1 w v u ÷ =
(
(
(

÷
0 0 0 0
1 d 0 0
(
(
¸

¸
Transformation of the finite (truncated)
viewing pyramid to the
cube (CVV), -1 < u, v, w < 1.
The image space
volume:
Let us first analyze w-axis only.
h f i i
volume:
1 w v, u, 1 s s ÷
Use the transformation matrix:
0 0 0 1
(
0 0 1 0
0 0 0 1
(
(
(

such that,
(0 0 -n)P  (0 0 1)
;
1 a 0 0
0 0 1 0
P
(
(

÷
=
(0, 0, -n)P  (0, 0, 1)
and
(0 0 -f)P  (0 0 -1)
0 b 0 0
1 a 0 0
(
(
¸

¸
(0, 0, -f)P  (0, 0, -1)
0 b 0 0
¸ ¸
Solve for parameters a and b, using the p , g
above equations:
From the constraints of the
n b an = +
From the constraints of the
above two equations:
and
n b an = + ÷
f b af
and
÷ = + ÷ f b a.f ÷ = + ÷
;
n f
a
+
=
The
solution:
;
n f
a
÷
=
solution:
2f.n
f
n f
2f.n
b=
n f ÷
Hence the
(
(

0 0 0 1
transformation is:
(
(
(

+
1
n f
0 0
0 0 1 0
(
(
(

÷
÷
+
=
1
n f
n f
0 0
P
(
(
¸

¸
0
n f
2f.n
0 0
¸ ¸
÷ n f
Wh t b t d i t f ti What about u and v-axis transformations
in the pyramid ?
u and v-axis transformations
in the pyramid
t ( /2)
u or v
n.tan(o/2)
f tan(o/2)
o/2
f.tan(o/2)
O (COP) -w 
o/2
(0, 0, -n) (0, 0, -f) ( ) ( , , ) ( , , )
Transformations for the two points
are as follows:
(0, n.tan(o/2), -n)
v
(0, f.tan(o/2), -f)
v
o/2
O (COP)
-w  (0, 0, -n) (0, 0, -f)
(
0 0 0 1
(
(
(

f
0 0 1 0
0 0 0 1
Desired normalized 3-D
coordinates for both the
(
(
(
(

÷
÷
+
=
2f
1
n f
n f
0 0
P
points: [0, 1, +/-1, 1].
(
(
¸

¸
÷
0
n f
2f.n
0 0
| |. 1 f /2) f.tan( 0
(
÷ o P
f
n f
2nf
n f
n f
f /2) f.tan( 0
(
¸
(

¸

÷
+
÷
+
÷ = o
| | f f /2) f.tan( 0
n f n f
÷ =
¸ ¸
o
Thus modify P
to be:
(
(

0 0 ) 2 / ( 0
0 0 0 ) 2 / cot(o
(
(
(

+
=
1
n f
0 0
0 0 ) 2 / cot( 0
P'
o
(
(
(

÷
÷
=
2f n
1
n f
0 0
P
(
(
¸

¸ ÷
0
n f
2f.n
0 0
| | ' 1 n /2) ntan( 0 ÷ P o | |
2nf n f
0
. 1 n /2) n.tan( 0
(
(

+
+
P o
| |
n
n f n f
n n 0
(
¸
(

¸

÷
+
÷
÷ =
| | 1 1 0 =
Its inverse has the form:
(
(

0 0 0 tan ) 2 / (o
(
(
(

÷ n f
0 0 tan 0 ) 2 / (o
(
(
(

=
÷
2fn
n f
0 0 0 P
1
(
(
¸

¸
+
÷
2f
n f
1 0 0
f
¸ ¸
2fn
= P P P
The Vi ew i ng Tr ansf or mat i on Mat r i x
(
(

=
0 0 0 ) 2 / ( d.cot
.P P P
d f
o
(
(
(

÷ +
=
d
2 n) d(f
0 0
0 0 ) 2 / ( d.cot 0
fn
o
(
(
(
¸

¸
÷
÷
0 0 0 0
d
n f
) (
0 0
f
¸ ¸
0 0 0 1
(
(
)
1
0 0 1 0
0 0 0 1
or ( ;
0 0 d 0
0 0 0 d
(
(
(
(

(
(
(
(

=
d
P (
(
(

f
0 0 cot( 0
0 0 0 ) cot(
) 2 /
2 /
o
o
)
0 0 0 0
d
1
1 0 0
or ( ;
0 0 0 0
1 d 0 0
(
(
(
¸

¸
÷
(
(
¸

¸
÷
d
P
(
(
(
(
(

÷
÷
+
=
2f n
1
n f
n f
0 0 P
| | | | w dw dv du
0 0 d 0
0 0 0 d
1 w v u =
(
(
(

(
(
¸

¸
÷
0
n f
2f.n
0 0
| | | | w d.w d.v d.u
0 0 0 0
1 d 0 0
1 w v u ÷ =
(
(
(
¸

¸
÷
(
0 0 0 ) 2 / ( cot
or
o
using the regular expression of P
d
(
(
(

0 0 ) 2 / ( cot 0
0 0 0 ) 2 / ( cot
o
o
(
(
(
(

÷
÷
+
=
1
n) d(f
2fn - n) d(f
0 0
(
(
¸

¸
0 0 0 0
n) d(f
0 0 0 1
(
(
)
1
0 0 1 0
0 0 0 1
or ( ;
0 0 d 0
0 0 0 d
(
(
(
(

(
(
(
(

=
d
P (
(
(

f
0 0 cot( 0
0 0 0 ) cot(
) 2 /
2 /
o
o
)
0 0 0 0
d
1
1 0 0
or ( ;
0 0 0 0
1 d 0 0
(
(
(
¸

¸
÷
(
(
¸

¸
÷
d
P
(
(
(
(
(

÷
÷
+
=
2f n
1
n f
n f
0 0 P
| | | | w dw dv du
0 0 d 0
0 0 0 d
1 w v u =
(
(
(

(
(
¸

¸
÷
0
n f
2f.n
0 0
| | | | w d.w d.v d.u
0 0 0 0
1 d 0 0
1 w v u ÷ =
(
(
(
¸

¸
÷
End of Lectures on
3D Viewing – 3D Viewing –
Projection Transformations j
and
Vi i Pi li Viewing Pipeline