CSCE 441: Computer Graphics: Hierarchical Models Jinxiang Chai
Summary: 3D Geometry Pipeline Object space World space View space Normalized project space Image space 2
Complex Models
Outline Hierarchical Models Reading: HB 9-8&9-9, HB chapter 11, OpenGL Programming Guide, chapter 3, and course slides
Symbols and Instances Most graphics API supports a few primitives: - sphere - cube - cylinders These symbols are instanced using instance/model transformation:
What’s the matrix for the instance transformation above? Symbols and Instances Most graphics API supports a few primitives: - sphere - cube - cylinders These symbols are instanced using instance transformation: What’s the matrix for the instance transformation above?
Symbols and Instances Most graphics API supports a few primitives: - sphere - cube - cylinders These symbols are instanced using instance transformation:
Sample Instance Trans. In opengl, instance/model transformation is created by modifying the Model-view matrix: glMatrixMode(GL_MODELVIEW); glLoadIdentity(…);// set current matrix to the identity glTranslate(…); // translate glRotate(…); //rotate glScale(…);//scale house();
Sample Instance Trans. In opengl, instance transformation is created by modifying the Model-view matrix: glMatrixMode(GL_MODELVIEW); glLoadIdentity(…); glTranslate(…); glRotate(…); glScale(…); house(); Does the transform seem to be backward?
Composite Transformation: Opengl Implementation Opengl postmultiplies transformation matrices as they are called Each subsequent transformation call concatenates the designated transformation matrix on the right of the composite matrix We must invoke the transformation in the opposite order from which they are applied. glMatrixMode(GL_MODELVIEW); glLoadIdentity(…); M4; M3; M2; M1; …
Lamp What’s the current coordinate A ? 11
Lamp Suppose we know how to draw each bone in local reference frames
Lamp How can we draw the character under a particular pose
Lamp How can we draw the character under a particular pose base(); upper_arm(); middel_arm(); lower_arm();
Lamp What’s the current coordinate A ? 15
Lamp What’s the current coordinate A ? 16
Lamp What’s the current coordinate A ? 17
Lamp What’s the current coordinate A ? 18
Lamp Implementation The lamp can be displayed by computing a global matrix and computing it at each step lamp() { M_model = base(); upper_arm(); middel_arm(); lower_arm(); } Matrix M_model; Main() { … M_model=Identity() lamp(); } 19
Lamp Implementation The lamp can be displayed by computing a global matrix and computing it at each step lamp() { M_model = base(); upper_arm(); middel_arm(); lower_arm(); } Matrix M_model; Main() { … M_model=Identity() lamp(); } Can we make it more efficiently? 20
Better Implementation Instead of recalculating the global matrix each time, we can just update it in place lamp() { M_model *= base(); upper_arm(); middel_arm(); lower_arm(); } Matrix M_model; Main() { … M_model=Identity() lamp(); } 21
Opengl Implementation Opengl maintains a global state matrix called model-view matrix Main() { … glMatrixMode(GL_MODELVIEW); glLoadIdentity(); 2D_lamp(a,b,c,d,e,f) } 2D_lamp(x, y, θ0, θ1, θ2, θ3) { glTranslatef(x,y,0) glRotatef(θ0,0,0,1,); base(); glTranslatef(0,l0,0) glRotatef(θ1,0,0,1,); upper_arm(); glTranslatef(0,l1,0) glRotatef(θ2,0,0,1,); middel_arm(); glTranslatef(0,l2,0) glRotatef(θ3,0,0,1,); lower_arm(); } //set current matrix to identity
More Complex Objects
Hierarchical Modeling Consider a model of a car – how many symbols/primitives? – how many instances?
Hierarchical Modeling Consider a model of a car – 2 primitives : – 5 instances : 25
Hierarchical Modeling Chasis system Consider a model of a car – 2 primitives : chassis + wheel – 5 instances : 1 chassis + 4 wheel World system front-left wheel system 26
Hierarchical Modeling Consider a model of a car – 2 primitives : chassis + wheel – 5 instances : 1 chassis + 4 wheel We can represent our car as a tree to show the relationship between the parts - tree nodes store subparts (i.e., instances) - transition edges represent relationship between the parts
Hierarchical Modeling Consider a model of a car – 2 symbols : chassis + wheel – 5 instances : 1 chassis + 4 wheel We can represent our car as a tree to show the relationship between the parts However, since all 4 wheels are instances of the same model, we’d like to only have that model appear once
Hierarchical Modeling Hierarchical model can be composed of instances using trees or directed acyclic graphs (DAGs) - edges contains geometric transformations - nodes contains geometry of subparts (i.e., primitives) This allows us to decompose geometry representation of a complex object into a set of geometric primitives and the geometric transformations between the primitives.
Hierarchical Modeling Hierarchical model can be composed of instances using trees or directed acyclic graphs (DAGs) - edges contains geometric transformations - nodes contains geometry of subparts (i.e., primitives) What might we draw the tree for the lamp?
Hierarchical Modeling Hierarchical model can be composed of instances using trees or directed acyclic graphs (DAGs) - edges contains geometric transformations - nodes contains geometry
Hierarchical Modeling Hierarchical model can be composed of instances using trees or directed acyclic graphs (DAGs) - edges contains geometric transformations - nodes contains geometry world base Upper arm middle arm lower arm 32
Different geometric models for Lamp
More Complex Objects
A More Complex Example: Human Figure torso
A More Complex Example: Human Figure torso 36
A More Complex Example: Human Figure torso 37
A More Complex Example: Human Figure torso What’s the most efficient way to draw this figure? Suppose we know how to draw each primitive in local reference frames
A More Complex Example: Human Figure torso What’s the most sensible way to traverse this tree? 39
A More Complex Example: Human Figure torso What’s the most sensible way to traverse this tree?
A More Complex Example: Human Figure torso What’s the most sensible way to traverse this tree?
A More Complex Example: Human Figure torso What’s the most sensible way to traverse this tree?
A More Complex Example: Human Figure torso What’s the most sensible way to traverse this tree?
A More Complex Example: Human Figure torso What’s the most sensible way to traverse this tree?
A More Complex Example: Human Figure torso What’s the most sensible way to traverse this tree?
A More Complex Example: Human Figure torso What’s the most sensible way to traverse this tree?
A More Complex Example: Human Figure torso What’s the most sensible way to traverse this tree?
A More Complex Example: Human Figure torso What’s the most sensible way to traverse this tree?
Opengl Implementation: Human Figure torso Mh Mlua Mlla 49
Opengl Implementation: Human Figure torso Mh Mlua Mlla Is this correct? 50
Opengl Implementation: Human Figure torso Mh Mh*Mlua should be Mlua Mh*Mlua*Mlla should be Mlua*Mlla Is this correct? No 51
Matrix Stack glMatrixMode(GL_MODELVIEW) - Initially, each of the stacks contains one matrix, an identity matrix. - The top matrix in the stack is “current matrix” - The depth is at least 32 Mc … I
Push and Pop the Current Matrix glPushMatrix() copy the current matrix at the top of the stack Mc Mc … Mc I … I
Push and Pop the Current Matrix glPopMatrix() destroys the matrix at the top of stack Mtop Mtop-1 Mtop-1 … … I I
Opengl Implementation: Human Figure
Opengl Implementation: Human Figure 56
Opengl Implementation: Human Figure 57
Opengl Implementation: Human Figure Mh I 58
Opengl Implementation: Human Figure 59
Opengl Implementation: Human Figure 60
Opengl Implementation: Human Figure Mlua I 61
Opengl Implementation: Human Figure Mlua Mlua I 62
Opengl Implementation: Human Figure Mlua*Mlla Mlua I 63
Opengl Implementation: Human Figure Mlua I 64
Opengl Implementation: Human Figure 65
Opengl Implementation: Human Figure Mh Mlua Mlua Mlla 66
Articulated Models You can draw these models as long as - you know how to draw each primitive in local reference frames - you know how to call transformation matrices to model the relationship between the primitives