computer graphics cs 543 computer graphics cs 543 lecture
play

Computer Graphics (CS 543) Computer Graphics (CS 543) Lecture 7 (Part - PowerPoint PPT Presentation

Computer Graphics (CS 543) Computer Graphics (CS 543) Lecture 7 (Part 3): Hierarchical 3D Models Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) I Instance Transformation t T f ti Start with unique object (a


  1. Computer Graphics (CS 543) Computer Graphics (CS 543) Lecture 7 (Part 3): Hierarchical 3D Models Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)

  2. I Instance Transformation t T f ti  Start with unique object (a symbol )  Start with unique object (a symbol )  Each appearance of object in model is an instance  Must scale, orient, position l  Defines instance transformation Instance Symbol

  3. S Symbol ‐ Instance Table b l I t T bl Can store a model by assigning number to each Can store a model by assigning number to each symbol and storing parameters for instance transformation

  4. R l ti Relationships in Car Model hi i C M d l  Symbol instance table does not show  Symbol ‐ instance table does not show relationships between parts of model  Consider model of car  Consider model of car  Chassis (body) + 4 identical wheels  Two symbols y  Relationship: Rate of forward motion determined by rotational speed of wheels

  5. Structure using Function Calls St t i F ti C ll car(speed) car(speed) { chassis() wheel(right_front); ( ) wheel(left_front); wheel(right rear); g _ wheel(left_rear); }  Fails to show relationships well  Look at problem using a graph p g g p 5

  6. G Graphs h  Set of nodes and edges (links)  Set of nodes and edges (links)  Edge connects a pair of nodes  Directed or undirected d d d  Cycle : directed path that is a loop loop loop 6

  7. Tree  Graph in which each node (except the root) has  Graph in which each node (except the root) has exactly one parent node  May have multiple children  May have multiple children  Leaf or terminal node: no children root node root node leaf node 7

  8. Tree Model of Car M d l f C 8 T

  9. Hi Hierarchical Transforms hi l T f  Robot arm: Many small parts  Robot arm: Many small parts  Attributes (position, orientation, etc) depend on each other each other hammer A Robot Hammer! lower arm base

  10. Hi Hierarchical Transforms hi l T f  Object dependency description using tree  Object dependency description using tree structure Root node Root node Base Base Object position and orientation can be affected by its parent, grand-parent, grand-grand-parent Lower arm … nodes d Upper arm Hierarchical representation is known as Scene Graph Leaf node Hammer

  11. T Transformations f ti  Two ways to specify transformations:  Two ways to specify transformations:  (1) Absolute transformation: each part of the object is transformed independently relative to the origin transformed independently relative to the origin Translate the base by (5,0,0); Translate the lower arm by (5,0,0); Translate the upper arm by (5,0,0); y … x z

  12. R l ti Relative Transformation T f ti A better (and easier) way: A better (and easier) way: (2) Relative transformation: Specify the transformation for each object relative to its parent for each object relative to its parent Step 1: Translate base and p its descendants by (5,0,0);

  13. R l ti Relative Transformation T f ti Step 2: Rotate the lower arm and all its descendants relative to the base’s local y axis by -90 degree y y g y y z x x z

  14. R l ti Relative Transformation T f ti  Represent relative transformation using scene  Represent relative transformation using scene graph Base Base T Translate (5,0,0) l t (5 0 0) Lower arm Rotate (-90) about its local y Upper arm Apply all the way pp y y down Apply all the way Hammer down

  15. Hi Hierarchical Transforms Using OpenGL hi l T f U i O GL  Translate base and all its descendants by (5 0 0)  Translate base and all its descendants by (5,0,0)  Rotate lower arm and its descendants by ‐ 90 degree about local y ctm = LoadIdentity(); y(); Base … // setup your camera ctm = ctm * Translatef(5 0 0); ctm = ctm * Translatef(5,0,0); Lower arm Draw_base(); U Upper arm ctm = ctm * Rotatef(-90, 0, 1, 0); Draw_lower _arm(); Hammer Hammer Draw upper arm(); Draw_upper_arm(); Draw_hammer();

  16. Hi Hierarchical Modeling hi l M d li  Previous CTM had 1 level P i CTM h d 1 l l  Hierarchical modeling: extend CTM to stack with multiple levels using linked list multiple levels using linked list     1 1 0 0 0 0 0 0     Current top 0 2 0 0   Of CTM stack 0 0 3 0           0 0 0 0 0 0 1 1

  17. P PushMatrix hM t i  PushMatrix( ): Save current modelview matrix in stack ( )  Positions 1 & 2 in linked list are same after PushMatrix  Further Rotate, Scale, Translate affect only top matrix , , y p Before PushMatrix After PushMatrix         1 0 0 0 1 0 0 0           Current top   Current top 0 2 0 0 0 2 0 0     Of CTM stack Of CTM stack 0 0 3 0 0 0 3 0                 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1   1 0 0 0       0 0 2 2 0 0 0 0   0 0 3 0       0 0 0 1

  18. P PopMatrix M t i  PopMatrix( ): Delete position 1 matrix, position 2 matrix p p p becomes top After PopMatrix Before PopMatrix     1 0 0 0 1 5 4 0           C Current top t t     0 0 2 2 0 0 0 0 0 2 2 0 Current top     Of CTM stack 0 0 3 0 Of CTM stack 0 6 3 0           0 0 0 1   0 0 0 1   1 0 0 0       0 2 0 0   0 0 3 0       0 0 0 1

  19. P PopMatrix and PushMatrix Illustration M i d P hM i Ill i • Note: Diagram uses old glTranslate, glScale etc commands glScale, etc commands • We want same behavior though Ref: Computer Graphics Ref: Computer Graphics Through OpenGL by Guha

  20. Humanoid Figure id Fi 20 H

  21. B ildi Building the Model th M d l  Can build model using simple shapes  Can build model using simple shapes  Access parts through functions  torso() ()  left_upper_arm()  Matrices describe position of node with respect d b f d h to its parent  M lla positions left lower leg with respect to left upper l f l l h l f arm 21

  22. Tree with Matrices ith M t i 22 T

  23. T Tree with Matrices ith M t i Set model-view matrix to Set model-view matrix to M and draw torso 23

  24. T Tree with Matrices ith M t i Set model-view matrix to Set model-view matrix to MM h and draw head 24

  25. T Tree with Matrices ith M t i Set model-view matrix to Set model-view matrix to MM lua and draw left-upper arm 25

  26. St Stack ‐ based Traversal k b d T l  We can use stack Push Pop for this  We can use stack, Push, Pop for this  Rather than recomputing MM lua from scratch or using an inverse matrix we can use the or using an inverse matrix, we can use the matrix stack to store M and other matrices as we traverse the tree we traverse the tree 26

  27. T Traversal Code l C d save present model view matrix save present model-view matrix figure() { figure() { PushMatrix() update model-view matrix for head torso(); Rotate (…); recover original model-view matrix head(); PopMatrix(); PopMatrix(); save it again sa e it again PushMatrix(); update model-view matrix Translate(…); for left upper arm for left upper arm Rotate(…); ( ) left_upper_arm(); recover and save original PopMatrix(); p (); model-view matrix again model-view matrix again PushMatrix(); rest of code 27

  28. VRML VRML  Scene graph introduced by SGI Open Inventor  Scene graph introduced by SGI Open Inventor  Want to have a scene graph that can be used over the World Wide Web th W ld Wid W b  Need links to other sites to support distributed d t b data bases  Virtual Reality Markup Language  Based on Inventor data base  Implemented with OpenGL 28

  29. VRML W VRML World Example ld E l

  30. References  Angel and Shreiner, Interactive Computer Graphics (6 th edition), Chapter 8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend