I have something stupid that needs fixing and it aint me

K.I.L.E.R

Retarded moron
Veteran
Can someone please tell me how to simplifying this without reverting to me creating a scenegraph?

What do you guys think?
http://members.optusnet.com.au/ksaho/work/ComputerGraphics/assignment2/Robot.exe

keys 0-9 to move joints

Code:
void Render::drawObjs()
{
    glEnable(GL_LIGHT0);
    glLightf(GL_LIGHT0, GL_AMBIENT, 0.6f);

    glPushMatrix();
    {
        drawHead();
        glTranslated(0, -1.5, 0);

        glPushMatrix();
        {
            drawNeck();
            glTranslated(0, -1.5, 0);

            glPushMatrix();
            {
                drawTorso();

                glPushMatrix();
                {
                    glTranslated(.6, .4, 0);
                    drawJoint();

                    glPushMatrix();
                    {
                        glTranslated(1, -2, 0);
                        drawArm();

                        glPushMatrix();
                        {
                            glTranslated(.2, -.6, 0);
                            glScaled(7, 1, 1);
                            drawJoint();
                        }
                        glPopMatrix();
                    }
                    glPopMatrix();
                }
                glPopMatrix();

                glPushMatrix();
                {
                    glTranslated(-0.6, .4, 0);
                    drawJoint();

                    glPushMatrix();
                    {
                        glTranslated(-1, -2, 0);
                        drawArm();

                        glPushMatrix();
                        {
                            glTranslated(-.2, -.6, 0);
                            glScaled(7, 1, 1);
                            drawJoint();
                        }
                        glPopMatrix();
                    }
                    glPopMatrix();
                }
                glPopMatrix();
            }
            glPopMatrix();
        }
        glPopMatrix();
    }
    glPopMatrix();
}
 
No matter what, you've got a scene graph. It's either implicit, or explicit. Yours in the above code is implicit.

You could do it in two other ways that look cleaner than one mega-method.

#1 make the individual methods themselves responsible for drawing children. This is sort of an implicit scene graph represented on the call stack

Code:
drawHead()
  push/translate
    drawNeck()
  pop

drawNeck()
   push/translate
     drawTorso()
   pop

drawTorso
   push/translate
   drawJoint()
etc

#2 Use a mini scene graph. Just make a small tree object which encodes the translation, and callback function. Trivial amount of code to traverse the tree, calling push/translate/draw/pop/etc.
 
Back
Top