2021年3月29日 星期一

賣女孩的小火柴Week06

 💻電腦圖學💻  

電腦圖學 Week06 2021-03-29

1. 主題: 階層轉動

  glPushMatrix();

    glPushMatrix();

 

    glPopMatrix();

  glPopMatrix();

(用滑鼠移動來旋轉)

    void motion(移動滑鼠)(int x, int y){
         angle++;
         display();
    }

(按鍵盤按鍵來旋轉)


    void keyboard(鍵盤按鍵)(unsigned char key,int x, int y){
            angle++;
            display();
    }

 

        void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(旋轉)(angle++(角度++),0,0,1);每次display都會angle++
        glutSolidCube(1);///方塊
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week5 drawing");
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutMainLoop();

}

(更改旋轉的軸心軸)


 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle++,0,0,1);
        glTranslatef(移動)(-0.25,0,0);  
        glScalef(0.5,0.1,0.1);
         glutSolidCube(1);///方塊

    glPopMatrix();
    glutSwapBuffers();

    


 

void hand()手的函式
{
    glPushMatrix();
     glScalef(0.5,0.1,0.1);
     glutSolidCube(1);///方塊
    glPopMatrix();

}

glPushMatrix();
        glTranslatef(-0.25,0,0); 
glRotatef(旋轉)(-/+angle,0,0,1);
glTranslatef(移動)(-0.25,0,0);
        hand();
    glPopMatrix();
    hand();




 glPushMatrix();
        glTranslatef(-0.25,0,0);
glRotatef(旋轉)(-/+angle(angle的加減來改變旋轉方向),0,0,1);
                        glTranslatef(移動)(-0.25,0,0);  
        hand();手的函式
            glPushMatrix();
                glTranslatef(-0.25,0,0); 
glRotatef(旋轉)(-/+angle,0,0,1);
glTranslatef(移動)(-0.25,0,0);
                hand();
            glPopMatrix();
    glPopMatrix();
    angle++;

 




 glPushMatrix();
        glTranslatef(-0.25,0,0);
        glRotatef(旋轉)(-/+angle(angle的加減來改變旋轉方向),0,0,1);
        glTranslatef(移動)(-0.25,0,0);
        hand();手的函式
            glPushMatrix();
                glTranslatef(-0.25,0,0); 
glRotatef(旋轉)(-/+angle,0,0,1);
glTranslatef(移動)(-0.25,0,0);
                hand();
            glPopMatrix();
    glPopMatrix();


沒有留言:

張貼留言

Week18期末作業(橘貓的跳舞熊熊)

 期末作業(橘貓的跳舞熊熊) 影片: https://youtu.be/R89tptMaQZw 程式碼: #include <opencv/highgui.h> #include <opencv/cv.h> #include <GL/glut.h...