3D Hierarchical Modelling
1
Intended Learning Outcomes
Understand the need of hierarchical structuring for building articulated 3D objects
Able to compute the relative coordinate transform between component parts
Able to represent an articulated 3D object as a hierarchical structure using OpenGL
2
Problem:
Given a large number of graphics models which form parts of a whole object, it is cumbersome to animate each part by individual commands
3
Example : Animate a car moving at a speed of 20 miles and in direction (2, 3, 4)
main () {
float s = 20.0; /* speed */
float d[3] = {2.0, 3.0, 4.0}; /* direction */
draw_chassis (s, d);
draw_right_front_wheel (s, d); draw_left_front_wheel (s, d); draw_right_rear_wheel (s, d); draw_left_rear_wheel (s, d);
}
Bad Programming – Redundancy: the 4 draw wheel functions can be replaced by one function
Tree with directed edge
4
Introduction of hierarchical structures
Use relative transformation to link the movements of different parts
Use a single function for a unique (single) part
5
Directed Acyclic Graph (DAG)
DAG is a graph with directed arc but no cycle
It is a tree but additional allows more than one arc from one node to another node
6
Revised program
main ()
{
float s = 20.0;
float d[3] ={2.0, 3.0, 4.0}; float w = 2.0, l = 4.0;
draw_chass (s, d);
glTranslatef ( w/2 , l/2, 0 );
Let the initial coordinate system be the centroid of the car
draw_wheel (s, d); glTranslatef ( -w, draw_wheel (s, d); glTranslatef ( 0, draw_wheel (s, d); glTranslatef ( w, draw_wheel (s, d);
}
0, 0 ); -l , 0 ); 0, 0 );
// position the right front wheel // position the left front wheel // position the left rear wheel
// position the right rear wheel
l
// width and length of the car
We can make it more systematic by formally introducing coordinate system change, which we do below
7
W
Moving a Robot Arm – a 3 level hierarchy
Parts : base B (cylinder),
lower arm La (rectangular box)
upper arm Ua (rectangular box) Arm has 3 degree of freedom:
B La Ua
rotate about Y by θ rotate about Z by φ
rotate about Z by ψ
8
Relative Coordinate Transformations
Use Change of coordinate system:
Ua
MLa←Ua = T(0, h2, 0) MB←La = T(0, h1, 0)
h2
h1
La
B
Z pointing out of paper
Y
X
9
DAG
Base
Lower Arm
Upper Arm
10
Write a program to …
Rotate the robot arm about its base by θ, then about its
lower arm by φ, then about its upper arm by ψ
when rotating the whole arm, everything should move; but when rotating the lower arm, only it and the upper arm should move; when rotating the upper arm, only the upper arm should move.
Solve this using a hierarchy concept
11
Program
robot_arm ()
{
glRotatef (theta, 0.0, 1.0, 0.0); // R y (θ ) rotate the whole robot arm
// each point of whole robot arm will be pre-multiplied by R y (θ ) base ();
glTranslatef (0.0, h1 , 0.0); // MB←La changes lower arm coord. sy. to base coord. sy. glRotatef (phi, 0.0, 0.0, 1.0); // Rz (φ) rotate the lower arm
// eachpointoflowerarmwillbepre-multipliedbyR (θ)T(0,h,0)R (φ) y1z
lower_arm ();
glTranslatef (0.0, h2 , 0.0); // MLa←Ua changes upper arm coord. sy. to lower arm coord. sy. glRotatef (psi, 0.0, 0.0, 1.0);
// each point of upper arm will be pre-multiplied by R (θ )T(0, h ,0)R (φ )T(0, h ,0)R (ψ ) y1z2Z
upper_arm (); }
12
Moving a Robot
Need to organize the hierarchy better
Solution: use glPushMatrix and glPopMatrix to store and
retrieve intermediate composite relative transformations
13
Program
Robot ()
{
glPushMatrix ();
torso;
glTranslate … glRotate … head ();
glPopMatrix (); glPushMatrix ();
glTranslate … glRotate … left_upper_arm (); glTranslate … glRotate … left_lower_arm ();
glPopMatrix (); glPushMatrix ();
glTranslate … glRotate … right_upper_arm ();
// go back to the node of the torso
// similar technique used here as that // used in example 2
// go back to the node of the torso
}
14
References
Our exposition follows:
E. Angel, Interactive Computer Graphics: A Top-down
Approach Using OpenGL, 5th Ed. (2009), Ch. 10.1-10.4 Ch. 11 of text provides an alterative reference.
15