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 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
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
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
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
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
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
Tree Model of Car M d l f C 8 T
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
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
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
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);
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
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
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();
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
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
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
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
Humanoid Figure id Fi 20 H
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
Tree with Matrices ith M t i 22 T
T Tree with Matrices ith M t i Set model-view matrix to Set model-view matrix to M and draw torso 23
T Tree with Matrices ith M t i Set model-view matrix to Set model-view matrix to MM h and draw head 24
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
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
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
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
VRML W VRML World Example ld E l
References Angel and Shreiner, Interactive Computer Graphics (6 th edition), Chapter 8
Recommend
More recommend