0% found this document useful (0 votes)
45 views

CAP4730: Computational Structures in Computer Graphics: 3D Transformations

This document discusses 3D transformations in computer graphics, including translation, scaling, and rotation. It explains how these transformations are represented by matrices in 3D, with 4x4 transformation matrices for translation, scaling, and rotation about different axes. It also covers combining multiple transformations and applying the overall transformation to 3D points. Finally, it briefly discusses the camera model and transforming from world coordinates to camera coordinates using a rotation matrix and translation vector derived from the camera position and orientation.

Uploaded by

mashuashu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

CAP4730: Computational Structures in Computer Graphics: 3D Transformations

This document discusses 3D transformations in computer graphics, including translation, scaling, and rotation. It explains how these transformations are represented by matrices in 3D, with 4x4 transformation matrices for translation, scaling, and rotation about different axes. It also covers combining multiple transformations and applying the overall transformation to 3D points. Finally, it briefly discusses the camera model and transforming from world coordinates to camera coordinates using a rotation matrix and translation vector derived from the camera position and orientation.

Uploaded by

mashuashu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 48

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. T=(t , t , t ) x y z

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.

Q: Since 2D is sort of like a


special case of 3D, what is
the vector we’ve been
rotating about in 2D?
Rotations about the Z axis
What do you think the rotation matrix is for
rotations about the z axis?
R=(0,0,1,)
cos  sin  0
cos  sin   
R      sin  cos 0
 sin  cos  
 0 0 1
cos  sin  0 0
 sin  cos 0 0
R (0,0,1, )  
 0 0 1 0 
 
 0 0 0 1
Rotations about the X axis

Let’s look at the other axis rotations

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    Rx1    R y1     Rz    R y     Rx  
u

Steps:
  1. Normalize vector u
2. Compute 
 3. Compute 
4. Create rotation matrix
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. Let’s do an example.
V
Normalized _ V 
V
Computing the Rotation Matrix

• 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    Rx1    R y1     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

P'  T (t x , t y , t z ) R ( )T (t x ,t y ,t z ) P


P'  MP
 x'  a b c d  x
 y '  e f g h   y 
 
 z '  i j k l  z 
    
 1  m n o p 1 
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?
Let’s 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 Right
View Up

View Normal
View Direction
Camera
View Up

ViewRight
AspectRatio 
ViewUp

View Right

What is are the vectors?


Graphics Pipeline So Far
Object Transformation
Object Coordinates Object -> World

World Projection Xform


World Coordinates World -> Projection

Camera Normalize Xform & Clipping


Projection Coordinates Projection -> Normalized

Viewport Viewport Transform


Normalized Coordinates Normalized -> Device

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

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.

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

• Q: What do you get when you cross an


elephant with a mouse?

• A: Elephant Mouse sin 

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
L1  tan 1 
1 0 L1 cos  0
 
0 1 L1 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

 z' xp   z' z' 


 x'  x p    x'  x p  xp 
 zp w   zp hz p 
zp  z' yp   z' z' 
w ;  y'  y p   w  z p  y'  y p  yp 
z'  zp w   zp hz p 
 z'   fz p z' f 
 z'  z p   z '   
 zp   f  z' f  z' 
Perspective Divide

 z' z'   z'


0 0 0

 x'  x p  xp   
 zp hz p   x '   hhoriztonal  xp 
 z' z'   y '  z'  y p 
w  z p  y'  y p  yp    0 hvertical
0 0
 
 zp hz p   z'   z 
   0 far  near * far   p 
 fz p z' f  0 
z '    w far  near far  near   1 
  
 f  z' f  z'   0 0 1 0 

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

World Projection Xform


World Coordinates World -> Projection

Camera Normalize Xform & Clipping


Projection Coordinates Projection -> Normalized

Viewport Viewport Transform


Normalized Coordinates Normalized -> Device

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...

World Transformation - Modelview


World Coordinates World -> Eye/Camera

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

You might also like