transformations iii week 2, fri jan 19 · 2007. 1. 19. · week 2, fri jan 19. 2 readings for jan...

38
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007 Transformations III Week 2, Fri Jan 19

Upload: others

Post on 15-Sep-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

University of British ColumbiaCPSC 314 Computer Graphics

Jan-Apr 2007

Tamara Munzner

http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007

Transformations III

Week 2, Fri Jan 19

Page 2: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

2

Readings for Jan 15-22

• FCG Chap 6 Transformation Matrices• except 6.1.6, 6.3.1

• FCG Sect 13.3 Scene Graphs

• RB Chap Viewing• Viewing and Modeling Transforms until Viewing

Transformations

• Examples of Composing Several Transformationsthrough Building an Articulated Robot Arm

• RB Appendix Homogeneous Coordinates andTransformation Matrices

• until Perspective Projection

• RB Chap Display Lists

Page 3: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

3

News

• reminder: office hours today after class in011 lab

• reminder: course newsgroup isubc.courses.cpsc.414

Page 4: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

4

Review: Shear, Reflection

• shear along x axis• push points to right in proportion to height

• reflect across x axis• mirror

x

y

x

y

+

=

0

0

10

1

y

xsh

y

x x

+

−=

0

0

10

01

y

x

y

x

x x

Page 5: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

5

Review: 2D Transformations

=

+

+=

+

'

'

y

x

by

ax

b

a

y

x

( ) ( )( ) ( )

−=

y

x

y

x

θθ

θθ

cossin

sincos

'

'

=

y

x

b

a

y

x

0

0

'

'

scaling matrix rotation matrix

=

'

'

y

x

y

x

dc

ba

translation multiplication matrix??

vector addition

matrix multiplicationmatrix multiplication

),( ba(x,y)

(x_,y_)

Page 6: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

6

Review: Linear Transformations

• linear transformations are combinations of• shear• scale• rotate• reflect

• properties of linear transformations• satisifes T(sx+ty) = s T(x) + t T(y)• origin maps to origin• lines map to lines• parallel lines remain parallel• ratios are preserved• closed under composition

=

y

x

dc

ba

y

x

'

'dycxy

byaxx

+=

+=

'

'

Page 7: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

7

Correction: Composing Transformations

• scaling

• rotation

=•∗

1

112

21

21

sysy

sxsx

SSso scales multiplyso scales multiply

++

+−+

=•

1

1

)21cos()21sin(

)21sin()21cos(

12θθθθ

θθθθ

RRso rotations addso rotations add

Page 8: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

8

Review: 3D Homog Transformations

• use 4x4 matrices for 3D transformations

=

11

1

1

1

1

'

'

'

z

y

x

c

b

a

z

y

x

translate(a,b,c)translate(a,b,c)

−=

11

cossin

sincos

1

1

'

'

'

z

y

x

z

y

x

θθ

θθ

),(Rotate θx

=

111

'

'

'

z

y

x

c

b

a

z

y

x

scale(a,b,c)scale(a,b,c)

1

cossin

1

sincos

θθ

θθ

),(Rotate θy

1

1

cossin

sincos

θθ

θθ

),(Rotate θz

Page 9: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

9

Review: Affine Transformations

• affine transforms are combinations of• linear transformations• translations

• properties of affine transformations• origin does not necessarily map to origin• lines map to lines• parallel lines remain parallel• ratios are preserved• closed under composition

=

w

y

x

fed

cba

w

y

x

100

'

'

Page 10: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

10

More: Composing Transformations

Ta Tb = Tb Ta, but RaTa Tb = Tb Ta, but Ra Rb Rb !=!= Rb Rb Ra and TaRa and Ta Rb Rb !=!= Rb Rb TaTa

• rotations around different axes do not commute

Page 11: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

11

p'= TRpReview: Composing Transformations

• which direction to read?• right to left

• interpret operations wrt fixed coordinates• moving object

• left to right• interpret operations wrt local coordinates• changing coordinate system• OpenGL updates current matrix with postmultiply

• glTranslatef(2,3,0);• glRotatef(-90,0,0,1);• glVertexf(1,1,1);

• specify vector last, in final coordinate system• first matrix to affect it is specified second-to-last

OpenGL pipeline ordering!

Page 12: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

12

(2,1)(1,1)

(1,1)

changing coordinate system

moving objecttranslate by (-1,0)

Interpreting Transformations

• same relative position between object andbasis vectors

intuitive?

OpenGL

Page 13: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

13

Matrix Composition

• matrices are convenient, efficient way to representseries of transformations• general purpose representation• hardware matrix multiply• matrix multiplication is associative

• p_ = (T*(R*(S*p)))• p_ = (T*R*S)*p

• procedure• correctly order your matrices!• multiply matrices together• result is one matrix, multiply vertices by this matrix• all vertices easily transformed with one matrix multiply

Page 14: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

14

Rotation About a Point: Moving Object

FFWW

translate p translate p to originto origin

θ

p = (x,y)

rotate about rotate about p by : p by :θ

rotate aboutrotate aboutoriginorigin

translate p translate p backback

T(x,y,z)R(z,θ)T(−x,−y,−z)

Page 15: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

15

Rotation: Changing Coordinate Systems

• same example: rotation around arbitrarycenter

Page 16: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

16

Rotation: Changing Coordinate Systems

• rotation around arbitrary center• step 1: translate coordinate system to rotation

center

Page 17: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

17

Rotation: Changing Coordinate Systems

• rotation around arbitrary center• step 2: perform rotation

Page 18: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

18

Rotation: Changing Coordinate Systems

• rotation around arbitrary center• step 3: back to original coordinate system

Page 19: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

19

General Transform Composition

• transformation of geometry into coordinatesystem where operation becomes simpler• typically translate to origin

• perform operation

• transform geometry back to originalcoordinate system

Page 20: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

20

Rotation About an Arbitrary Axis

• axis defined by two points

• translate point to the origin

• rotate to align axis with z-axis (or x or y)

• perform rotation

• undo aligning rotations

• undo translation

Page 21: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

Arbitrary Rotation

• problem:• given two orthonormal coordinate systems XYZ and UVW

• find transformation from one to the other• answer:

• transformation matrix R whose columns are U,V,W:

R =

ux vx wx

uy vy wy

uz vz wz

Y Z

X

W

V

U

Page 22: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

22

Arbitrary Rotation

• why?

• similarly R(Y) = V & R(Z) = W€

R(X) =

ux vx wx

uy vy wy

uz vz wz

100

= (ux,uy,uz)=U

Page 23: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

23

Transformation Hierarchies

Page 24: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

24

Transformation Hierarchies

• scene may have a hierarchy of coordinatesystems• stores matrix at each level with incremental

transform from parent’s coordinate system

• scene graph roadroad

stripe1stripe1 stripe2stripe2 ...... car1car1 car2car2 ......

w1w1 w3w3w2w2 w4w4

Page 25: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

25

Transformation Hierarchy Example 1

torsotorso

headheadRUarmRUarm

RLarmRLarm

RhandRhand

RUlegRUleg

RLlegRLleg

RfootRfoot

LUarmLUarm

LLarmLLarm

LhandLhand

LUlegLUleg

LLlegLLleg

LfootLfoot

worldworld

trans(0.30,0,0) rot(z, )trans(0.30,0,0) rot(z, )θ

Page 26: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

26

Transformation Hierarchies

• hierarchies don’t fall apart when changed

• transforms apply to graph nodes beneath

Page 27: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

27

Demo: Brown Applets

http://www.http://www.cscs.brown..brown.eduedu//exploratoriesexploratories//freeSoftwarefreeSoftware/catalogs//catalogs/scenegraphsscenegraphs.html.html

Page 28: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

28

Transformation Hierarchy Example 2

• draw same 3D data with differenttransformations: instancing

Page 29: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

29

Matrix Stacks

• challenge of avoiding unnecessarycomputation• using inverse to return to origin

• computing incremental T1 -> T2Object coordinatesObject coordinates

World coordinatesWorld coordinates

TT11(x)(x) TT22(x)(x)

TT33(x)(x)

Page 30: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

30

Matrix Stacks

glPushMatrixglPushMatrix()()

glPopMatrixglPopMatrix()()

AA

BB

CC

AA

BB

CC

AA

BB

CC

CC

glScale3f(2,2,2)glScale3f(2,2,2)

D = C scale(2,2,2) trans(1,0,0)D = C scale(2,2,2) trans(1,0,0)

AA

BB

CC

DD

DrawSquareDrawSquare()()

glTranslate3f(1,0,0)glTranslate3f(1,0,0)

DrawSquareDrawSquare()()

glPushMatrixglPushMatrix()()

glPopMatrixglPopMatrix()()

Page 31: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

31

Modularization

• drawing a scaled square• push/pop ensures no coord system change

voidvoid drawBlock drawBlock(float k) {(float k) { glPushMatrix glPushMatrix();();

glScalef glScalef(k,k,k);(k,k,k); glBegin glBegin(GL_LINE_LOOP);(GL_LINE_LOOP); glVertex3f(0,0,0); glVertex3f(0,0,0); glVertex3f(1,0,0); glVertex3f(1,0,0); glVertex3f(1,1,0); glVertex3f(1,1,0); glVertex3f(0,1,0); glVertex3f(0,1,0); glEnd glEnd();();

glPopMatrix glPopMatrix();();}}

Page 32: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

32

Matrix Stacks

• advantages• no need to compute inverse matrices all the time

• modularize changes to pipeline state

• avoids incremental changes to coordinate systems• accumulation of numerical errors

• practical issues• in graphics hardware, depth of matrix stacks is

limited• (typically 16 for model/view and about 4 for projective

matrix)

Page 33: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

33

Transformation Hierarchy Example 3

FFWW

FFhh

FFhh

glLoadIdentityglLoadIdentity();();glTranslatefglTranslatef(4,1,0);(4,1,0);glPushMatrixglPushMatrix();();glRotatefglRotatef(45,0,0,1);(45,0,0,1);glTranslatefglTranslatef(0,2,0);(0,2,0);glScalefglScalef(2,1,1);(2,1,1);glTranslateglTranslate(1,0,0);(1,0,0);glPopMatrixglPopMatrix();();

FF11

FF hh

FF hh

FF hh

FF hh

FFhh

Page 34: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

34

Transformation Hierarchy Example 4

1θ5θ 3θ

xx

yy

glTranslate3f(x,y,0);glTranslate3f(x,y,0);glRotatefglRotatef( ,0,0,1);( ,0,0,1);DrawBodyDrawBody();();glPushMatrixglPushMatrix();(); glTranslate3f(0,7,0); glTranslate3f(0,7,0); DrawHead DrawHead();();glPopMatrixglPopMatrix();();glPushMatrixglPushMatrix();(); glTranslate glTranslate(2.5,5.5,0);(2.5,5.5,0); glRotatef glRotatef( ,0,0,1);( ,0,0,1); DrawUArm DrawUArm();(); glTranslate glTranslate(0,-3.5,0);(0,-3.5,0); glRotatef glRotatef( ,0,0,1);( ,0,0,1); DrawLArm DrawLArm();();glPopMatrixglPopMatrix();();... (draw other arm)... (draw other arm)

Page 35: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

35

Hierarchical Modelling

• advantages• define object once, instantiate multiple copies• transformation parameters often good control knobs• maintain structural constraints if well-designed

• limitations• expressivity: not always the best controls• can’t do closed kinematic chains

• keep hand on hip

• can’t do other constraints• collision detection

• self-intersection• walk through walls

Page 36: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

36

Single Parameter: Simple

• parameters as functions of other params• clock: control all hands with seconds s

m = s/60, h=m/60,

theta_s = (2 pi s) / 60,

theta_m = (2 pi m) / 60,

theta_h = (2 pi h) / 60

Page 37: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

37

Single Parameter: Complex

• mechanisms not easily expressible withaffine transforms

http://www.flying-pig.co.http://www.flying-pig.co.ukuk

Page 38: Transformations III Week 2, Fri Jan 19 · 2007. 1. 19. · Week 2, Fri Jan 19. 2 Readings for Jan 15-22 •FCG Chap 6 Transformation Matrices

38

Single Parameter: Complex

• mechanisms not easily expressible withaffine transforms

http://www.flying-pig.co.http://www.flying-pig.co.ukuk/mechanisms/pages/irregular.html/mechanisms/pages/irregular.html