如何在OpenGL中为2D腿设置动画来回摆动? C ++

时间:2018-09-26 03:32:00

标签: c++ animation opengl 2d

我有一个编程任务,其中一部分是来回摆动腿以产生步行动作。对我来说,这应该是合乎逻辑的工作。它应该是20个步骤,每个循环都要检查它是奇数还是偶数。如果是偶数,它会改变要行走的角度;如果很奇怪,它的双脚都在地面上。我不确定是否将代码放置在正确的位置,目前我在drawicon方法中拥有它。是否需要将其放置在其他位置,或者我的逻辑是否正确或这里发生了什么? (有500行代码,但是如果您需要查看全部内容,请告诉我)

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();

            }
        }

0 个答案:

没有答案