2015年3月27日 星期五

week05

我做的是一隻紫色的小魚兒
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();//備份Matrix
      glRotatef(angle,0,1,0.5);//轉動
      glBegin(GL_POLYGON);;//開始畫圖形 我的圖形是魚
        glColor3f(0.8,0.5,0.8);//我選擇了紫色好吃的顏色
        glVertex3f( -0.5, -0.5, 0.1);
        glVertex3f(   -1,    0, 0.1);
        glVertex3f( -0.5,  0.5, 0.1);
        glVertex3f(    0,    0, 0.1);
  glEnd();
 glBegin(GL_POLYGON);;
        glVertex3f(    0,    0, 0.1);
        glVertex3f(  0.3, -0.3, 0.1);
        glVertex3f(  0.3,  0.3, 0.1);

    glEnd();




      glBegin(GL_POLYGON);;//這是另一個面
        glColor3f(0.8,0.5,0.8);
        glVertex3f( -0.5, -0.5, -0.1);
        glVertex3f(   -1,    0, -0.1);
        glVertex3f( -0.5,  0.5, -0.1);
        glVertex3f(    0,    0, -0.1);
    glEnd();
 glBegin(GL_POLYGON);;
        glVertex3f(   0,    0, -0.1);
        glVertex3f( 0.3, -0.3, -0.1);
        glVertex3f( 0.3,  0.3, -0.1);

    glEnd();


    glBegin(GL_QUAD_STRIP);;

        glVertex3f( -0.5, -0.5, 0.1);glVertex3f( -0.5, -0.5, -0.1);
        glVertex3f(   -1,    0, 0.1);glVertex3f(   -1,    0, -0.1);
        glVertex3f( -0.5,  0.5, 0.1);glVertex3f( -0.5,  0.5, -0.1);
        glVertex3f(    0,    0, 0.1);glVertex3f(    0,    0, -0.1);


    glEnd();
    glBegin(GL_QUAD_STRIP);;
      glVertex3f(    0,    0, 0.1);glVertex3f(   0,    0, -0.1);
      glVertex3f(  0.3, -0.3, 0.1);glVertex3f( 0.3, -0.3, -0.1);
      glVertex3f(  0.3,  0.3, 0.1);glVertex3f( 0.3,  0.3, -0.1);


    glEnd();



    glPopMatrix();//還原Matrix
    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("02160252");
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutMotionFunc(motion);//mouse motion drag動作移動的函式
    glutMainLoop();
}


沒有留言:

張貼留言