2017年3月13日 星期一

week 03 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З

1.
    複習上周的作業1,2
    做出茶壺,如下圖

 並加入-
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
 兩行
 這兩行是本周的重點_關於滑鼠的應用
 滑鼠拆解動作,分隔成按下與放開
 
   先加入兩行
 #include<math.h>
 #include <stdio.h>
 在進入本周的重頭戲 關於滑鼠的參數
 void mouse(int button, int state, int x, int y)
 {

     printf("%d %d %d %d\n",button, state, x, y);

 }
 這一組涵式便可以印出我們滑鼠所案的位置所含的座標數字並印出來 完成作業1



2.
 在上面的涵式中,增加兩行程式碼
 glColor3f( 1 , x/300.0 , y/300.0);
    glutPostRedisplay();
 以控制茶壺的顏色
 
可是控制RGB的3個參數並不能靠XY的兩個座標替代,所以先用1來代替

 加入一個motion涵式void motion(int x, int y)
 並把上面的
 glColor3f( 1 , x/500.0 , y/500.0);
    glutPostRedisplay();
 移下來
 最後再把下面那行剛剛還沒用到的
 glutMotionFunc(motion);打上來
 便可完成隨著滑鼠移動同時變色的程式了


3.
 刪除剛剛茶壺的程式碼
 glutSolidTeapot(0.3);

再加入glclear(GL_COLORBUFFER_BIT|GL_DEPTH_BUFFER_BIT);
            glBegin(GL_POLYGON);
            for(float angle=0;angle<3.1415926*2;angle+=0.001)
           {
           
                 glVertex2f(cos(angle),sin(angle));

           }
            glEnd();
            glutSwapBuffers();

即可畫出圓形




















沒有留言:

張貼留言