2019年3月21日 星期四

電腦圖學W5

(1)主題:旋轉 Rotation

(2)實作:glRotatef()

1.先到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/中,接著下載[data],[win32],[glut32.dll],解壓縮之後放到同一個資料夾中。



2.打開 Transformation.exe 

 

3.glRotatef()裡的第一個數值是旋轉角度,第二.三.四個數值分別是x , y ,z 軸,用來調整旋轉方向。

(3)滑鼠旋轉 , 自動旋轉

1.先到https://www.transmissionzero.co.uk/software/freeglut-devel/裡面,點擊 Download freeglut 3.0.0 for MinGW 。


2.解壓縮之後,打開 freeglut 資料夾裡的 lib 資料夾,將裡面的 libfreeglut.a 複製,直接貼上,重新命名為 : libglut32.a ,結果如下圖。


3.打開 CodeBlocks → File → New → Project...→ 選擇 GlutProject → 打檔名.設定路徑。


4. 按 Build and Run 出現這個畫面代表可以執行。


5.把所有程式碼刪除,開始打程式囉。

自動旋轉


1.跟之前一樣先做出一個普通的茶壺。



2.然後加上float angle=0; 設置一個角度,glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 用來消除殘影,
angle+=3; 讓它持續旋轉,就完成了。



滑鼠旋轉

1.承上,加上float angle=0; 設置一個角度,glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 用來消除殘影,
把 angle+=3 刪除掉 。
再加上一個涵式 motion :
void motion(int x , int y)
{
    angle=x;
    display();
}
main 涵式裡面加上兩行程式碼,分別是
    glutIdleFunc(display);
    glutMotionFunc(motion);
就完成了。


滑鼠事件

1.承上,加上mouse涵式
#include <stdio.h>
void mouse(int bottom ,int state,int x, int y)
{
    printf("%d %d %d %d\n",bottom,state,x,y);
}
在main涵式裡面加上一行 glutMouseFunc(mouse); 

沒有留言:

張貼留言