2020年4月21日 星期二

-HEYU 金棒を回転させる 一起下去-

叫出方塊,讓方塊會旋轉
讓他轉得像手臂
叫出兩隻手



程式碼:

void arm()
{
    glPushMatrix();
        glScalef(1,0.3,0.3);
        glutSolidCube(0.5);
    glPopMatrix();

}
float a=0;

static void display(void)
{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
        glTranslatef(0.3,0,0);
        glRotatef(a,0,0,1);
        glTranslatef(0.25,0,0);
        glColor3f(1,0,0);
        arm();

        glPushMatrix();
            glTranslatef(0.3,0,0);
            glRotatef(a,0,0,1);
            glTranslatef(0.25,0,0);
            glColor3f(1,1,0);
            arm();
        glPopMatrix();

    glPopMatrix();
    glPushMatrix();
        glTranslatef(-0.3,0,0);
        glRotatef(-a,0,0,1);
        glTranslatef(-0.25,0,0);
        glColor3f(1,0,0);
        arm();

        glPushMatrix();
            glTranslatef(-0.3,0,0);
            glRotatef(-a,0,0,1);
            glTranslatef(-0.25,0,0);
            glColor3f(1,1,0);
            arm();
        glPopMatrix();

    glPopMatrix();
    a++;


    glutSwapBuffers();
}

沒有留言:

張貼留言