Sie sind auf Seite 1von 49

CAP4730: Computational

Structures in Computer Graphics


3D Transformations
Outline
3D World
What we are trying to do
Translate
Scale
Rotate
Transformations in 3D!
Remembering 2D transformations -> 3x3
matrices, take a wild guess what happens to
3D transformations.
( )
( )
(
(
(
(

=
(
(
(

+
(
(
(

=
(
(
(

=
(

+
(

=
1 0 0 0
1 0 0
0 1 0
0 0 1
, ,
1 0 0
1 0
0 1
,
z
y
x
z
y
x
z y x
y
x
y
x
y x
t
t
t
t
t
t
z
y
x
t t t T
t
t
t
t
y
x
t t T
T=(t
x
, t
y
, t
z
)
Scale, 3D Style
( )
( )
(
(
(
(

=
(
(
(

(
(
(

=
(
(
(

=
(

=
1 0 0 0
0 0 0
0 0 0
0 0 0
*
0 0
0 0
0 0
, ,
1 0 0
0 0
0 0
*
0
0
,
z
y
x
z
y
x
z y x
y
x
y
x
y x
s
s
s
z
y
x
s
s
s
s s s S
s
s
y
x
s
s
s s S
S=(s
x
, s
y
, s
z
)
Rotations, in 3D no less!
R=(r
x
, r
y
, r
z
, u)
What does a rotation in 3D mean?
Q: How do we specify a rotation?
A: We give a vector to
rotate about, and a theta
that describes how much
we rotate.
u
Q: Since 2D is sort of like a
special case of 3D, what is
the vector weve been
rotating about in 2D?
Rotations about the Z axis
R=(0,0,1,u)
What do you think the rotation matrix is for
rotations about the z axis?
u
( )
(
(
(
(


=
(
(
(


=
(


=
1 0 0 0
0 1 0 0
0 0 cos sin
0 0 sin cos
) , 1 , 0 , 0 (
1 0 0
0 cos sin
0 sin cos
cos sin
sin cos
u u
u u
u
u u
u u
u u
u u
u
R
R
Rotations about the X axis
R=(1,0,0,u)
Lets look at the other axis rotations
u
(
(
(
(

=
1 0 0 0
0 cos sin 0
0 sin cos 0
0 0 0 1
) , 0 , 0 , 1 (
u u
u u
u R
Rotations about the Y axis
R=(0,1,0,u)
u
(
(
(
(

=
1 0 0 0
0 cos 0 sin
0 0 1 0
0 sin 0 cos
) , 0 , 1 , 0 (
u u
u u
u R
Rotations for an arbitrary axis
(
(
(
(


=
1 0 0 0
0 1 0 0
0 0 cos sin
0 0 sin cos
) , 1 , 0 , 0 (
u u
u u
u R
(
(
(
(

=
1 0 0 0
0 cos 0 sin
0 0 1 0
0 sin 0 cos
) , 0 , 1 , 0 (
u u
u u
u R
(
(
(
(

=
1 0 0 0
0 cos sin 0
0 sin cos 0
0 0 0 1
) , 0 , 0 , 1 (
u u
u u
u R
( ) ( ) ( ) ( ) ( ) ( ) o | u | o u
x y z y x
R R R R R R - - - - =
1 1
Rotations for an arbitrary axis
o
|
u
Steps:
1. Normalize vector u
2. Compute o
3. Compute |
4. Create rotation matrix
u
Vector Normalization
Given a vector v, we want to create a unit
vector that has a magnitude of 1 and has the
same direction as v. Lets do an example.

V
V
V Normalized = _
Computing the Rotation Matrix
1. Normalize u
2. Compute R
x
(o)
3. Compute R
y
(|)
4. Generate Rotation Matrix
a
d
d
b
d
c
u u
u u
u
c b d
c b a u
z
z
z
=
=
=
=

=
=
+ =
=
|
|
o
o
sin
cos
sin
'
'
cos
) 1 , 0 , 0 (
) , , (
2 2
Rotation Matrix
( ) ( ) ( ) ( ) ( ) ( )
( )
( )
(
(
(
(


=
(
(
(
(
(
(

=
- - - - =

1 0 0 0
0 0
0 0 1 0
0 0
1 0 0 0
0 0
0 0
0 0 0 1
1 1
d a
a d
R
d
c
d
b
d
b
d
c
R
R R R R R R
y
x
x y z y x
|
o
o | u | o u
Applying 3D Transformations
P=TRTP
Lets compute M
(
(
(
(

(
(
(
(

=
(
(
(
(

=
=
1 1
'
'
'
'
) , , ( ) ( ) , , ( '
z
y
x
p o n m
l k j i
h g f e
d c b a
z
y
x
MP P
P t t t T R t t t T P
z y x z y x
u
Homogenous Coordinates
We need to do something to the vertices
By increasing the dimensionality of the
problem we can transform the addition
component of Translation into
multiplication.
(
(
(
(
(
(

=
=
=
(
(
(

(
(
(

(
(
(
(
(
(

=
=
=
(
(
(

=
2
2
2
14
7
2
6
3
2
14
6
7
3
. ,
1
2
4
2
4
. Ex Ex
h
h
h
y
y
h
x
x
h
y
x
y
x
P
h
h
h
h
Homogenous Coordinates
Homogenous Coordinates embed 3D transforms
into 4D
All transformations can be expressed as matrix
multiplications.
Inverses and combination easier
Equivalence of vectors (4 2 1 1)=(8 4 2 2)
What this means programatically
The Question
Given a 3D point, an eye position, a camera
position, and a display plane, what is the
resulting pixel position?
Now extend this for a group of three points
Then apply what you know about scan
conversion.
Different Phases:
Model Definition
Different Phases:
Transformations
Different Phases:
Projection
Different Phases:
Projection
Different Phases:
Rasterization
Different Phases:
Scan Conversion
What are the steps needed?
Lets Examine the Camera
If I gave you a world, and said I want to
render it from another viewpoint, what
information do I have to give you?
Position
Which way we are looking
Which way is up
Aspect Ratio
Field of View
Near and Far
Camera
View Direction
View Up
View Right
View Normal
Camera
View Up
View Right
ViewUp
ViewRight
o AspectRati =
What are the vectors?
Graphics Pipeline So Far
Object
Object Coordinates
Transformation
Object -> World
World
World Coordinates
Projection Xform
World -> Projection
Camera
Projection Coordinates
Screen
Device Coordinates
Normalize Xform & Clipping
Projection -> Normalized
Viewport
Normalized Coordinates
Viewport Transform
Normalized -> Device
Transformation World->Camera
View Direction
View Up
View Right
View Normal
Transformation World->Camera
T R M
n n n
v v v
u u u
R
v v v u n v
u u u
N V
N V
u
n n n
N
N
n
camera
camera
camera
T
VC WC
z
y
x
- =
(
(
(
(

=
= =
=

=
= =
(
(
(
(

1 0 0 0
0
0
0
) , , (
) , , (
) , , (
1 0 0 0
1 0 0
0 1 0
0 0 1
3 2 1
3 2 1
3 2 1
3 2 1
3 2 1
3 2 1
View Up = V
View Right = u
View Direction = -N
Cross Products
(
(
(

=
=
=
z y x
z y x
x y x
x y y x z x x z y z z y
B B B
A A A
u u u
B A
B A B A B A B A B A B A B A
B A u B A
) , , (
sin u
Given two vectors, the cross product returns a vector that is
perpendicular to the plane of the two vectors and with
magnitude equal to the area of the parallelogram formed by
the two vectors.
u
u
Parallel Projections (known aliases):
Orthographic or Isometric Projection
(
(
(
(

=
=
1 0 0 0
0 0 0 0
0 0 1 0
0 0 0 1
) (
'
ic Orthograph Parallel
Parallel P
P
MV P V
Parallel Projection
Parallel Projections (known aliases):
Oblique Projection
(
(
(
(

=
=
=


1 0 0 0
0 0 0 0
0 sin 1 0
0 cos 0 1
tan
1
1
) (
1 1
'
|
|
o
L
L
P
L
MV P V
Oblique Parallel
VC Parallel P
L
o
|
Projections
foreshortening - the
farther an object is from
the camera , the smaller it
appears in the final image
Perspective Projection Side View
P=(x
p
,y
p
,z
p
) t=0
C=(x
c
,y
c
,z
c
) t=1
P=(x,y,z) t=?
' '
'
'
'
'
z z
z
y
z
y
z
x
z
x
p
p
p
p
=
=
=
|
|
|
|
|
|
|
.
|

\
|
=
= =
= =
=
p
p
p
p
p
p
p
p
p
z
z
z z
w
y
z
z
y y
w
x
z
z
x x
z
z
w
'
'
'
'
'
'
;
'
(
(
(
(

(
(
(
(
(

=
(
(
(
(

1
0
'
1
0 0
0 1 0 0
0 0 1 0
0 0 0 1
'
'
'
p
p
p
z
y
x
z
w
z
y
x
z
z
p

x
p

x
Perspective Projection Side View
P=(x
p
,y
p
,z
p
) t=0
C=(x
c
,y
c
,z
c
) t=1
P=(x,y,z) t=?
|
|
|
|
|
|
|
.
|

\
|

=
= =
= =
=
'
'
'
'
' '
'
' '
'
z f
f z
z f
fz
z
hz
z
y
z
z
y y
hz
z
x
z
z
x x
z w
p
p
p
p
p
p
p
p
p
p
z
z
p

x
p

x
h
|
|
|
|
|
|
|
.
|

\
|
=
= =
= =
=
p
p
p
p
p
p
p
p
p
z
z
z z
w
y
z
z
y y
w
x
z
z
x x
z
z
w
'
'
'
'
'
'
;
'
Scale by h
Perspective Divide
(
(
(
(

(
(
(
(
(
(
(
(

=
(
(
(
(

1
0 1 0 0
*
0 0
0 0
'
0
0 0 0
'
'
'
'
p
p
p
vertical
horiztonal
z
y
x
near far
far near
near far
far
h
z
h
z
w
z
y
x
|
|
|
|
|
|
|
.
|

\
|

=
= =
= =
=
'
'
'
'
' '
'
' '
'
z f
f z
z f
fz
z
hz
z
y
z
z
y y
hz
z
x
z
z
x x
z w
p
p
p
p
p
p
p
p
p
p
Foreshortening - look at the x,y, and w values, and how they depend on how far
away the object is.
Modelview Matrix - describes how to move the world->camera coordinate
system
Perspective Matrix - describes the camera you are viewing the world with.
Lets closely examine
min max
min max
_
' * 2 '
' * 2 '
0 1 0 0
*
0 0
0 0
'
0
0 0 0
'
y y
z
h
z
x x
z
h
z
near far
far near
near far
far
h
z
h
z
P
vertical
horiztonal
vertical
horiztonal
Matrix e Perspectiv

=
(
(
(
(
(
(
(
(

=
What the Perspective Matrix
means
Note: Normalized Device Coordinates are a
LEFT-HANDED Coordinate system
Graphics Pipeline So Far
Object
Object Coordinates
Transformation
Object -> World
World
World Coordinates
Projection Xform
World -> Projection
Camera
Projection Coordinates
Screen
Device Coordinates
Normalize Xform & Clipping
Projection -> Normalized
Viewport
Normalized Coordinates
Viewport Transform
Normalized -> Device
What happens to an object...
Object
Object Coordinates
Transformation
Object -> World
World
World Coordinates
(
(
(
(

=
(
(
(
(

>
1
1
_
_
_
'
_
'
_
'
_
s coordinate object
s coordinate object
s coordinate object
World Object
s coordinate world
s coordinate world
s coordinate world
z
y
x
M
z
y
x
What happens to an object...
Modelview View World
s coordinate world
s coordinate world
s coordinate world
View World
s coordinate view
s coordinate view
s coordinate view
M M
z
y
x
M
z
y
x
=
(
(
(
(

=
(
(
(
(

>
>
1 1
'
_
'
_
'
_
'
_
'
_
'
_
World
World Coordinates
Transformation - Modelview
World -> Eye/Camera
Viewport
Viewport Coordinates
What happens to an object...
ojection e Perspectiv Screen View
ojection Parallel Screen View
s coordinate view
s coordinate view
s coordinate view
Screen View
s coordinate screen normalized
s coordinate screen normalized
s coordinate screen normalized
M M
M M
z
y
x
M
z
y
x
Pr _
Pr _
'
_
'
_
'
_
'
_ _
'
_ _
'
_ _
1 1
=
=
(
(
(
(

=
(
(
(
(

>
>
>
Viewport
Viewport Coordinates
Rasterization
Scan Converting Triangles
Transformation - Projection
(Includes Perspective Divide)
Eye/Camera ->View Plane
Normalized Screen Coordinates
Normalized Screen Coordinates
Lets label all the vectors
z
nsc
=0
z
nsc
=1
View Volume (View Frustum)
Usually:
View Plane = Near Plane
Far Plane
Think about:
Clipping 3D Triangles
View Frustum Culling
M
perspective_Matrix

-1,1,1
1,-1,-1
Comparison with a camera
Lets verbalize whats going on
Review:
Pipeline
Series of steps
What well do next:
Hidden Surface Removal
Depth Buffers
Lighting
Shading
Blending (the elusive alpha)
Textures

Das könnte Ihnen auch gefallen