1110. Hierarchical Modeling22Reading Angel, sections 9.1 - 9.6[reader pp. 169-185] OpenGL Programming Guide, chapter 3• Focus especially on section titled“Modelling Transformations”.33Symbols and instancesMost graphics APIs support a few geometric primitives: spheres cubes trianglesThese symbols are instanced using an instance transformation.44Use 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 matricesdon’t commute under matrix multiplication)55Two 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:66#1: Xform for global coordinatesFinalPosition = M1* M2* … * Mn* InitialPositionApply FirstApply LastNote: Positions are column vectors: 1xyz⎡⎤⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦77#2: Xform for coordinate systemFinalPosition = M1* M2* … * Mn* InitialPositionApply FirstApply Last88Xform direction for coord. sysFinalPosition = M1* M2* … * Mn* InitialPositionTranslate/Rotate:FROM previous coord sysTO new onewith transformation expressed inthe ‘previous’ coordinate system.Global coord sysCoord sys resulting from M1.Local coord sys, resultingfrom M1 * M2 * … * Mn[[[Coord sys resulting from M * M299Connecting primitives10103D 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 arm1111Robot arm implementationThe robot arm can be displayed by keeping a global matrix and 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?1212Instead of recalculating the global matrix each time, we can just update it 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, better1313OpenGL maintains a global state matrix called the model-view matrix, 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, OpenGL1414Hierarchical modelingHierarchical models can be composed of instances using trees or DAGs: edges contain geometric transformations nodes contain geometry (and possibly drawing attributes)How might we draw the tree for the robot arm?1515A complex example: human figureQ: What’s the most sensible way to traverse this tree?1616Human figure implementation, OpenGLfigure(){torso();glPushMatrix();glTranslate( ... );glRotate( ... );head();glPopMatrix();glPushMatrix();glTranslate( ... );glRotate( ... );left_upper_arm();glPushMatrix();glTranslate( ... );glRotate( ... );left_lower_arm();glPopMatrix();glPopMatrix();. . .}1717AnimationThe above examples are called articulated models: rigid parts connected by jointsThey can be animated by specifying the joint angles (or other display parameters) as functions of time.1818Key-frame animationThe most common method for character animation in production is key-frame animation. Each joint specified at various key frames(not necessarily the same as other joints) System does interpolation or in-betweeningDoing this well requires: A way of smoothly interpolating key frames: splines A good interactive system A lot of skill on the part of the animator1919Scene graphsThe idea of hierarchical modeling can be extended to an entire scene, encompassing: many different objects lights camera positionThis is called a scene tree or scene graph.SceneCameraLight1Light2Object1Object2
View Full Document