Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

26
Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003

description

David Luebke 3 1/24/2016 Admin ● Assn 1 due… now ■ Any issues?

Transcript of Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

Page 1: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

Transformations: Projection

CS 445/645Introduction to Computer Graphics

David Luebke, Spring 2003

Page 2: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 2 05/03/23

Admin

● Assn 1 due…

Page 3: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 3 05/03/23

Admin

● Assn 1 due… now■ Any issues?

Page 4: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 4 05/03/23

Recap: 3-D Rotation Matrices

● An arbitrary rotation about A can be formed by compositing 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!

Page 5: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 5 05/03/23

Recap: Compositing Matrices

● 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 ● Thus:

p’ = Ry-1 Rx

-1 Rz Rx Ry p

Page 6: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 6 05/03/23

Recap: Rotation Matrices

● Rotation matrix is orthogonal■ Columns/rows linearly independent■ Columns/rows sum to 1

● The inverse of an orthogonal matrix is its transpose:

jfciebhda

jihfedcba

jihfedcba T1

Page 7: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 7 05/03/23

Recap:Homogeneous Coordinates

● Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector

(Note that typically w = 1 in object coordinates)

wzyx

wzwywx

zyx

1///

),,(

Page 8: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 8 05/03/23

Recap:Homogeneous Coordinates

● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier

● Our transformation matrices are now 4x4:

10000)cos()sin(00)sin()cos(00001

xR

Page 9: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 9 05/03/23

Recap:Homogeneous Coordinates

● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier

● Our transformation matrices are now 4x4:

10000)cos(0)sin(00100)sin(0)cos(

yR

Page 10: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 10 05/03/23

Recap:Homogeneous Coordinates

● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier

● Our transformation matrices are now 4x4:

1000010000)cos()sin(00)sin()cos(

zR

Page 11: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 11 05/03/23

Recap:Homogeneous Coordinates

● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier

● Our transformation matrices are now 4x4:

1000000000000

z

y

x

SS

S

S

Page 12: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 12 05/03/23

Recap:Homogeneous Coordinates

● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier

● Our transformation matrices are now 4x4:

1 0 00 1 00 0 10 0 0 1

x

y

z

TTT

T

Page 13: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 13 05/03/23

Recap: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:

wzyx

wzyx

10000)90cos()90sin(00)90sin()90cos(00001

10001010000100001

''''

Page 14: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 14 05/03/23

Recap: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:

wzyx

wzyx

1000001001000001

10001010000100001

''''

Page 15: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 15 05/03/23

Recap: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:

wzyx

wzyx

10001001001000001

''''

Page 16: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 16 05/03/23

Recap: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:

wy

zx

wzyx

10''''

Page 17: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 17 05/03/23

More On Homogeneous Coords

● What effect does the following matrix have?

● Conceptually, the fourth coordinate w is a bit like a scale factor

wzyx

wzyx

10000010000100001

''''

Page 18: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 18 05/03/23

More On Homogeneous Coords

● Intuitively:■ The w coordinate of a homogeneous point is typically 1■ Decreasing w makes the point “bigger”, meaning further

from the origin■ Homogeneous points with w = 0 are thus “points at

infinity”, meaning infinitely far away in some direction. (What direction?)

■ To help illustrate this, imagine subtracting two homogeneous points

Page 19: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 19 05/03/23

Perspective Projection

● In the real world, objects exhibit perspective foreshortening: distant objects appear smaller

● The basic situation:

Page 20: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 20 05/03/23

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 shouldthis bunny be?

Page 21: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 21 05/03/23

Perspective Projection

● The geometry of the situation is that of similar triangles. View from above:

● What is x’?

P (x, y, z)X

Z

Viewplane

d

(0,0,0) x’ = ?

Page 22: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 22 05/03/23

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?

dzdz

yz

ydydz

xz

xdx

zy

dy

zx

dx

,','

','

Page 23: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 23 05/03/23

A Perspective Projection Matrix

● Answer:

0100010000100001

d

M eperspectiv

Page 24: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 24 05/03/23

A Perspective Projection Matrix

● Example:

● Or, in 3-D coordinates:

10100010000100001

zyx

ddzzyx

d

dzy

dzx ,,

Page 25: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 25 05/03/23

A Perspective Projection Matrix

● OpenGL’s gluPerspective() command generates a slightly more complicated matrix:

■ Can you figure out what this matrix does?

2cotwhere

0100

200

000

000

y

farnear

nearfar

farnear

nearfar

fovf

ZZZZ

ZZZΖ

faspect

f

Page 26: Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

David Luebke 26 05/03/23

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: can create a single matrix encapsulating modeling, viewing, and projection transforms■ Though you will recall that in practice OpenGL separates

the modelview from projection matrix (why?)