CS 551 / 645:
Introductory Computer Graphics
Viewing Transforms
Administrivia
Assignment 2 is online - get started this
weekend
Midterm will be before reading break - Oct 19
Today’s reading material: FvD, Chapter 6
Translations
Moving an object is called a translation. We translate a point by adding to
the x and y coordinates, respectively, the amount the point should be
shifted in the x and y directions. We translate an object by translating
each vertex in the object.
ty
tx
xnew = xold + tx; ynew = yold + ty
Scaling
Changing the size of an object is called a scale. We scale an object by
scaling the x and y coordinates of each vertex in the object.
hnew
hold
wold wnew
sx=wnew/wold sy=hnew/hold
xnew = sxxold ynew = syyold
Rotation about the Origin
To rotate a line or polygon, we must rotate each
of its vertices. y-axis
We want to rotate point (x1,y1) to point (x2,y2) (x2,y2)
through angle B
(x1,y1)
From the illustration we know that:
r
sin (A + B) = y2/r cos (A + B) = x2/r B
sin A = y1/r cos A = x1/r A
(0,0)
x-axis
Rotation about the origin (cont.)
From the double angle formulas: sin (A + B) = sinAcosB + cosAsinB
Substituting: y2/r = (y1/r)cosB + (x1/r)sinB
Therefore: y2 = y1cosB + x1sinB
We have x2 = x1cosB - y1sinB
y2 = x1sinB + y1cosB
Transformations as matrices
Scale:
xnew = sxxold sx 0 x sx x
0
ynew = syyold
s y y s y y
Rotation:
x2 = x1cos - y1sin
cos sin x x cos y sin
y2 = x1sin + y1cos
sin
cos y x sin y cos
Translation:
xnew = xold + tx
t x x x t x
ynew = yold + ty
t y t
y y y
Homogeneous Coordinates
In order to represent a translation as a matrix multiplication operation we
use 3 x 3 matrices and pad our points to become 3 x 1 matrices. This
coordinate system (using three values to represent a 2D point) is called
homogeneous coordinates.
x cos sin 0
P( x , y ) y R sin cos 0
1 0 0 1
sx 0 0 1 0 t x
S x, y 0 sy 0 Tx , y 0 1 t y
0 0 1 0 0 1
Composite Transformations
Suppose we wished to perform multiple transformations on a point:
P2 T3,1 P1
P3 S2, 2 P2
P4 R30 P3
M R30 S2,2 T3,1
P4 MP1
Remember:
• Matrix multiplication is associative, not commutative!
• Transform matrices must be pre-multiplied
• The first transformation you want to perform will be at the far
right, just before the point
Composite Transforms -
Scaling (cont.)
If we scale a line between (0,0) & (2,0) to twice its length, the left-hand
endpoint does not move.
Before After
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10
(0,0) is known as a fixed point for the basic scaling transformation.
We can use composite transformations to create a scale
transformation with different fixed points.
Fixed Point Scaling
Scale by 2 with fixed point = (2,1)
Translate the point (2,1) to the origin
Scale by 2
Translate origin to point (2,1)
Before
1 0 2 2 0 0 1 0 2 2 0 2 0 1 2 3 4 5 6 7 8 9 10
0 1 1 0 1 0 0 1 1 0 1 0
0 0 1 0 0 1 0 0 1 0 0 1
T2,1 S 2,1 T 2, 1 C
2 0 22 2 2 0 2 4 6
0 1 0 1 1 After
0 1 0 1 1
0 0 1 1 1 0 0 1 1 1
C C 0 1 2 3 4 5 6 7 8 9 10
Rotation about a Fixed Point
Rotation Of Degrees About Point (x,y)
Translate (x,y) to origin
Rotate (x,y) (x,y)
Translate origin to (x,y)
1 0 x cos sin 0 1 0 x
C 0 1 y sin cos 0 0 1 y
0 0 1 0 0 1 0 0 1
Tx , y R T x , y
Shears
Original Data y Shear x Shear
1 0 0 1 b 0
a 1 0 0 1 0
0 0 1 0 0 1
Reflections
Reflection about the y-axis Reflection about the x-axis
1 0 0 1 0 0
0 1 0 0 1 0
0 0 1 0 0 1
More Reflections
Reflection about the origin Reflection about the line y=x
1 0 0
0 1 0
?
0 0 1
?
Transformations as a change in
coordinate system
All transformations we have looked at involve
transforming points in a fixed coordinate
system (CS).
Can also think of them as a transformation of
the CS itself
Transforming the CS - examples
Translate(4,4)
Rotate(180°)
Why transform the CS?
Objects often defined in a “natural” or
“convenient” CS
To draw objects transformed
(2,2) by T, we could:
– Transform each vertex by T, then draw
– Or, draw vertices in a transformed CS
Drawing in transformed CS
Tell system once how to draw the object,
then draw in a transformed CS to transform
the object
House drawn in a CS
that’s been translated,
rotated, and scaled
M = Sx,y Rd Tx,y
Projecting 3-D into 2-D
Rotations and translations are sufficient to
convert 3D to 2D
We frequently map from world space (3D)
into eye space (2D)
Create a special class of transformations for
this mapping: viewing transformations
A 3D Scene
Notice the presence of
the camera, the projection
plane, and the world
coordinate axes
Viewing transformations define how to
acquire the image on the projection plane
Viewing Transformations
Create a camera-centered view
Camera is at origin
Camera is looking along negative z-axis
Camera’s ‘up’ is aligned with y-axis
2 Basic Steps
Align the two coordinate frames by rotation
2 Basic Steps
Translate to align origins
Creating Camera Coordinate
Space
Specify a point where the camera is located
in world space, the eye point
Specify a point in world space that we wish to
become the center of view, the lookat point
Specify a vector in world
space that we wish to
point up in camera
image, the up vector
Intuitive camera
movement
Constructing Viewing
Transformation, V
Create a vector from eye-point to lookat-point
Normalize the vector
Desired rotation matrix should map this
vector to [0, 0, -1]T Why?
Constructing Viewing
Transformation, V
Construct another important vector from the
cross product of the lookat-vector and the
vup-vector
This vector, when normalized, should align
with [1, 0, 0]T Why?
Constructing Viewing
Transformation, V
One more vector to define…
This vector, when normalized, should align
with [0, 1, 0]T
Now let’s composite the results
Compositing Vectors to Form V
We know the three world axis vectors (x, y, z)
We know the three camera axis vectors (u, v, n)
Viewing transformation, V, must convert from
world to camera coordinate systems
Compositing Vectors to Form V
Remember
– Each camera axis vector is unit length.
– Each camera axis vector is perpendicular to others
Camera matrix is orthogonal and normalized
– Orthonormal
Therefore, M-1 = MT
Compositing Vectors to Form V
Therefore, rotation component of viewing
transformation is just transpose of computed
vectors
Compositing Vectors to Form V
Translation component too
Multiply it through
Final Viewing Transformation, V
To transform vertices, use this matrix:
And you get this:
Special Viewing Transformations
Orthographic is one alternative
Orthographic Transformation
Simple Orthographic Transformation
Original world units are preserved
– Pixel units are preferred
Screen-space Transformation
left, right, top, bottom refer to the viewing
frustum in modeling coordinates
width and height are in pixel units
This matrix scales and translates to
accomplish the transition in units
Perspective Projections
First discovered by Donatello, Brunelleschi,
and DaVinci during Renaissance
Objects closer to viewer look larger
Parallel lines appear to converge to single
point
Perspective Projection
In the real world, objects exhibit perspective
foreshortening: distant objects appear smaller
The basic situation:
Perspective Projection
When we do 3-D graphics, we think of the
screen as a 2-D window onto the 3-D world:
How tall should
this bunny be?
Perspective Projection
The geometry of the situation is that of
similar triangles. View from above:
P (x, y, z) View
plane
y’ = ?
Z (0,0,0)
What is y’? d
Perspective Projection
Desired result for a point [x, y, z, 1]T projected
onto the view plane:
x' x y' y
,
d z d z
dx x dy y
x' , y' , zd
z z d z z d
What could a matrix look like to do this?
A Perspective Projection Matrix
Answer:
1 0 0 0
0 1 0
0
Mperspective
0 0 1 0
0 0 1d 0
A Perspective Projection Matrix
Example:
x 1 0 0 0 x
y 0 1 0
0 y
z 0 0 1 0 z
z d 0 0 1d 0 1
Or, in 3-D coordinates:
x y
, , d
z d zd
Screen-space Coordinates
Translate model units to pixel units
Canonical Perspective View
Volume
Perspective view volume is shaped like a
truncated pyramid
A canonical perspective view volumes scale
a perspective view volume
– Base has sides length 2
– Height is 1
– Origin is centered
Canonical Space Mapping for
Perspective Projection