2016年3月22日 星期二

Week 05 林育廷

課堂作業一 - 比教(A)和(B)的差異

(A)移動 glTranslatef
     旋轉 glRotatef
     縮放 glScalef
     glBegin() iglEnd()

(原圖)

(先旋轉)
(再移動)

(B)旋轉 glRotatef
     移動 glTranslatef
     縮放 glScalef
     Begin End()

(原圖)
(先移動)
(再旋轉)

* 口訣:左耳靠左肩

兩者差別: (A)是左右邊在轉
                  (B)整輛車在繞

課堂作業二 - mouse轉動

程式碼:

#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("Hello3D");

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

       glutMainLoop();
}

(原圖)

(往左轉)


課堂作業三 - Buffer和Double Buffer是什麼

Q1.什麼是Buffer

Buffer又稱之為緩衝是記憶體的緩衝區

Q2什麼是Double Buffer



兩倍遮蔽,增加緩衝

當第一張圖呈現出來時,第二張圖正在繪製,當第二張圖匯出時,第三張正在繪製,以此類推。

ex.第一個小爆炸匯出時,第二個大爆炸正在繪製,當大爆炸匯出時,破碎正在繪製,以此類推。

課堂作業四 - 階層式旋轉

程式碼:

#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);
           glRotatef(rotX,0,1,0);
           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("hello3D");

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

       glutMainLoop();

}











沒有留言:

張貼留言