Transformations III Week 2, Fri Jan 19 - - PowerPoint PPT Presentation

transformations iii week 2 fri jan 19
SMART_READER_LITE
LIVE PREVIEW

Transformations III Week 2, Fri Jan 19 - - PowerPoint PPT Presentation

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Transformations III Week 2, Fri Jan 19 http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007 Readings for Jan 15-22 FCG Chap 6 Transformation Matrices except


slide-1
SLIDE 1

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

slide-2
SLIDE 2

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 Transformations

through Building an Articulated Robot Arm

  • RB Appendix Homogeneous Coordinates and

Transformation Matrices

  • until Perspective Projection
  • RB Chap Display Lists
slide-3
SLIDE 3

3

News

  • reminder: office hours today after class in

011 lab

  • reminder: course newsgroup is

ubc.courses.cpsc.414

slide-4
SLIDE 4

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       +             =       ′ ′ 1 1 y x sh y x

x

      +             − =       ′ ′ 1 1 y x y x x x

slide-5
SLIDE 5

5

Review: 2D Transformations

      =       + + =       +       ' ' y x b y a x b a y x

( ) ( ) ( ) ( )

            − =       y x y x θ θ θ θ cos sin sin cos ' '

            =       y x b a y x ' '

scaling matrix rotation matrix

      =             ' ' y x y x d c b a

translation multiplication matrix?? vector addition matrix multiplication matrix multiplication

) , ( b a

(x,y) (x_,y _)

slide-6
SLIDE 6

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 d c b a y x ' ' dy cx y by ax x + = + = ' '

slide-7
SLIDE 7

7

Correction: Composing Transformations

  • scaling
  • rotation

            =

1 1 1 2

2 1 2 1

sy sy sx sx S S

so scales multiply so scales multiply

            + + + − + =

  • 1

1 ) 2 1 cos( ) 2 1 sin( ) 2 1 sin( ) 2 1 cos( 1 2 θ θ θ θ θ θ θ θ R R

so rotations add so rotations add

slide-8
SLIDE 8

8

Review: 3D Homog Transformations

  • use 4x4 matrices for 3D transformations

                        =             1 1 1 1 1 1 ' ' ' z y x c b a z y x

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

                        − =             1 1 cos sin sin cos 1 1 ' ' ' z y x z y x θ θ θ θ

) , ( Rotate θ x

                        =             1 1 1 ' ' ' z y x c b a z y x

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

            − 1 cos sin 1 sin cos θ θ θ θ

) , ( Rotate θ y

            − 1 1 cos sin sin cos θ θ θ θ

) , ( Rotate θ z

slide-9
SLIDE 9

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 f e d c b a w y x 1 ' '

slide-10
SLIDE 10

10

More: Composing Transformations

Ta Tb = Tb Ta, but Ra Ta Tb = Tb Ta, but Ra Rb Rb != != Rb Rb Ra and Ta Ra and Ta Rb Rb != != Rb Rb Ta Ta

  • rotations around different axes do not commute
slide-11
SLIDE 11

11

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);
  • specify vector last, in final coordinate system
  • first matrix to affect it is specified second-to-last

OpenGL pipeline ordering!

slide-12
SLIDE 12

12 (2,1) (1,1) (1,1)

changing coordinate system moving object translate by (-1,0)

Interpreting Transformations

  • same relative position between object and

basis vectors

intuitive? OpenGL

slide-13
SLIDE 13

13

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
slide-14
SLIDE 14

14

Rotation About a Point: Moving Object

F FW

W

translate p translate p to origin to origin

θ p = (x,y)

rotate about rotate about p by : p by :

θ

rotate about rotate about

  • rigin
  • rigin

translate p translate p back back

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

slide-15
SLIDE 15

15

Rotation: Changing Coordinate Systems

  • same example: rotation around arbitrary

center

slide-16
SLIDE 16

16

Rotation: Changing Coordinate Systems

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

center

slide-17
SLIDE 17

17

Rotation: Changing Coordinate Systems

  • rotation around arbitrary center
  • step 2: perform rotation
slide-18
SLIDE 18

18

Rotation: Changing Coordinate Systems

  • rotation around arbitrary center
  • step 3: back to original coordinate system
slide-19
SLIDE 19

19

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

slide-20
SLIDE 20

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
slide-21
SLIDE 21

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

slide-22
SLIDE 22

22

Arbitrary Rotation

  • why?
  • similarly R(Y) = V & R(Z) = W

R(X) = ux vx wx uy vy wy uz vz wz           1           = (ux,uy,uz) = U

slide-23
SLIDE 23

23

Transformation Hierarchies

slide-24
SLIDE 24

24

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

road road stripe1 stripe1 stripe2 stripe2 ... ... car1 car1 car2 car2 ... ... w1 w1 w3 w3 w2 w2 w4 w4

slide-25
SLIDE 25

25

Transformation Hierarchy Example 1

torso torso head head RUarm RUarm RLarm RLarm Rhand Rhand RUleg RUleg RLleg RLleg Rfoot Rfoot LUarm LUarm LLarm LLarm Lhand Lhand LUleg LUleg LLleg LLleg Lfoot Lfoot world world trans(0.30,0,0) rot(z, ) trans(0.30,0,0) rot(z, )

θ

slide-26
SLIDE 26

26

Transformation Hierarchies

  • hierarchies don’t fall apart when changed
  • transforms apply to graph nodes beneath
slide-27
SLIDE 27

27

Demo: Brown Applets

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

slide-28
SLIDE 28

28

Transformation Hierarchy Example 2

  • draw same 3D data with different

transformations: instancing

slide-29
SLIDE 29

29

Matrix Stacks

  • challenge of avoiding unnecessary

computation

  • using inverse to return to origin
  • computing incremental T1 -> T2

Object coordinates Object coordinates World coordinates World coordinates

T T1

1(x)

(x) T T2

2(x)

(x) T T3

3(x)

(x)

slide-30
SLIDE 30

30

Matrix Stacks

glPushMatrix glPushMatrix() () glPopMatrix glPopMatrix() () A A B B C C A A B B C C A A B B C C C C 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) A A B B C C D D DrawSquare DrawSquare() () glTranslate3f(1,0,0) glTranslate3f(1,0,0) DrawSquare DrawSquare() () glPushMatrix glPushMatrix() () glPopMatrix glPopMatrix() ()

slide-31
SLIDE 31

31

Modularization

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

void void 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(); (); } }

slide-32
SLIDE 32

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)

slide-33
SLIDE 33

33

Transformation Hierarchy Example 3

F FW

W

F Fh

h

F Fh

h

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

1

F Fh

h

F Fh

h

F Fh

h

F Fh

h

F Fh

h

slide-34
SLIDE 34

34

Transformation Hierarchy Example 4

4

θ

1

θ

5

θ

3

θ

2

θ

x x y y glTranslate3f(x,y,0); glTranslate3f(x,y,0); glRotatef glRotatef( ,0,0,1); ( ,0,0,1); DrawBody DrawBody(); (); glPushMatrix glPushMatrix(); (); glTranslate3f(0,7,0); glTranslate3f(0,7,0); DrawHead DrawHead(); (); glPopMatrix glPopMatrix(); (); glPushMatrix glPushMatrix(); (); 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(); (); glPopMatrix glPopMatrix(); (); ... (draw other arm) ... (draw other arm)

1

θ

2

θ

3

θ

slide-35
SLIDE 35

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
slide-36
SLIDE 36

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

slide-37
SLIDE 37

37

Single Parameter: Complex

  • mechanisms not easily expressible with

affine transforms

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

slide-38
SLIDE 38

38

Single Parameter: Complex

  • mechanisms not easily expressible with

affine transforms

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