Universit of British Columbia CPSC 34 Computer Graphics Jan-Apr 2007 Tamara Munzner Transformations III Week 2, Fri Jan 9 http://www.ugrad.cs.ubc.ca/~cs34/vjan2007
Readings for Jan 5-22 FCG Chap 6 Transformation Matrices ecept 6..6, 6.3. FCG Sect 3.3 Scene Graphs RB Chap Viewing Viewing and Modeling Transforms until Viewing Transformations Eamples of Composing Several Transformations through Building an Articulated Robot Arm RB Appendi Homogeneous Coordinates and Transformation Matrices until Perspective Projection RB Chap Displa Lists 2
News reminder: office hours toda after class in 0 lab reminder: course newsgroup is ubc.courses.cpsc.44 3
4 Review: Shear, Reflection shear along ais push points to right in proportion to height reflect across ais mirror + = 0 0 0 sh + = 0 0 0 0
5 Review: 2D Transformations = + + = + ' ' b a b a ( ) ( ) ( ) ( ) = cos sin sin cos ' ' = b a 0 0 ' ' scaling matri rotation matri = ' ' d c b a translation multiplication matri?? vector addition matri multiplication matri multiplication ), ( b a (,) (_, _)
Review: Linear Transformations linear transformations are combinations of shear scale rotate reflect ' ' a c b d properties of linear transformations satisifes T(s+t) = s T() + t T() origin maps to origin lines map to lines parallel lines remain parallel ratios are preserved closed under composition = ' = ' = a c + + b d 6
Correction: Composing Transformations scaling S2 S = rotation s s 2 s s 2 so scales multipl R2 R = cos( + 2) sin( + 2) sin( + 2) cos( + 2) so rotations add 7
8 Review: 3D Homog Transformations use 44 matrices for 3D transformations = ' ' ' z c b a z translate(a,b,c) translate(a,b,c) = cos sin sin cos ' ' ' z z ), ( Rotate = ' ' ' z c b a z scale(a,b,c) scale(a,b,c) cos sin sin cos ), ( Rotate cos sin sin cos ), ( Rotate z
9 Review: Affine Transformations affine transforms are combinations of linear transformations translations properties of affine transformations origin does not necessaril map to origin lines map to lines parallel lines remain parallel ratios are preserved closed under composition = w f e d c b a w 0 0 ' '
More: Composing Transformations Ta Tb = Tb Ta, but Ra Rb!= Rb Ra and Ta Rb!= Rb Ta rotations around different aes do not commute 0
Review: Composing Transformations p'= TRp which direction to read? right to left interpret operations wrt fied coordinates moving object left to right OpenGL pipeline ordering! interpret operations wrt local coordinates changing coordinate sstem OpenGL updates current matri with postmultipl gltranslatef(2,3,0); glrotatef(-90,0,0,); glvertef(,,); specif vector last, in final coordinate sstem first matri to affect it is specified second-to-last
Interpreting Transformations translate b (-,0) moving object (2,) (,) intuitive? changing coordinate sstem (,) OpenGL same relative position between object and basis vectors 2
Matri Composition matrices are convenient, efficient wa to represent series of transformations general purpose representation hardware matri multipl matri multiplication is associative p_ = (T*(R*(S*p))) p_ = (T*R*S)*p procedure correctl order our matrices! multipl matrices together result is one matri, multipl vertices b this matri all vertices easil transformed with one matri multipl 3
Rotation About a Point: Moving Object rotate about p b : translate p to origin rotate about origin translate p back p = (, ) F W T(,,z)R(z,)T(,, z) 4
Rotation: Changing Coordinate Sstems same eample: rotation around arbitrar center 5
Rotation: Changing Coordinate Sstems rotation around arbitrar center step : translate coordinate sstem to rotation center 6
Rotation: Changing Coordinate Sstems rotation around arbitrar center step 2: perform rotation 7
Rotation: Changing Coordinate Sstems rotation around arbitrar center step 3: back to original coordinate sstem 8
General Transform Composition transformation of geometr into coordinate sstem where operation becomes simpler tpicall translate to origin perform operation transform geometr back to original coordinate sstem 9
Rotation About an Arbitrar Ais ais defined b two points translate point to the origin rotate to align ais with z-ais (or or ) perform rotation undo aligning rotations undo translation 20
Arbitrar Rotation Y Z W V problem: given two orthonormal coordinate sstems XYZ and UVW find transformation from one to the other answer: X transformation matri R whose columns are U,V,W: u v w R = u v w u z v z w z U
Arbitrar Rotation wh? u v w R(X) = u v w 0 u z v z w z 0 = (u,u,u z ) = U similarl R(Y) = V & R(Z) = W 22
Transformation Hierarchies 23
Transformation Hierarchies scene ma have a hierarch of coordinate sstems stores matri at each level with incremental transform from parent s coordinate sstem scene graph road stripe stripe2... car car2... w w2 w3 w4 24
Transformation Hierarch Eample world torso LUleg RUleg LUarm RUarm head LLleg RLleg LLarm RLarm Lfoot Rfoot Lhand Rhand trans(0.30,0,0) rot(z, ) 25
Transformation Hierarchies hierarchies don t fall apart when changed transforms appl to graph nodes beneath 26
Demo: Brown Applets http://www.cs cs.brown..brown.edu/eploratories/ freesoftware/catalogs/ /catalogs/scenegraphs.html 27
Transformation Hierarch Eample 2 draw same 3D data with different transformations: instancing 28
Matri Stacks challenge of avoiding unnecessar computation using inverse to return to origin computing incremental T -> T 2 Object coordinates T () T 2 () T 3 () World coordinates 29
Matri Stacks glpushmatri() D = C scale(2,2,2) trans(,0,0) glpopmatri() C D DrawSquare() C C C C glpushmatri() B A B A B A B A glscale3f(2,2,2) gltranslate3f(,0,0) DrawSquare() glpopmatri() 30
Modularization drawing a scaled square push/pop ensures no coord sstem change void drawblock(float k) { glpushmatri(); glscalef(k,k,k); glbegin(gl_line_loop); glverte3f(0,0,0); glverte3f(,0,0); glverte3f(,,0); glverte3f(0,,0); glend(); } glpopmatri(); 3
advantages Matri Stacks no need to compute inverse matrices all the time modularize changes to pipeline state avoids incremental changes to coordinate sstems accumulation of numerical errors practical issues in graphics hardware, depth of matri stacks is limited (tpicall 6 for model/view and about 4 for projective matri) 32
Transformation Hierarch Eample 3 F h F h F h F F h F h F h glloadidentit(); gltranslatef(4,,0); glpushmatri(); glrotatef(45,0,0,); gltranslatef(0,2,0); glscalef(2,,); gltranslate(,0,0); glpopmatri(); F W 33
Transformation Hierarch Eample 4 2 4 5 3 gltranslate3f(,,0); glrotatef( (,0,0,); DrawBod(); glpushmatri(); gltranslate3f(0,7,0); DrawHead(); glpopmatri(); glpushmatri(); gltranslate(2.5,5.5,0); glrotatef( ( 2,0,0,); DrawUArm(); gltranslate(0,-3.5,0); glrotatef( ( 3,0,0,); DrawLArm(); glpopmatri();... (draw other arm) 34
Hierarchical Modelling advantages define object once, instantiate multiple copies transformation parameters often good control knobs maintain structural constraints if well-designed limitations epressivit: not alwas 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 35
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 36
Single Parameter: Comple mechanisms not easil epressible with affine transforms http://www.fling-pig.co.uk 37
Single Parameter: Comple mechanisms not easil epressible with affine transforms http://www.fling-pig.co.uk uk/mechanisms/pages/irregular.html 38