transformations iii week 3, mon jan 21

28
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner http://www.ugrad.cs.ubc.ca/~cs314/ Vjan2008 Transformations III Week 3, Mon Jan 21

Upload: jillian-adriano

Post on 31-Dec-2015

21 views

Category:

Documents


0 download

DESCRIPTION

http://www.ugrad.cs.ubc.ca/~cs314/Vjan2008. Transformations III Week 3, Mon Jan 21. Readings for Jan 16-25. 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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Transformations III Week 3, Mon Jan 21

University of British ColumbiaCPSC 314 Computer Graphics

Jan-Apr 2008

Tamara Munzner

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

Transformations III

Week 3, Mon Jan 21

Page 2: Transformations III Week 3, Mon Jan 21

2

Readings for Jan 16-25

• 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 Transformations through

Building an Articulated Robot Arm

• RB Appendix Homogeneous Coordinates and Transformation Matrices

• until Perspective Projection

• RB Chap Display Lists

Page 3: Transformations III Week 3, Mon Jan 21

3

News

• Homework 1 out today

Page 4: Transformations III Week 3, Mon Jan 21

4

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

1 hyx hzx 0

hxy 1 hzy 0

hxz hyz 1 0

0 0 0 1

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

shear(hxy,hxz,hyx,hyz,hzx,hzy)shear(hxy,hxz,hyx,hyz,hzx,hzy)

Page 5: Transformations III Week 3, Mon Jan 21

5

Review: Composing Transformations

Ta Rb != Rb Ta Ta Rb != Rb Ta

Page 6: Transformations III Week 3, Mon Jan 21

6

p'=TRp

Review: 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);

OpenGL pipeline ordering!

Page 7: Transformations III Week 3, Mon Jan 21

7

Matrix Composition

• matrices are convenient, efficient way to represent series 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 8: Transformations III Week 3, Mon Jan 21

8

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 9: Transformations III Week 3, Mon Jan 21

9

Rotation: Changing Coordinate Systems

• same example: rotation around arbitrary center

Page 10: Transformations III Week 3, Mon Jan 21

10

Rotation: Changing Coordinate Systems

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

center

Page 11: Transformations III Week 3, Mon Jan 21

11

Rotation: Changing Coordinate Systems

• rotation around arbitrary center• step 2: perform rotation

Page 12: Transformations III Week 3, Mon Jan 21

12

Rotation: Changing Coordinate Systems

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

Page 13: Transformations III Week 3, Mon Jan 21

13

General Transform Composition

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

• perform operation

• transform geometry back to original coordinate system

Page 14: Transformations III Week 3, Mon Jan 21

14

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 15: Transformations III Week 3, Mon Jan 21

Arbitrary Rotation

• arbitrary rotation: change of basis • given two orthonormal coordinate systems XYZ and ABC

• A’s location in the XYZ coordinate system is (ax, ay, az, 1), ...

• transformation from one to the other is matrix R whose columns are A,B,C:

Y

ZX

B

C

A

Y

ZX

B

C

A

(cx, cy, cz,

1)

(ax, ay, az,

1)

(bx, by, bz,

1)

R(X) =

ax bx cx 0

ay by cy 0

az bz cz 0

0 0 0 1

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

1

0

0

1

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

= (ax,ay,az,1) = A

Page 16: Transformations III Week 3, Mon Jan 21

16

Transformation Hierarchies

Page 17: Transformations III Week 3, Mon Jan 21

17

Transformation Hierarchies

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

transform from parent’s coordinate system

• scene graph roadroad

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

w1w1 w3w3w2w2 w4w4

Page 18: Transformations III Week 3, Mon Jan 21

18

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 19: Transformations III Week 3, Mon Jan 21

19

Transformation Hierarchy Example 2

• draw same 3D data with different transformations: instancing

Page 20: Transformations III Week 3, Mon Jan 21

20

Transformation Hierarchies Demo

• transforms apply to graph nodes beneath

http://www.cs.brown.edu/exploratories/freeSoftware/catalogs/http://www.cs.brown.edu/exploratories/freeSoftware/catalogs/scenegraphs.htmlscenegraphs.html

Page 21: Transformations III Week 3, Mon Jan 21

21

Transformation Hierarchies Demo

• transforms apply to graph nodes beneath

http://www.cs.brown.edu/exploratories/freeSoftware/catalogs/http://www.cs.brown.edu/exploratories/freeSoftware/catalogs/scenegraphs.htmlscenegraphs.html

Page 22: Transformations III Week 3, Mon Jan 21

22

Matrix Stacks

• challenge of avoiding unnecessary computation• 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 23: Transformations III Week 3, Mon Jan 21

23

Matrix Stacks

glPushMatrix()glPushMatrix()

glPopMatrix()glPopMatrix()

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

DrawSquare()DrawSquare()

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

DrawSquare()DrawSquare()

glPushMatrix()glPushMatrix()

glPopMatrix()glPopMatrix()

Page 24: Transformations III Week 3, Mon Jan 21

24

Modularization

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

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

glScalef(k,k,k);glScalef(k,k,k); glBegin(GL_LINE_LOOP);glBegin(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 25: Transformations III Week 3, Mon Jan 21

25

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 26: Transformations III Week 3, Mon Jan 21

26

Transformation Hierarchy Example 3

FFWW

FFhh

FFhh

glLoadIdentity();glLoadIdentity();glTranslatef(4,1,0);glTranslatef(4,1,0);glPushMatrix();glPushMatrix();glRotatef(45,0,0,1);glRotatef(45,0,0,1);glTranslatef(0,2,0);glTranslatef(0,2,0);glScalef(2,1,1);glScalef(2,1,1);glTranslate(1,0,0);glTranslate(1,0,0);glPopMatrix();glPopMatrix();

FF11

FF hh

FF hh

FF hh

FF hh

FFhh

Page 27: Transformations III Week 3, Mon Jan 21

27

Transformation Hierarchy Example 4

1θ5θ 3θ

xx

yy

glTranslate3f(x,y,0);glTranslate3f(x,y,0);glRotatef( ,0,0,1);glRotatef( ,0,0,1);DrawBody();DrawBody();glPushMatrix();glPushMatrix(); glTranslate3f(0,7,0);glTranslate3f(0,7,0); DrawHead();DrawHead();glPopMatrix();glPopMatrix();glPushMatrix();glPushMatrix(); glTranslate(2.5,5.5,0);glTranslate(2.5,5.5,0); glRotatef( ,0,0,1);glRotatef( ,0,0,1); DrawUArm();DrawUArm(); glTranslate(0,-3.5,0);glTranslate(0,-3.5,0); glRotatef( ,0,0,1);glRotatef( ,0,0,1); DrawLArm();DrawLArm();glPopMatrix();glPopMatrix();... (draw other arm)... (draw other arm)

Page 28: Transformations III Week 3, Mon Jan 21

28

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