INT32GP Graphics Programming: Tutorial #17
More Hierarchical Modelling

B2.11 Indy Lay 3:00pm Mon 23 Sep 02
B1.11 12midday Tues 24 Sep 02

Start with dancer1.c. This program has some, though not all, features from Tutorial #16. Add a second dancer next to the first. The head should still rotate in response to the h key, but this dancer should not move in and out in resposne to Page Up and Page Down.
  1. Change the code in renderView() so that there are two calls to renderDancer().
    void renderView(){
       glTranslated(t[dancer][x],t[dancer][y],t[dancer][z]);
       renderDancer();
       renderDancer();
    }
  2. Observe that this code does not result in two dancers next to each other.
  3. What happens when you rotate the head?
  4. Change the code in renderView() to push and pop the GL_MODELVIEW matrix.
       glTranslated(t[dancer][x],t[dancer][y],t[dancer][z]);
       glPushMatrix();
       renderDancer();
       glPopMatrix();
       renderDancer();
  5. Describe the change. What happens when you press the Page Up and Page Down keys?
  6. Move glPushMatrix() so that only the first dancer responds the the Page Up and Page Down keys.
  7. Use a translation to place the dancers next to each other.
  8. Use translation(s) to move only the second dancer along the x-axis in response to the x key. When dancer 2 reaches the xRight clipping plane reverse direction. Similarly, when dancer 2 reaches the xLeft clipping plane automatically reverse direction.
  9. Use orthographic projection to check that this is working.
  10. Use translation and scaling to place a third dancer, half the size of the other two, next to the first.
Light the scene with global ambient light, tracking material colours.
  1. Edit void initialiseGL(), adding the following.
       glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient);
       glEnable(GL_LIGHTING);
       glEnable(GL_COLOR_MATERIAL);
  2. Set up ambient light globally.
    /*
    ** manage lights
    */
    GLfloat ambient[]={0.5,0.5,0.5,1.0};
  3. Toggle between a filled and wire rendering tool - hints follow.
    GLUquadricObj * renderTool;
    int wire=TRUE;
    
    if(wire)
          gluQuadricDrawStyle(renderTool,GLU_LINE);
    else
          gluQuadricDrawStyle(renderTool,GLU_FILL);
Advanced

Animate the dancers using the glutIdleFunc() attached to the left mouse button (see Tutorial #14 for animation). Design your own hierarchical model and place it in the scene.

Fran Soddell email:F.Soddell@bendigo.latrobe.edu.au
last updated 23 September 2002