CS 445 / 645: Introductory Computer Graphics

1 / 44

# CS 445 / 645: Introductory Computer Graphics - PowerPoint PPT Presentation

CS 445 / 645: Introductory Computer Graphics. Geometric Transforms. Matrix Manipulation - Example. Drawing a car with wheels and lugnuts. draw_wheel( ); for (j=0; j&lt;5; j++) { glPushMatrix (); glRotatef(72.0*j, 0.0, 0.0, 1.0); glTranslatef (3.0, 0.0, 0.0); draw_bolt ( );

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'CS 445 / 645: Introductory Computer Graphics' - donkor

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### CS 445 / 645: Introductory Computer Graphics

Geometric Transforms

Matrix Manipulation - Example

• Drawing a car with wheels and lugnuts

draw_wheel( );

for (j=0; j<5; j++) {

glPushMatrix ();

glRotatef(72.0*j, 0.0, 0.0, 1.0);

glTranslatef (3.0, 0.0, 0.0);

draw_bolt ( );

glPopMatrix ( );

Matrix Manipulation - Example

draw_wheel( );

for (j=0; j<5; j++) {

glPushMatrix ();

glRotatef(72.0*j, 0.0, 0.0, 1.0);

glTranslatef (3.0, 0.0, 0.0);

draw_bolt ( );

glPopMatrix ( );

Global – Bottom Up

Start

Rot

Trans

Matrix Manipulation - Example

draw_wheel( );

for (j=0; j<5; j++) {

glPushMatrix ();

glRotatef(72.0*j, 0.0, 0.0, 1.0);

glTranslatef (3.0, 0.0, 0.0);

draw_bolt ( );

glPopMatrix ( );

Local – Top Down

Start

Rot

Trans

Translation Matrices?
• We can composite scale matrices just as we did rotation matrices
• But how to represent translation as a matrix?
Homogeneous Coordinates
• Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector

(Note that typically w = 1 in object coordinates)

Homogeneous Coordinates
• Homogeneous coordinates seem unintuitive, but they make graphics operations much easier
• Our transformation matrices are now 4x4:
Homogeneous Coordinates
• Homogeneous coordinates seem unintuitive, but they make graphics operations much easier
• Our transformation matrices are now 4x4:
Homogeneous Coordinates
• Homogeneous coordinates seem unintuitive, but they make graphics operations mucheasier
• Our transformation matrices are now 4x4:
Homogeneous Coordinates
• Homogeneous coordinates seem unintuitive, but they make graphics operations much easier
• Our transformation matrices are now 4x4:
Homogeneous Coordinates
• How can we represent translation as a 4x4 matrix?
• A: Using the rightmost column:
Translation 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:
Translation 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:
Translation 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:
Translation 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:
Transformation 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 ?
More On Homogeneous Coords
• What effect does the following matrix have?
• Conceptually, the fourth coordinate wis a bit like a scale factor
Homogenous Coordinates
• In particular, increasing w makes things smaller
• We think of homogenous coordinates as defining a projective space
• Increasing w “getting further away”
• Will come in handy for projection matrices
Projection Matrix
• 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 projection as a matrix
• Next few slides: representing orthographic and perspective projection with the projection matrix
Orthographic Projection
• Simple OrthographicTransformation
• Original world units are preserved
• Pixel units are preferred
Orthographic: Screen Space Transformation

left =10 m

right = 20 m

top=20 m

(max pixx, max pixy)

(height in pixels)

(0, 0)

bottom=10 m

(width in pixels)

Orthographic: 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 Transformation
• 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:

How tall shouldthis bunny be?

Perspective Projection
• When we do 3-D graphics, we think of the screen as a 2-D window onto the 3-D world:

Viewplane

X

P (x, y, z)

x’ = ?

(0,0,0)

Z

Perspective Projection
• The geometry of the situation is that of similar triangles. View from above:
• What is x’ ?

d

Perspective Projection
• Desired result for a point [x, y, z, 1]T projected onto the view plane:
• What could a matrix look like to do this?
A Perspective Projection Matrix
• Example:
• Or, in 3-D coordinates:
Perspective Projection
• Translate model units to pixel units
Projection 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
A 3D Scene
• Notice the presence ofthe camera, theprojection plane, and the worldcoordinate 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 worldspace 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]TWhy?
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: