Welcome, Unregistered.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Reply
Old 22-Oct-2005, 16:01   #1
K.I.L.E.R
Retarded moron
 
Join Date: Jun 2002
Location: Australia, Melbourne
Posts: 2,949
Send a message via ICQ to K.I.L.E.R Send a message via AIM to K.I.L.E.R Send a message via MSN to K.I.L.E.R
Default I have something stupid that needs fixing and it aint me

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...ent2/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();
}
__________________
I eat coffee.
K.I.L.E.R is offline   Reply With Quote
Old 23-Oct-2005, 04:40   #2
DemoCoder
Regular
 
Join Date: Feb 2002
Location: California
Posts: 4,732
Default

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.
DemoCoder is offline   Reply With Quote
Old 23-Oct-2005, 04:49   #3
K.I.L.E.R
Retarded moron
 
Join Date: Jun 2002
Location: Australia, Melbourne
Posts: 2,949
Send a message via ICQ to K.I.L.E.R Send a message via AIM to K.I.L.E.R Send a message via MSN to K.I.L.E.R
Default

Thanks.
The second mode looks a lot better.
__________________
I eat coffee.
K.I.L.E.R is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:39.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.