電腦圖學 2024-03-04 Week03
1. 主題: mouse滑鼠
2. HW2 講解
3. 主題: 移動 glTranslatef(x, y, z);
4. 主題: 旋轉 glRotatef(角度, x, y, z);
1. 桌面有「葉正聖老師上課軟體」把freeglut資料夾拉到桌面,並把Lib裡面的libfreeglut.a複製,把複製的那一個改名為libglut32.a
2. Codeblocks File-New-Project,選擇GLUT專案,命名為week03_mouse
3. 把Blog/github的10行程式貼近來
4. 再打三行
void mouse(int botton,int state,int x,int y){
}
glutCreateWindow()之後,在 glutMainLoop()之前,
glutMouseFunc(mouse); ///這一行,設定定義mouse函式
圖一:
輸出:按下、放開 各一次Hello World,所以滑鼠點一下 會印出2個Hello World
_______
圖2:
刪除printf("Hello World\n");
新增了 printf("%d %d %d %d\n",button,state,x,y) ;
輸出:左0中1右2鍵、按下0放開1、x座標、y座標
_______
圖3:
刪除了 printf("%d %d %d %d\n",button,state,x,y) ;
新增if(state==GLUT_DOWN){
printf("glVertex2f((%d-150)/150.0, (%d-150)/150.0;\n",x,y);
(可應用在第二週的作業
口訣:減一半、除一半; y要加負號
_______
/*
到http://jsyeh.org/sdcg10/
下載data和win32
windows解壓縮
data.zip點兩下解壓縮變成data 把data移到window資料夾裡
開啟transformation.exe
glTranslatef -->移動
glRotatef-->旋轉
*/
_______
week03_mouse_glTranslatef
移動
圖四:點哪茶壺到哪
_________
旋轉方向與找X軸、Y軸、Z軸:用安培右手定折
_________
week03_mouse_glRotatef
旋轉
圖五:
_________
鍵盤
week03_mouse_translate_rotate
圖六 :
新增了w跟e快捷鍵的功能
執行的時候按w可以拖曳茶壺移動
按e可以旋轉








沒有留言:
張貼留言