transformations iv week 3 mon jan 22
play

Transformations IV Week 3, Mon Jan 22 - PowerPoint PPT Presentation

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


  1. University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Transformations IV Week 3, Mon Jan 22 http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007

  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 2

  3. Review: Interpreting Transformations right to left: moving object p' = TRp (1,1) intuitive? translate by (-1,0) (2,1) left to right: changing coordinate system (1,1) OpenGL • same relative position between object and basis vectors 3

  4. Correction/More: Arbitrary Rotation (b x , b y , b z , 1) Y (a x , a y , a z , 1) Y B B A A X C X Z C Z (c x , c y , c z , 1) • arbitrary rotation: change of basis • given two orthonormal coordinate systems XYZ and ABC • A ’ s location in the XYZ coordinate system is (a x , a y , a z , 1), ... • transformation from one to the other is matrix R whose columns are A,B,C: a b c 0 1     x x x     a b c 0 0 y y y     R ( X ) = ( a , a , a , 1 ) A = = a b c 0 0 x y z     z z z     0 0 0 1 1    

  5. Transformation Hierarchies 5

  6. 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 6

  7. 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, ) θ 7

  8. Transformation Hierarchies • hierarchies don’t fall apart when changed • transforms apply to graph nodes beneath 8

  9. Demo: Brown Applets http://www.cs cs.brown. .brown.edu edu/ /exploratories exploratories/ / http://www. freeSoftware/catalogs/ /catalogs/scenegraphs scenegraphs.html .html freeSoftware 9

  10. Transformation Hierarchy Example 2 • draw same 3D data with different transformations: instancing 10

  11. 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 11

  12. Matrix Stacks D = C scale(2,2,2) trans(1,0,0) D = C scale(2,2,2) trans(1,0,0) glPushMatrix() () glPushMatrix glPopMatrix() () glPopMatrix C D C D DrawSquare() DrawSquare () C C C C glPushMatrix() () C C C glPushMatrix C glScale3f(2,2,2) glScale3f(2,2,2) B B B B B B B B glTranslate3f(1,0,0) glTranslate3f(1,0,0) A A A A A A A A DrawSquare() () DrawSquare glPopMatrix() glPopMatrix () 12

  13. Modularization • drawing a scaled square • push/pop ensures no coord system change void drawBlock drawBlock(float k) { (float k) { void glPushMatrix glPushMatrix(); (); glScalef(k,k,k); (k,k,k); glScalef glBegin(GL_LINE_LOOP); (GL_LINE_LOOP); glBegin 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 } } 13

  14. 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) 14

  15. Transformation Hierarchy Example 3 glLoadIdentity(); (); glLoadIdentity F h F h glTranslatef(4,1,0); (4,1,0); glTranslatef glPushMatrix(); (); glPushMatrix F h F h glRotatef(45,0,0,1); (45,0,0,1); glRotatef F h F h glTranslatef(0,2,0); (0,2,0); glTranslatef glScalef(2,1,1); (2,1,1); glScalef F h F h F h F F h F h h glTranslate(1,0,0); (1,0,0); glTranslate F 1 F F h 1 F glPopMatrix(); (); glPopMatrix h F W F W 15

  16. Transformation Hierarchy Example 4 glTranslate3f(x,y,0); glTranslate3f(x,y,0); glRotatef( ,0,0,1); ( ,0,0,1); glRotatef θ 1 DrawBody(); (); DrawBody glPushMatrix(); (); glPushMatrix θ glTranslate3f(0,7,0); glTranslate3f(0,7,0); 2 DrawHead(); (); θ DrawHead 4 glPopMatrix(); (); glPopMatrix glPushMatrix(); (); glPushMatrix glTranslate(2.5,5.5,0); (2.5,5.5,0); glTranslate θ θ glRotatef( ,0,0,1); ( ,0,0,1); glRotatef θ θ 3 5 2 1 DrawUArm(); (); DrawUArm glTranslate(0,-3.5,0); (0,-3.5,0); glTranslate y y glRotatef( ,0,0,1); ( ,0,0,1); glRotatef θ 3 DrawLArm(); (); DrawLArm x x glPopMatrix(); (); glPopMatrix ... (draw other arm) ... (draw other arm) 16

  17. 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 17

  18. 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 18

  19. Single Parameter: Complex • mechanisms not easily expressible with affine transforms http://www.flying-pig.co.uk uk http://www.flying-pig.co. 19

  20. Single Parameter: Complex • mechanisms not easily expressible with affine transforms http://www.flying-pig.co.uk uk/mechanisms/pages/irregular.html /mechanisms/pages/irregular.html http://www.flying-pig.co. 20

  21. Display Lists 21

  22. Display Lists • precompile/cache block of OpenGL code for reuse • usually more efficient than immediate mode • exact optimizations depend on driver • good for multiple instances of same object • but cannot change contents, not parametrizable • good for static objects redrawn often • display lists persist across multiple frames • interactive graphics: objects redrawn every frame from new viewpoint from moving camera • can be nested hierarchically • snowman example http://www.lighthouse3d.com/opengl/displaylists 22

  23. One Snowman void drawSnowMan drawSnowMan() () { { void // Draw Eyes // Draw Eyes glPushMatrix(); (); glPushMatrix glColor3f(1.0f, 1.0f, 1.0f); glColor3f(0.0f,0.0f,0.0f); glColor3f(1.0f, 1.0f, 1.0f); glColor3f(0.0f,0.0f,0.0f); glTranslatef(0.05f, 0.10f, 0.18f); (0.05f, 0.10f, 0.18f); glTranslatef // Draw Body glutSolidSphere(0.05f,10,10); (0.05f,10,10); // Draw Body glutSolidSphere glTranslatef(0.0f ,0.75f, 0.0f); (0.0f ,0.75f, 0.0f); glTranslatef(-0.1f, 0.0f, 0.0f); (-0.1f, 0.0f, 0.0f); glTranslatef glTranslatef glutSolidSphere(0.75f,20,20); (0.75f,20,20); glutSolidSphere(0.05f,10,10); (0.05f,10,10); glutSolidSphere glutSolidSphere glPopMatrix(); (); glPopMatrix // Draw Head // Draw Head // Draw Nose // Draw Nose glTranslatef(0.0f, 1.0f, 0.0f); (0.0f, 1.0f, 0.0f); glTranslatef glColor3f(1.0f, 0.5f , 0.5f); glColor3f(1.0f, 0.5f , 0.5f); glutSolidSphere(0.25f,20,20); (0.25f,20,20); glutSolidSphere glRotatef(0.0f,1.0f, 0.0f, 0.0f); glRotatef (0.0f,1.0f, 0.0f, 0.0f); glutSolidCone(0.08f,0.5f,10,2); glutSolidCone (0.08f,0.5f,10,2); } } 23

  24. Instantiate Many Snowmen // Draw 36 Snowmen // Draw 36 Snowmen for(int int i = -3; i < 3; i++) i = -3; i < 3; i++) for( for(int int j=-3; j < 3; j++) { j=-3; j < 3; j++) { for( glPushMatrix(); (); glPushMatrix glTranslatef(i*10.0, 0, j glTranslatef(i*10.0, 0, j * 10.0); * 10.0); // Call the function to draw a snowman // Call the function to draw a snowman drawSnowMan drawSnowMan(); (); glPopMatrix(); (); glPopMatrix } } 36K polygons, 55 FPS 24

  25. Making Display Lists GLuint createDL() { () { GLuint createDL GLuint snowManDL; ; GLuint snowManDL // Create the id for the list // Create the id for the list snowManDL = = glGenLists glGenLists(1); (1); snowManDL glNewList(snowManDL,GL_COMPILE); ); glNewList(snowManDL,GL_COMPILE drawSnowMan(); drawSnowMan (); glEndList(); (); glEndList return(snowManDL snowManDL); } ); } return( snowmanDL = createDL(); snowmanDL = createDL(); for(int i = -3; i < 3; i++) for(int i = -3; i < 3; i++) for(int j=-3; j < 3; j++) { for(int j=-3; j < 3; j++) { glPushMatrix(); glPushMatrix(); glTranslatef(i*10.0, 0, j * 10.0); glTranslatef(i*10.0, 0, j * 10.0); glCallList(Dlid); glCallList(Dlid); 36K polygons, 153 FPS glPopMatrix(); } glPopMatrix(); } 25

  26. Transforming Normals 26

  27. Transforming Geometric Objects • lines, polygons made up of vertices • just transform the vertices, interpolate between • does this work for everything? no! 27

Recommend


More recommend