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 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 2
News • reminder: office hours today after class in 011 lab • reminder: course newsgroup is ubc.courses.cpsc.414 3
Review: Shear, Reflection • shear along x axis • push points to right in proportion to height y y x 1 sh x 0 ′ x = + x x y 0 1 y 0 ′ • reflect across x axis • mirror x 1 0 x 0 ′ = + y 0 1 y 0 ′ − x x 4
Review: 2D Transformations matrix multiplication matrix multiplication ( ) ( ) x ' a 0 x x ' cos sin x θ − θ = = ( ) ( ) y ' sin cos y y ' 0 b y θ θ scaling matrix rotation matrix vector addition (x_,y x a x a x ' + _) + = = (x,y) ( a , b ) y b y b y ' + a b x x ' = c d y y ' translation multiplication matrix?? 5
Review: Linear Transformations • linear transformations are combinations of • shear x ' ax by x ' a b x = + • scale = y ' cx dy y ' c d y • rotate = + • reflect • properties of linear transformations • satisifes T( s x + t y ) = s T( x ) + t T( y ) • origin maps to origin • lines map to lines • parallel lines remain parallel • ratios are preserved • closed under composition 6
Correction: Composing Transformations • scaling sx sx 1 2 ∗ sy sy 1 2 ∗ S 2 S 1 • = 1 so scales multiply so scales multiply 1 • rotation cos( 1 2 ) sin( 1 2 ) θ + θ − θ + θ sin( 1 2 ) cos( 1 2 ) θ + θ θ + θ R 2 R 1 • = so rotations add so rotations add 1 1 7
Review: 3D Homog Transformations • use 4x4 matrices for 3D transformations translate(a,b,c) translate(a,b,c) scale(a,b,c) scale(a,b,c) x ' 1 a x x ' a x y ' 1 b y y ' b y = = z ' c z z ' 1 c z 1 1 1 1 1 1 Rotate ( x , ) Rotate ( z , ) Rotate ( y , ) θ θ θ cos sin x ' 1 x cos sin θ θ θ − θ y ' cos sin y 1 sin cos θ − θ θ θ = z ' sin cos z 1 sin cos θ θ − θ θ 1 1 1 1 1 8
Review: Affine Transformations • affine transforms are combinations of • linear transformations x ' a b c x • translations y ' d e f y = w 0 0 1 w • 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 9
More: Composing Transformations Ta Tb = Tb Ta, but Ra Rb Rb != != Rb Rb Ra and Ta Ra and Ta Rb Rb != != Rb Rb Ta Ta Ta Tb = Tb Ta, but Ra • rotations around different axes do not commute 10
Review: Composing Transformations p' = TRp • which direction to read? • right to left • interpret operations wrt fixed coordinates • moving object • left to right OpenGL pipeline ordering! • 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 11
Interpreting Transformations moving object translate by (-1,0) (1,1) (2,1) intuitive? changing coordinate system (1,1) OpenGL • same relative position between object and basis vectors 12
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 13
Rotation About a Point: Moving Object rotate about translate p translate p rotate about translate p translate p rotate about rotate about origin back to origin origin back to origin p by : p by : θ p = ( x , y ) θ F W F W T ( x , y , z ) R ( z , θ ) T ( − x , − y , − z ) 14
Rotation: Changing Coordinate Systems • same example: rotation around arbitrary center 15
Rotation: Changing Coordinate Systems • rotation around arbitrary center • step 1: translate coordinate system to rotation center 16
Rotation: Changing Coordinate Systems • rotation around arbitrary center • step 2: perform rotation 17
Rotation: Changing Coordinate Systems • rotation around arbitrary center • step 3: back to original coordinate system 18
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 19
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 20
Arbitrary Rotation W Y Z V X U • 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: u x v x w x R = u y v y w y u z v z w z
Arbitrary Rotation • why? u x v x w x 1 R ( X ) = u y v y w y 0 u z v z w z 0 = ( u x , u y , u z ) = U • similarly R(Y) = V & R(Z) = W 22
Transformation Hierarchies 23
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 ... ... car1 car1 car2 car2 ... stripe2 ... stripe2 stripe1 stripe1 w1 w2 w3 w4 w1 w2 w3 w4 24
Transformation Hierarchy Example 1 world world torso torso head LUleg RUleg LUarm RUarm head LUleg RUleg LUarm RUarm LLleg RLleg LLarm RLarm LLleg RLleg LLarm RLarm Lfoot Rfoot Lhand Rhand Lfoot Rfoot Lhand Rhand trans(0.30,0,0) rot(z, ) trans(0.30,0,0) rot(z, ) θ 25
Transformation Hierarchies • hierarchies don’t fall apart when changed • transforms apply to graph nodes beneath 26
Demo: Brown Applets http://www.cs cs.brown. .brown.edu edu/ /exploratories exploratories/ / http://www. freeSoftware/catalogs/ /catalogs/scenegraphs scenegraphs.html .html freeSoftware 27
Transformation Hierarchy Example 2 • draw same 3D data with different transformations: instancing 28
Matrix Stacks • challenge of avoiding unnecessary computation • using inverse to return to origin • computing incremental T 1 -> T 2 Object coordinates Object coordinates T 2 (x) T 2 (x) T 1 (x) T 1 (x) T 3 (x) T 3 (x) World coordinates World coordinates 29
Recommend
More recommend