2017年5月8日 星期一

2017 Week12 ID張凱盛

下載老師的檔案


開啟Projection




開起老師的範例檔



float eyeX=0, eyeY=0.9, eyeZ=1;
float centerX=1, centerY=0, centerZ=0;
float upX=0, upY=1, upZ=0;

調整變數觀察茶壺

調整變數觀察


加入
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60,1,0.001,10000);
    glMatrixMode(GL_MODELVIEW);




static void display(void)
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60, 1, 0.001, 10000);
    glMatrixMode(GL_MODELVIEW);


    angle+=dir;
    if(angle>60) dir=-dir;
    if(angle<0) dir=-dir;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);
    glPushMatrix();
        gluLookAt(eyeX, eyeY, eyeZ,
                  centerX, centerY, centerZ,
                  upX, upY, upZ);


        glPushMatrix();
            glColor3f(1,0,0);
            glutSolidTeapot(0.3);///head
            glPushMatrix();
                glTranslatef(0, -0.3, 0);
                glColor3f(1,1,1);
                glutSolidTeapot(0.3);///body
                glPushMatrix();
                    ///glTranslatef(0.6,0,0);///old rotate
                    glTranslatef(0.3,0,0);/// T
                    glRotatef(angle, 0,0,1);///R
                    glTranslatef(0.3,0,0);/// T
                    glutSolidTeapot(0.3);///right upper arm
                    glPushMatrix();
                        glTranslatef(0.3, 0,0);///T
                        glRotatef(angle, 0,0,1);///R
                        glTranslatef(0.3, 0,0);///T
                        glutSolidTeapot(0.3);///right lower arm
                    glPopMatrix();
                glPopMatrix();
                glPushMatrix();
                    ///glTranslatef(0.6,0,0);///old rotate
                    glTranslatef(-0.3,0,0);/// T
                    glRotatef(-angle, 0,0,1);///R
                    glTranslatef(-0.3,0,0);/// T
                    glutSolidTeapot(0.3);///left upper arm
                    glPushMatrix();
                        glTranslatef(-0.3, 0,0);///T
                        glRotatef(-angle, 0,0,1);///R
                        glTranslatef(-0.3, 0,0);///T
                        glutSolidTeapot(0.3);///left lower arm
                    glPopMatrix();
                glPopMatrix();
            glPopMatrix();
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}







沒有留言:

張貼留言