University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don FussellHierarchical ModelingUniversity of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 2ReadingAngel, sections 9.1 - 9.6[reader pp. 169-185]OpenGL Programming Guide, chapter 3Focus especially on section titled“Modelling Transformations”.University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 3Hierarchical ModelingConsider a moving automobile, with 4wheels attached to the chassis, and lug nutsattached to each wheel:University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 4Symbols and instancesMost graphics APIs support a few geometricprimitives:spherescubestrianglesThese symbols are instanced using an instancetransformation.University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 5Use a series of transformationsUltimately, a particular geometric instance istransformed by one combined transformation matrix:But it’s convenient to build this single matrixfrom a series of simpler transformations:We have to be careful about how we thinkabout composing these transformations.(Mathematical reason: Transformation matrices don’t commute under matrix multiplication)University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 6Two ways to compose xformsMethod #1:Express every transformation with respectto global coordinate system:Method #2:Express every transformation with respectto a “parent” coordinate system created byearlier transformations:The goal of this second approachis to build a series of transforms.Once they exist, we can think ofpoints as being “processed” bythese xforms as in Method #1University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 7#1: Xform for global coordinatesFinalPosition = M1 * M2 * … * Mn * InitialPositionApply FirstApply LastNote: Positions are column vectors: 1xyz! "# $# $# $# $# $% &University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 8#2: Xform for coordinate systemFinalPosition = M1 * M2 * … * Mn * InitialPositionApply FirstApply LastUniversity of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 9Xform direction for coord. sysFinalPosition = M1 * M2 * … * Mn * InitialPositionTranslate/Rotate: FROM previous coord sys TO new one with transformation expressed in the ‘previous’ coordinate system.Global coord sysCoord sys resulting from M1.Local coord sys, resultingfrom M1 * M2 * … * Mn[[[[Coord sys resulting from M * M2University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 10Connecting primitivesUniversity of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 113D Example: A robot armConsider this robot arm with 3 degrees of freedom:Base rotates about its vertical axis by θUpper arm rotates in its xy-plane by φLower arm rotates in its xy-plane by ψQ: What matrix do we use to transform the base?Q: What matrix for the upper arm?Q: What matrix for the lower arm?h1h2h3BaseUpper armLower armUniversity of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 12Robot arm implementationThe robot arm can be displayed by keeping a global matrixand computing it at each step:Matrix M_model;main(){ . . . robot_arm(); . . .}robot_arm(){ M_model = R_y(theta); base(); M_model = R_y(theta)*T(0,h1,0)*R_z(phi); upper_arm(); M_model = R_y(theta)*T(0,h1,0)*R_z(phi) *T(0,h2,0)*R_z(psi); lower_arm();}Do the matrix computations seem wasteful?University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 13Instead of recalculating the global matrix each time, we can just updateit in place by concatenating matrices on the right:Matrix M_model;main(){ . . . M_model = Identity(); robot_arm(); . . .}robot_arm(){ M_model *= R_y(theta); base(); M_model *= T(0,h1,0)*R_z(phi); upper_arm(); M_model *= T(0,h2,0)*R_z(psi); lower_arm();}Robot arm implementation, betterUniversity of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 14OpenGL maintains a global state matrix called the model-viewmatrix, which is updated by concatenating matrices on the right.main(){ . . . glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); robot_arm(); . . .}robot_arm(){ glRotatef( theta, 0.0, 1.0, 0.0 ); base(); glTranslatef( 0.0, h1, 0.0 ); glRotatef( phi, 0.0, 0.0, 1.0 ); lower_arm(); glTranslatef( 0.0, h2, 0.0 ); glRotatef( psi, 0.0, 0.0, 1.0 ); upper_arm();}Robot arm implementation, OpenGLUniversity of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 15Hierarchical modelingHierarchical models can be composed of instancesusing trees or DAGs:edges contain geometric transformationsnodes contain geometry (and possibly drawingattributes)How might we draw thetree for the robot arm?University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 16A complex example: human figureQ: What’s the most sensible way to traverse this tree?University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 17Human figure implementation, OpenGLfigure(){ torso(); glPushMatrix(); glTranslate( ... ); glRotate( ... ); head(); glPopMatrix(); glPushMatrix(); glTranslate( ... ); glRotate( ... ); left_upper_arm(); glPushMatrix(); glTranslate( ... ); glRotate( ... ); left_lower_arm(); glPopMatrix(); glPopMatrix(); . . .}University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 18AnimationThe above examples are called articulatedmodels:rigid partsconnected by jointsThey can be animated by specifying thejoint angles (or other display parameters) asfunctions of time.University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 19Key-frame animationThe most common method for character animation inproduction is key-frame animation.Each joint specified at various key frames (not necessarily thesame as other joints)System does interpolation or
View Full Document