2016年3月22日 星期二

Week 05 魏珩

作業一:
jsyeh.org/3dcg10 下載Window、data、glut32.dll
解壓縮,執行Transformation

1.改變Rotate
車子會原地旋轉
改變Translate一樣是原地旋轉(自轉)

<中心點為車子中心 >











2.按右鍵,點選swap 
先改變Translate
然後Rotate就會繞著中心點旋轉(公轉)

<中心點變成在攝影機的中心點>













作業二:

使茶壺旋轉(mouse)

程式碼:
#include <GL/glut.h>
float rotX=0;

void display()
{
    glClearColor(0.5,0.5,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();//備份Matrix
         glRotatef(rotX, 0,1,0);
         glColor3f(1,1,0.5);
    glutSolidTeapot(0.3);
    glPopMatrix();//還原Matrix
    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");

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

    glutMainLoop();


}


Q1.什麼是Buffers??
   A:Buffer是緩衝記憶體
Q2.什麼是Double?
   A:多做一次讓圖更完整

作業三:

同時對X、Y軸做旋轉

程式碼:
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
    glClearColor(0.5,0.5,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotated(rotX, 0,1,0);//X的移動量,對Y軸做旋轉
        glRotated(rotY, 1,0,0);//Y的移動量,對X軸 轉
        glColor3f(1,1,0.5);
        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(400,400);glutInitWindowPosition(600,0);//hello 3D的視窗設定
    glutCreateWindow("hello 3D");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();

}















Q1:什麼是Push And Pop?
  A:Push->將資料放入記憶體
      Pop->將資料從記憶體中拿出來








Q2:什麼是Matrix?

  A:Matrix是矩陣



沒有留言:

張貼留言