2016年3月22日 星期二

Week 05 楊淳安

作業一:

移動 glTranslatef
旋轉 glRotatef
縮放 glScalef

以車子為中心旋轉


[s]Swap translate/rotate
像整個鍋子在旋轉
以畫面中心旋轉



作業二:

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("Hello 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
///glutMouseFunc(mouse);
glutMainLoop();
}


作業三:

Q1.什麼是Buffer  A: 緩衝記憶體

Q2.什麼是Double Buffer  A: 兩倍的緩衝記憶體「Double Buffer」的圖片搜尋結果

Q3.什麼是Depth  A: 圖形深度Z

Q4.float  A:不打float可以變得更有效能


作業四:

mouse 轉動
動手打程式
使茶壺能隨著滑鼠移動而上下左右旋轉

程式碼:
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
    glClearColor(0,0,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotatef(rotX,0,1,0);
        glRotatef(rotY,1,0,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);

    glutMainLoop();
}





沒有留言:

張貼留言