CAP4730: Computational Structures in Computer Graphics: 3D Transformations
CAP4730: Computational Structures in Computer Graphics: 3D Transformations
3D Transformations
Outline
•3D World
•What we are trying to do
•Translate
•Scale
•Rotate
Transformations in 3D!
1 0 t x
x t
T t x , t y 0 1 t y
x
y t y 0 0 1
1 0 0 t x
x
x t
0 1 0 t
T t x , t y , t z y t y
y
0 0 1 t z
z t z
0 0 0 1
Scale, 3D Style
sx 0 0
sx 0 x S=(sx, sy, sz)
S sx , s y * 0
s y y
sy 0
0 0 0 1
sx 0 0 0
sx 0 0 x
0 sy 0 0
S s x , s y , s z 0 sy
0 * y
0 0 sz 0
0 0 s z z
0 0 0 1
Rotations, in 3D no less!
What does a rotation in 3D mean? R=(rx, ry, rz, )
Q: How do we specify a rotation?
A: We give a vector to
rotate about, and a theta
that describes how much
we rotate.
R=(1,0,0,)
1 0 0 0
0 cos sin 0
R(1,0,0, )
0 sin cos 0
0 0 0 1
Rotations about the Y axis
R=(0,1,0,)
cos 0 sin 0
0 1 0 0
R(0,1,0, )
sin 0 cos 0
0 0 0 1
Rotations for an arbitrary axis
1 0 0 0
0 cos sin 0
R(1,0,0, )
0 sin cos 0
0 0 0 1
cos 0 sin 0
0 1 0 0
R(0,1,0, )
sin 0 cos 0
0 0 0 1
cos sin 0 0
sin cos 0 0
R(0,0,1, )
0 0 1 0
0 0 0 1
Rotations for an arbitrary axis
R Rx1 R y1 Rz R y Rx
u
Steps:
1. Normalize vector u
2. Compute
3. Compute
4. Create rotation matrix
Vector Normalization
• 1. Normalize u u (a, b, c)
• 2. Compute Rx() d b2 c2
• 3. Compute Ry() u z (0,0,1)
u 'u z c
• 4. Generate Rotation Matrix cos
u' uz d
b
sin
d
cos d
sin a
Rotation Matrix
R Rx1 R y1 Rz R y Rx
1 0 0 0
c b
0 d d
0
Rx b c
0 0
d d
0 0 0 1
d 0 a 0
0 1 0 0
Ry
a 0 d 0
0 0 0 1
Applying 3D Transformations
P’=TRTP
Let’s compute M
View Normal
View Direction
Camera
View Up
ViewRight
AspectRatio
ViewUp
View Right
Screen
Device Coordinates
Transformation World->Camera
View Right
View Up
View Normal
View Direction
Transformation World->Camera
View Right = u
1 0 0 camerax
0 1 0 camera y
View Up = V
T
0 0 1 cameraz
0 0 0 1
N
n (n1 , n2 , n3 )
N
V N
u (u1 , u2 , u3 )
V N
v n u (v1 , v2 , v3 ) View Direction = -N
u1 u2 u3 0
v v v3 0
R 1 2
n1 n2 n3 0
0 0 0 1
M WC VC R T
Cross Products
A B u A B sin
A B ( Ay Bz Az B y , Az Bx Ax Bz , Ax B y Ay Bx ) u
ux uy ux
A B Ax Ay Az
Bx By Bz
Joke
A B ( B A)
A B C A B C
A B C A B A C
Parallel Projections (known aliases):
Orthographic or Isometric Projection
VP' M ParallelVVC
1 0 0 0
0 1 0 0
M Parallel (Orthographic )
0 0 0 0
0 0 0 1
Parallel Projection
Parallel Projections (known aliases):
Oblique Projection
VP' M ParallelVVC
L
L1 tan 1
1 0 L1 cos 0
0 1 L1 sin 0
M Parallel (Oblique )
0 0 0 0
0 0 0 1
Projections
foreshortening - the
farther an object is from
the camera , the smaller it
appears in the final image
Perspective Projection Side View
P=(xp,yp,zp) t=0 P’=(x’,y’,z’) t=?
C=(xc,yc,zc) t=1
xp
x’
z’
zp
x' x p
z' xp x ' 1 0 0 0 x
z' z p x' x p p
zp w y ' 0 1 0
0 y
y' y p zp z' yp p
w ; y' y p
z' zp
w
z ' 0 0 1 0 z
z' z p
0 0
1 p
0 1
z' z p
z'
w z'
z' z' zp
Perspective Projection Side View
P=(xp,yp,zp) t=0 P’=(x’,y’,z’) t=?
C=(xc,yc,zc) t=1
xp h
x’
z’
zp
Foreshortening - look at the x,y, and w values, and how they depend on how
far away the object is.
Molelview Matrix - describes how to move the world->camera coordinate
system
Perspective Matrix - describes the camera you are viewing the world with.
Let’s closely examine
z'
h 0 0 0
horiztonal
0 z'
0 0
PPerspective _ Matrix hvertical
far near * far
0 0
far near far near
0 0 1 0
z' 2 * z'
hhoriztonal xmax xmin
z' 2 * z'
hvertical ymax ymin
What the Perspective Matrix
means
Note: Normalized Device Coordinates are a
LEFT-HANDED Coordinate system
Graphics Pipeline So Far
Object Transformation
Object Coordinates Object -> World
Screen
Device Coordinates
What happens to an object...
Object Transformation
Object Coordinates Object -> World
World
World Coordinates
xworld
'
_ coordinate s xobject _ coordinate s
' y
y
world _ coordinate s M object _ coordinate s
zworld
'
_ coordinate s
Object World
zobject _ coordinate s
1 1
What happens to an object...
Viewport
Viewport Coordinates
xview
'
_ coordinates xworld
'
_ coordinate s
' '
y
view _ coordinates M y
world _ coordinates
zview
'
_ coordinate s
World View
zworld
'
_ coordinate s
1 1
M World View M Modelview
What happens to an object...
Transformation - Projection
Viewport
(Includes Perspective Divide)
Viewport Coordinates
Eye/Camera ->View Plane
Rasterization
Scan Converting Triangles
xnormalized
'
_ screen _ coordinate s xview
'
_ coordinate s
' '
y
normalized _ screen _ coordinates M y
view _ coordinates
View Screen
znormalized
'
_ screen _ coordinate s
z '
view _ coordinate s
1 1
M View Screen M Parallel _ Pr ojection
M View Screen M Perspective _ Pr ojection
Normalized Screen Coordinates
Normalized Screen Coordinates
Let’s label all the vectors
znsc=0 znsc=1
View Volume (View Frustum)
Usually: Far Plane
View Plane = Near Plane -1,1,1
Mperspective_Matrix
Think about:
1,-1,-1
Clipping 3D Triangles
View Frustum Culling
Comparison with a camera
Let’s verbalize what’s going on
Review:
•Pipeline
•Series of steps
•What we’ll do next:
•Hidden Surface Removal
•Depth Buffers
•Lighting
•Shading
•Blending (the elusive alpha)
•Textures