2016年3月22日 星期二

Week 05 蔡雯茜

【課堂作業 一】

jsyeh/3dcg10/ 到這個網頁,下載 data win32 glut32.dll ( 如Week02【課堂作業 一】 )

接下來開啟 Transformation (出現下圖)




先按右鍵→ [r] Reset parameters



嘗試更改以下變數:
         移動 glTranslatef(  );
         旋轉 glRotatef(  );
         縮放 glScalef(  );
            glBegin(  );
         由下而上,先看縮放再旋轉再移動鏡頭 → 左右邊轉



按右鍵→ [s] Swap translate/rotate

嘗試更改以下變數:
         旋轉 glRotatef(  );
         移動 glTranslatef(  );
         縮放 glScalef(  );
            glBegin(  );
         由下而上,先看縮放再移動在旋轉鏡頭 → 軸心轉動





【課堂作業 二】

輸入以下程式碼,可透過滑鼠旋轉水壺(y軸)。

#include <GL/glut.h>
float rotX=0;
void display()
{
    glClearColor(0,0,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotatef(rotX,0,1,0);
        glColor3f(1,1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x;
    display();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Hello 3D");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    ///glutMouseFunc(mouse);

    glutMainLoop();
}





【課堂作業 四】

輸入以下程式碼,可透過滑鼠讓水壺繞x.y軸旋轉。

#include <GL/glut.h>
float rotX=0, rotY=0;
void display()
{
    glClearColor(0,0,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotatef(rotY,1,0,0); ///旋轉 角度rotY, 軸(1,0,0) x軸
        glRotatef(rotX,0,1,0); ///旋轉 角度rotY, 軸(0,1,0) y軸
        glColor3f(1,1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x; rotY=y;
    display();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutInitWindowSize(600,600);
    glutInitWindowPosition(700,0);
    glutCreateWindow("Hello 3D");

    glutMotionFunc(motion);
    glutDisplayFunc(display);
    ///glutMouseFunc(mouse);

    glutMainLoop();
}


沒有留言:

張貼留言