Universit of British Columbia CPSC 34 Computer Graphics Jan-Apr 27 Tamara Munzner Transformations II Week 2, Wed Jan 7 http://www.ugrad.cs.ubc.ca/~cs34/vjan27
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
Review: Event-Driven Programming main loop not under our control vs. procedural control flow through event callbacks redraw the window now ke was pressed mouse moved callback functions called from main loop when events occur mouse/keboard state setting vs. redrawing 3
Review: 2D Rotation (_, _) (, ) _ cos() - sin() _ sin() + cos() cos sin ( ) sin( ) ( ) cos( ) ν counterclockwise, RHS 4
Review: 2D Rotation From Trig Identities φ (_, _) (, ) r cos (φ) r sin (φ) _ r cos (φ + ) _ r sin (φ + ) Trig Identit _ r cos(φ) cos() r sin(φ) sin() _ r sin(φ) cos() + r cos(φ) sin() Substitute _ cos() - sin() _ sin() + cos() 5
Review: 2D Rotation: Another Derivation (_, _) B cos sin + sin cos (,) A B A cos A 6
7 Shear shear along ais push points to right in proportion to height +??????
8 Shear shear along ais push points to right in proportion to height + sh
Reflection reflect across ais mirror???? +?? 9
Reflection reflect across ais mirror +
2D Translation + + + b a b a ), ( b a (,) (, )
2 2D Translation + + + b a b a ), ( b a (,) (, ) ( ) ( ) ( ) ( ) cos sin sin cos b a scaling matri rotation matri
3 2D Translation + + + b a b a ), ( b a (,) (, ) ( ) ( ) ( ) ( ) cos sin sin cos b a scaling matri rotation matri vector addition matri multiplication matri multiplication
4 2D Translation + + + b a b a ), ( b a (,) (, ) ( ) ( ) ( ) ( ) cos sin sin cos b a scaling matri rotation matri d c b a translation multiplication matri?? vector addition matri multiplication matri multiplication
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 5
matri multiplication Challenge for everthing ecept translation how to do everthing with multiplication? then just do composition, no special cases homogeneous coordinates trick represent 2D coordinates (,) with 3-vector (,,) 6
7 Homogeneous Coordinates our 2D transformation matrices are now 33: ) cos( ) sin( ) sin( ) cos( Rotation b a Scale T T Translation + + + + b a b a b a use rightmost column
Homogeneous Coordinates Geometricall point in 2D cartesian 8
Homogeneous Coordinates Geometricall w w w w homogeneous (,, w) w / w cartesian point in 2D cartesian + weight w point P in 3D homog. coords multiples of (,,w) ( w form a line L in 3D, w all homogeneous points on L represent same 2D cartesian point eample: (2,2,) (4,4,2) (,,.5) ) 9
Homogeneous Coordinates Geometricall w w w w homogeneous (,, w) w / w cartesian homogenize to convert homog. 3D point to cartesian 2D point: divide b w to get (/w, /w, ) projects line to point onto w plane like normalizing, one dimension up when w, consider it as direction points at infinit these points cannot be homogenized lies on - plane (,,) is undefined ( w, w ) 2
2 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
Homogeneous Coordinates Summar ma seem unintuitive, but the make graphics operations much easier allow all affine transformations to be epressed through matri multiplication we ll see even more later... use 33 matrices for 2D transformations use 44 matrices for 3D transformations 22
23 3D Rotation About Z Ais cos sin sin cos z z glrotatef(angle,,,z); glrotatef(angle,,,z); P z z + cos sin sin cos P glrotatef(angle,,,); glrotatef(angle,,,); ν general OpenGL command ν rotate in z
24 3D Rotation in X, Y cos sin sin cos z z glrotatef(angle,,,); glrotatef(angle,,,); around ais: cos sin sin cos z z glrotatef(angle,,,); glrotatef(angle,,,); around ais:
25 3D Scaling z c b a z glscalef(a,b,c); glscalef(a,b,c);
26 3D Translation z c b a z > < c b a,, gltranslatef(a,b,c); gltranslatef(a,b,c);
3D Shear shear in shear in shear in z s sz shear(s,sz) s sz shear(s,sz) zshear(s,s) s s 27
28 Summar: 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
Undoing Transformations: Inverses T(,,z) T(,, z) T(,,z) T(,, z) I R(z,) R(z, ) R T (z,) R(z,) R(z, ) I (R is orthogonal) S(s,s,sz) S( s, s, sz ) S(s,s,sz)S( s, s, sz ) I 29
Composing Transformations 3
translation Composing Transformations d d T T(d,d) d 2 d 2 T2 T(d 2,d 2) P T2 P T2 [T P] [T2 T] P,where d + d 2 d + d 2 T2 T so translations add 3
scaling Composing Transformations S2 S rotation s d 2 s s 2 so scales multipl R2 R cos( + 2) sin( + 2) sin( + 2) cos( + 2) so rotations add 32
Composing Transformations Ta Tb Tb Ta, but Ra Rb! Rb Ra and Ta Rb! Rb Ta 33
Composing Transformations suppose we want F h j i j F W i 34
Composing Transformations suppose we want Rotate(z,-9) F h j i j F W i F W F h p R(z, 9)p 35
Composing Transformations suppose we want Rotate(z,-9) Translate(2,3,) F h j i F h j F W i F W F h F W p R(z, 9)p p T(2,3,)p 36
Composing Transformations suppose we want Rotate(z,-9) Translate(2,3,) F h j i F h j F W i F W F h F W p R(z, 9)p p T(2,3,)p p T(2,3,)R(z, 9)p TRp 37
Composing Transformations p TRp which direction to read? right to left interpret operations wrt fied coordinates moving object left to right interpret operations wrt local coordinates changing coordinate sstem 38
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 39
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,); glrotatef(-9,,,); glvertef(,,); specif vector last, in final coordinate sstem first matri to affect it is specified second-to-last 4
Interpreting Transformations translate b (-,) moving object (2,) (,) intuitive? changing coordinate sstem (,) OpenGL same relative position between object and basis vectors 4
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 42
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) 43
Rotation: Changing Coordinate Sstems same eample: rotation around arbitrar center 44
Rotation: Changing Coordinate Sstems rotation around arbitrar center step : translate coordinate sstem to rotation center 45
Rotation: Changing Coordinate Sstems rotation around arbitrar center step 2: perform rotation 46
Rotation: Changing Coordinate Sstems rotation around arbitrar center step 3: back to original coordinate sstem 47
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 48
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 49
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 u z v z w z (u,u,u z ) U similarl R(Y) V & R(Z) W 5