1

I have a programming assignment that one portion is swinging the legs back and forth in order to create a walking motion. To me this is what should logically work. It should be 20 steps, each loop through checks if it's odd or even. If it's even it changes the angles to be walking, if it's odd it's both feet on the ground. I'm not sure if I'm putting the code in the correct place, I currently have it in the drawicon method. Any thoughts on if it needs to be put somewhere else or if my logic is off or what's going on here? (There's 500 lines of code, but if you need to see the full thing just let me know)

for (i = 0; i <= 20; i++) {
            if (i % 2) {
                glBegin(GL_LINE_STRIP);
                //Draw polymans upper body
                glVertex2f(pxp[0], pyp[0]);// top line left
                glVertex2f(pxp[1], pyp[1]);//top line right
                glVertex2f(pxp[2], pyp[2]); //far right point
                glVertex2f(pxp[5], pyp[5]); // far left point
                glVertex2f(pxp[6], pyp[6]);//far top left diag line
                glEnd();

                glBegin(GL_LINE_STRIP);
                //Draw Polymans lower body
                glVertex2f(pxp[5], pyp[5]); //mouth part
                glVertex2f(pxp[2], pyp[2]);//far right point
                glVertex2f(pxp[3], pyp[3]);//bottom right line
                glVertex2f(pxp[4], pyp[4]);// bottom line left
                glVertex2f(pxp[5], pyp[5]);// mouth part
                glEnd();
                //now draw the feet and eyes

                //make the eyes
                glPointSize(5.0f);
                glBegin(GL_POINTS);
                glVertex2f(pxp[8], pyp[8]);
                glEnd();

                //foot one
                glBegin(GL_LINE_STRIP);

                glVertex2f(plxp[3], plyp[3]);
                glVertex2f(plxp[4], plyp[4]);
                glVertex2f(plxp[4], plyp[4]);
                glVertex2f(plxp[5], plyp[5]);

                glEnd();



                //foot two
                glBegin(GL_LINE_STRIP);

                glVertex2f(pxp[12], pyp[12]);
                glVertex2f(pxp[13], pyp[13]);
                glVertex2f(pxp[13], pyp[13]);
                glVertex2f(pxp[14], pyp[14]);

                glEnd();
            }
            else {
                glBegin(GL_LINE_STRIP);
                //Draw polymans upper body
                glVertex2f(pxp[0], pyp[0]);// top line left
                glVertex2f(pxp[1], pyp[1]);//top line right
                glVertex2f(pxp[2], pyp[2]); //far right point
                glVertex2f(pxp[5], pyp[5]); // far left point
                glVertex2f(pxp[6], pyp[6]);//far top left diag line
                glEnd();

                glBegin(GL_LINE_STRIP);
                //Draw Polymans lower body
                glVertex2f(pxp[5], pyp[5]); //mouth part
                glVertex2f(pxp[2], pyp[2]);//far right point
                glVertex2f(pxp[3], pyp[3]);//bottom right line
                glVertex2f(pxp[4], pyp[4]);// bottom line left
                glVertex2f(pxp[5], pyp[5]);// mouth part
                glEnd();
                //now draw the feet and eyes

                //make the eyes
                glPointSize(5.0f);
                glBegin(GL_POINTS);
                glVertex2f(pxp[8], pyp[8]);
                glEnd();


                //foot one
                glBegin(GL_LINE_STRIP);

                glVertex2f(plxp[0], plyp[0]);
                glVertex2f(plxp[1], plyp[1]);
                glVertex2f(plxp[2], plyp[2]);

                glEnd();



                //foot two

                glBegin(GL_LINE_STRIP);

                glVertex2f(pxp[9], pyp[9]);
                glVertex2f(pxp[10], pyp[10]);
                glVertex2f(pxp[11], pyp[11]);

                glEnd();

            }
        }
Cecilia T.
  • 11
  • 1

0 Answers0