2015年3月25日 星期三

02160704 王庭翊 week05



因為之前在忙啦啦的事,所以缺了一兩堂課
所以今天上課的時候就對上課內容有點不熟悉
但經過同學跟老師的幫忙也慢慢地跟上進度了~~~~






3D正方形


讓3D正方形移動


                                                                              利用(菱形密密縫)的方式做出長方體







插入glutMotionFunc(motion);函式讓我們可以利用滑鼠操控圖形




#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glRotatef( angle,  0, 1, 0.5);
    glBegin(GL_POLYGON);;
        glColor3f(1,0,0);
        glVertex3f(0.1, 0.1, 0.8);
        glVertex3f(-0.1, 0.1, 0.8);
        glVertex3f(-0.1, -0.1, 0.8);
        glVertex3f(0.1, -0.1, 0.8);
     glEnd();

     glBegin(GL_POLYGON);;
        glColor3f(1,0,0);
        glVertex3f(0.1, 0.1, -0.8);
        glVertex3f(-0.1, 0.1, -0.8);
        glVertex3f(-0.1, -0.1, -0.8);
        glVertex3f(0.1, -0.1, -0.8);
     glEnd();

     glBegin(GL_QUAD_STRIP);
        glColor3f(1,1,0);
        glVertex3f(0.1, 0.1, 0.8);
        glVertex3f(0.1, 0.1, -0.8);
        glVertex3f(-0.1, 0.1, 0.8);
        glVertex3f(-0.1, 0.1, -0.8);
        glVertex3f(-0.1, -0.1, 0.8);
        glVertex3f(-0.1, -0.1, -0.8);
        glVertex3f(0.1, -0.1, 0.8);
        glVertex3f(0.1, -0.1, -0.8);
     glEnd();
     glPopMatrix();
     angle +=0.01;
     glFlush();
}
   int oldX=0;
   void motion(int x, int y)
   {
       angle += (x-oldX);
       oldX=x;
   }

int main(int argc,char **argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("02160704flight");
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutMotionFunc(motion);///mouse motion drag動作移動的函式

    glutMainLoop();
}


沒有留言:

張貼留言