2016年3月22日 星期二

Week05柯竹盈

Week 05



(1)主題:旋轉&移動

上圖是以車子轉動



(2)教材做Swap交換
(3)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,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("Hello 3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

Q1:Buffer?   A:是一個緩衝區,讓電腦準備下一張圖形的地方

Q2:Double? A:2個場地A和B,以遮住螢幕A,把螢幕換到螢幕B,螢幕A馬上準備下張圖

Q3:Depth?圖形深度Z,讓重疊的圖有距離,呈現最前面的圖

Q4:float?浮點數如果不弄,可以增加電腦性能




旋轉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);///旋轉 角度,rotX, (0,1,0)y軸
        glColor3f(1,0,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);
    glutCreateWindow("Hello 3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}










沒有留言:

張貼留言