**Unformatted text preview:**

CSCE 441: Computer Graphics: Hierarchical ModelsSummary: 3D Geometry PipelineComplex ModelsOutlineSymbols and InstancesSlide 6Slide 7Sample Instance Trans.Slide 9Composite Transformation: Opengl ImplementationLampSlide 12Slide 13Slide 14Slide 15Lamp ImplementationSlide 17Better ImplementationOpengl ImplementationHierarchical ModelingSlide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28A More Complex Example: Human FigureSlide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Opengl Implementation: Human FigureSlide 43Slide 44Matrix StackPush and Pop the Current MatrixSlide 47Slide 48Slide 49CSCE 441: Computer Graphics:Hierarchical ModelsJinxiang ChaiImage space2Normalized project spaceView spaceWorld spaceObject spaceSummary: 3D Geometry PipelineComplex ModelsOutlineHierarchical ModelsReading: HB chapter 14, OpenGL Programming Guide, chapter 3, and course slides•Most graphics API supports a few primitives: - sphere - cube - cylinders•These symbols are instanced using instance transformation:Symbols and Instances•Most graphics API supports a few primitives: - sphere - cube - cylinders•These symbols are instanced using instance transformation:Symbols and InstancesWhat’s the matrix for the instance transformation above?•Most graphics API supports a few primitives: - sphere - cube - cylinders•These symbols are instanced using instance transformation:Symbols and Instances),(*)(*),(yxyxssSRttTM•In opengl, instance transformation is created by modifying the Model-view matrix:Sample Instance Trans.glMatrixMode(GL_MODELVIEW);glLoadIdentity(…);// set current matrix to the identityglTranslate(…); // translate glRotate(…); //rotateglScale(…);//scalehouse();),(*)(*),(*yxyxssSRttTI•In opengl, instance transformation is created by modifying the Model-view matrix:Sample Instance Trans.Does the transform seem to be backward? glMatrixMode(GL_MODELVIEW);glLoadIdentity(…);glTranslate(…);glRotate(…);glScale(…);house();•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. Composite Transformation: Opengl ImplementationglMatrixMode(GL_MODELVIEW);glLoadIdentity(…);M4;M3;M2;M1;…xMMMMIx *****'1234Lamp•What’s the current coordinate A ?1233c2c1cA03221100)()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp),,(0yx0c11Lamp•What’s the current coordinate A ?1233c2c1cA03221100)()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp),,(0yx0c12Lamp•What’s the current coordinate A ?1233c2c1cA03221100)()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp),,(0yx0c13Lamp•What’s the current coordinate A ?1233c2c1cA03221100)()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp),,(0yx0c14Lamp•What’s the current coordinate A ?1233c2c1cA03221100)()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp),,(0yx0c15Lamp Implementation•The lamp can be displayed by computing a global matrix and computing it at each step)(),(0RyxT)(),0()(),(100RlTRyxT)0,()()0,()(),0()(),(221100lTRlTRlTRyxTMatrix M_model;Main(){ … lamp();}lamp(){ M_model = base(); M_model = upper_arm(); M_model = middel_arm(); M_model = lower_arm();})()0,()()0,()(),0()(),(3221100RlTRlTRlTRyxTLamp Implementation•The lamp can be displayed by computing a global matrix and computing it at each step)(),(0RyxT)(),0()(),(100RlTRyxT)()0,()(),0()(),(21100RlTRlTRyxTMatrix M_model;Main(){ … lamp()}lamp(){ M_model = base(); M_model = upper_arm(); M_model = middel_arm(); M_model = lower_arm();})()0,()()0,()(),0()(),(3221100RlTRlTRlTRyxTCan we make it more efficiently?Better Implementation•Instead recalculating the global matrix each time, we can just update it in place)(),(0RyxT)(),0(10RlT)()0,(21RlTMatrix M_model;Main(){ … M_model=Identity() lamp();}lamp(){ M_model *= base(); M_model *= upper_arm(); M_model *= middel_arm(); M_model *= lower_arm();})()0,(32RlTOpengl Implementation•Opengl maintains a global state matrix called model-view matrix2D_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();}Main(){ … glMatrixMode(GL_MODELVIEW); glLoadIdentity(); 2D_lamp(a,b,c,d,e,f) …} //set current matrixto identityHierarchical Modeling•Consider a model of a car – how many symbols? – how many instances?Hierarchical Modeling•Consider a model of a car – 2 symbols : – 5 instances :Hierarchical Modeling•Consider a model of a car – 2 symbols : chassis + wheel – 5 instances : 1 chassis + 4 wheel World systemfront-left wheel systemChasis systemHierarchical 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 partsHierarchical 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 onceHierarchical Modeling•Hierarchical model can be composed of instances using trees or directed acyclic graphs (DAGs) - edges contains geometric transformations - nodes contains geometryHierarchical Modeling•Hierarchical model can be composed of instances using trees or directed acyclic graphs (DAGs) - edges contains geometric transformations - nodes contains geometryWhat 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 geometry123c2c1cAHierarchical Modeling•Hierarchical model can be composed of instances using trees or directed acyclic graphs (DAGs) - edges contains geometric transformations - nodes contains geometrylower armbaseUpper armworld)(),(0RyxT)(),0(10RlT)()0,(21RlT)()0,(32RlTmiddle

View Full Document