Title: CS 551 / 645: Introductory Computer Graphics
1CS 551 / 645 Introductory Computer Graphics
2Administrivia
- Return assignment 1
- Hand out assignment 2
- Todays reading material FvD, Chapter 5
3Recap Rendering Pipeline (3-D)
Scene graphObject geometry
- Result
- All vertices of scene in shared 3-D world
coordinate system - Vertices shaded according to lighting model
- Scene vertices in 3-D view or camera
coordinate system - Exactly those vertices portions of polygons in
view frustum - 2-D screen coordinates of clipped vertices
ModelingTransforms
LightingCalculations
ViewingTransform
Clipping
ProjectionTransform
4Recap Transformations
- Modeling transforms
- Size, place, scale, and rotate objects parts of
the model w.r.t. each other - Object coordinates ? world coordinates
Y
Z
X
5Rigid-Body Transforms
- Goal object coordinates?world coordinates
- Idea use only transformations that preserve the
shape of the object - Rigid-body or Euclidean transforms
- Includes rotation, translation, and scale
- To reiterate we will represent points as column
vectors
6Translations
- For convenience we usually describe objects in
relation to their own coordinate system - We can translate or move points to a new position
by adding offsets to their coordinates - Note that this translates all points uniformly
7Scaling
- Scaling a coordinate means multiplying each of
its components by a scalar - Uniform scaling means this scalar is the same for
all components
? 2
8Scaling
- Non-uniform scaling different scalars per
component - How can we represent this in matrix form?
X ? 2,Y ? 0.5
9Scaling
- Scaling operation
- Or, in matrix form
scaling matrix
102-D Rotation
(x, y)
(x, y)
x x cos(?) - y sin(?) y x sin(?) y cos(?)
?
112-D Rotation
- This is easy to capture in matrix form
- 3-D is more complicated
- Need to specify an axis of rotation
- Simple cases rotation about X, Y, Z axes
123-D Rotation
- What does the 3-D rotation matrix look like for a
rotation about the Z-axis? - Build it coordinate-by-coordinate
133-D Rotation
- What does the 3-D rotation matrix look like for a
rotation about the Y-axis? - Build it coordinate-by-coordinate
143-D Rotation
- What does the 3-D rotation matrix look like for a
rotation about the X-axis? - Build it coordinate-by-coordinate
153-D Rotation
- General rotations in 3-D require rotating about
an arbitrary axis of rotation - Deriving the rotation matrix for such a rotation
directly is a good exercise in linear algebra - Standard approach express general rotation as
composition of canonical rotations - Rotations about X, Y, Z
16Composing Canonical Rotations
- Goal rotate about arbitrary vector A by ?
- Idea we know how to rotate about X,Y,Z
- So, rotate about Y by ? until A lies in the YZ
plane - Then rotate about X by ? until A coincides with
Z - Then rotate about Z by ?
- Then reverse the rotation about X (by -?)
- Then reverse the rotation about Y (by -?)
17Composing Canonical Rotations
- First rotating about Y by ? until A lies in YZ
- Draw it
- How exactly do we calculate ??
- Project A onto XZ plane
- Find angle ? to X
- ? -(90 - ?) ? - 90
- Second rotating about X by ? until A lies on Z
- How do we calculate ??
18Composing Canonical Rotations
- Why are we slogging through all this tedium?
- A Because youll have to do it on the test
193-D Rotation Matrices
- So an arbitrary rotation about A composites
several canonical rotations together - We can express each rotation as a matrix
- Compositing transforms multiplying matrices
- Thus we can express the final rotation as the
product of canonical rotation matrices - Thus we can express the final rotation with a
single matrix!
20Compositing Matrices
- So we have the following matrices
- p The point to be rotated about A by ?
- Ry? Rotate about Y by ?
- Rx ? Rotate about X by ?
- Rz? Rotate about Z by ?
- Rx ? -1 Undo rotation about X by ?
- Ry?-1 Undo rotation about Y by ?
- In what order should we multiply them?
21Compositing Matrices
- Short answer the transformations, in order, are
written from right to left - In other words, the first matrix to affect the
vector goes next to the vector, the second next
to the first, etc. - So in our case
- p Ry?-1 Rx ? -1 Rz? Rx ? Ry? p
22Rotation Matrices
- Notice these two matrices
- Rx ? Rotate about X by ?
- Rx ? -1 Undo rotation about X by ?
- How can we calculate Rx ? -1?
23Rotation Matrices
- Notice these two matrices
- Rx ? Rotate about X by ?
- Rx ? -1 Undo rotation about X by ?
- How can we calculate Rx ? -1?
- Obvious answer calculate Rx (-?)
- Clever answer exploit fact that rotation
matrices are orthonormal
24Rotation Matrices
- Notice these two matrices
- Rx ? Rotate about X by ?
- Rx ? -1 Undo rotation about X by ?
- How can we calculate Rx ? -1?
- Obvious answer calculate Rx (-?)
- Clever answer exploit fact that rotation
matrices are orthonormal - What is an orthonormal matrix?
- What property are we talking about?
25Rotation Matrices
- Orthonormal matrix
- orthogonal (columns/rows linearly independent)
- Columns/rows length of 1
- The inverse of an orthogonal matrix is just its
transpose
26Translation Matrices?
- We can composite scale matrices just as we did
rotation matrices - But how to represent translation as a matrix?
- Answer with homogeneous coordinates
27Homogeneous Coordinates
- Homogeneous coordinates represent coordinates in
3 dimensions with a 4-vector -
- (Note that typically w 1 in object coordinates)
28Homogeneous Coordinates
- Homogeneous coordinates seem unintuitive, but
they make graphics operations much easier - Our transformation matrices are now 4x4
29Homogeneous Coordinates
- Homogeneous coordinates seem unintuitive, but
they make graphics operations much easier - Our transformation matrices are now 4x4
30Homogeneous Coordinates
- Homogeneous coordinates seem unintuitive, but
they make graphics operations much easier - Our transformation matrices are now 4x4
31Homogeneous Coordinates
- Homogeneous coordinates seem unintuitive, but
they make graphics operations much easier - Our transformation matrices are now 4x4
32Homogeneous Coordinates
- How can we represent translation as a 4x4
matrix? - A Using the rightmost column
33Translation Matrices
- Now that we can represent translation as a
matrix, we can composite it with other
transformations - Ex rotate 90 about X, then 10 units down Z
34Translation Matrices
- Now that we can represent translation as a
matrix, we can composite it with other
transformations - Ex rotate 90 about X, then 10 units down Z
35Translation Matrices
- Now that we can represent translation as a
matrix, we can composite it with other
transformations - Ex rotate 90 about X, then 10 units down Z
36Translation Matrices
- Now that we can represent translation as a
matrix, we can composite it with other
transformations - Ex rotate 90 about X, then 10 units down Z
37Transformation Commutativity
- Is matrix multiplication, in general,
commutative? Does AB BA? - What about rotation, scaling, and translation
matrices? - Does RxRy RyRx?
- Does RAS SRA ?
- Does RAT TRA ?
38More On Homogeneous Coords
- What effect does the following matrix have?
- Conceptually, the fourth coordinate w is a bit
like a scale factor
39Homogenous Coordinates
- In particular, increasing w makes things smaller
- We think of homogenous coordinates as defining a
projective space - Increasing w ? getting further away
- Points with w 0 are, in this sense, projected
on the plane at infinity - Will come in handy for projection matrices
40Perspective Projection
- We talked about geometric transforms, focusing on
modeling transforms - Ex translation, rotation, scale, gluLookAt()
- These are encapsulated in the OpenGL modelview
matrix - Can also express perspective projection (and
other projections) as a matrix - Next few slides representing perspective
projection with the projection matrix
41Perspective Projection
- In the real world, objects exhibit perspective
foreshortening distant objects appear smaller - The basic situation
42Perspective Projection
- When we do 3-D graphics, we think of the screen
as a 2-D window onto the 3-D world
How tall shouldthis bunny be?
43Perspective Projection
- The geometry of the situation is that of similar
triangles. View from above - What is x?
Viewplane
P (x, y, z)
X
x ?
(0,0,0)
Z
d
44Perspective Projection
- Desired result for a point x, y, z, 1T
projected onto the view plane - What could a matrix look like to do this?
45A Perspective Projection Matrix
46A Perspective Projection Matrix
- Example
- Or, in 3-D coordinates
47Projection Matrices
- Now that we can express perspective
foreshortening as a matrix, we can composite it
onto our other matrices with the usual matrix
multiplication - End result a single matrix encapsulating
modeling, viewing, and projection transforms
48Matrix Operations In OpenGL
- Certain commands affect the current matrix in
OpenGL - glMatrixMode() sets the current matrix
- glLoadIdentity() replaces the current matrix with
an identity matrix - glTranslate() postmultiplies the current matrix
with a translation matrix - gluPerspective() postmultiplies the current
matrix with a perspective projection matrix - It is important that you understand the order in
which OpenGL concatenates matrices
49Matrix Operations In OpenGL
- In OpenGL
- Vertices are multiplied by the modelview matrix
- The resulting vertices are multiplied by the
projection matrix - Example
- Suppose you want to scale an object, translate
it, apply a lookat transformation, and view it
under perspective projection. What order should
you make calls?
50Matrix Operations in OpenGL
- Problem scale an object, translate it, apply a
lookat transformation, and view it under
perspective - A correct code fragment
- glMatrixMode(GL_PERSPECTIVE)
- glLoadIdentity()
- gluPerspective()
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- gluLookAt()
- glTranslate()
- glScale()
- / Draw the object... /
51Matrix Operations in OpenGL
- Problem scale an object, translate it, apply a
lookat transformation, and view it under
perspective - An incorrect code fragment
- glMatrixMode(GL_PERSPECTIVE)
- glLoadIdentity()
- glTranslate()
- glScale()
- gluPerspective()
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- gluLookAt()
- / Draw the object... /