2016年3月21日 星期一

week 05



因為程式碼是從下往上看
所以這個是自己在旋轉
按右鍵選擇swap translate/rotate改變整個視角
變成下面這張是空間在旋轉



 

使茶壺可以左右轉
程式碼:
#include <GL/glut.h>
float rotX=0;
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glRotatef(rotX,0,1,0);
    glColor3f(1,0,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);
    glutMainLoop();
}

課堂問題
Q1; 什麼是glPushMatrix();
                glPopMatrix();
A:
     和rush pop相同意義,push是儲存資料 pop則是提出資料互為相反的涵式
Q2: 什麼是 Buffers
                 Double
A:
    buffer是電腦繪圖緩衝區,怕圖形呈現時不完整,所以在圖片顯示前會先在這繪製好圖形再一起呈現
    double-buffer即為兩次緩衝,較為保險


多加了y軸可以變成上下也能旋轉



沒有留言:

張貼留言