2022年3月22日 星期二

尖🦉-圖學筆記 Week05

電腦圖學之父:Ivan Sutherland --Sketchpad◇

老師範例程式Tranformation.exe:

    1.下面視窗(Command manipulation window)右鍵可以交換位置(translate)旋轉(rotate)的程式執行順序分別會顯示自轉公轉效果!



利用glutKeyboardFunc()函式使用鍵盤:

    1.先建立一個 glutKeyboardFunc(keyboard) 在Main裡。

   2.在建立函式 void keyboard( unsigned char key , int x , int y) ,

       key會去偵測你鍵盤的英文輸入和數字xy會去顯示你滑鼠指的位置。

☆char範圍是-128~127,加了unsigned(不要負號)範圍會變成0~255

glutDisplayFunc(display)/glutKeyboardFunc(keyboard)/

  glutMotionFunc(motion)/glutMouseFunc(mouse)這種函式是callback函式



◇結合之前mouse (滑鼠)、motion(轉動)函式:
   1.把glutMotionFunc(motion) 、 glutMouseFunc(mouse);加入main裡
    2.把設 x , y , z  , oldx , oldy 都設為0。
    3.在display裡 多加 glPushMatrix(); (備份矩陣)和 glPopMatrix();(還原矩陣)和 glTranslatef( (x-150)/150.0 ,-(y-150)/150.0 ,z); (移動)! 記得y座標要加負號!
   4.將motion裡的寫好。 mouse裡寫的是為了解決圖會瞬間移動的問題。
   更改背景顏色 glClearColor( 0 , 0 , 0 , 1)  R G B A (A為半透明功能,目前沒有開)

◇將scale(縮放)加入

   1.將先前的x,y設成150,讓他在畫面中間。
    2.增加scale=1.0。 並把glScalef(scale ,scale,scale);加入
    3.將上一個motion裡的函式,改成:
      if(mouseX-oldX>0) scale*=1.01;(如果滑鼠往右,則放大)
      if(mouseX-oldX<0) scale*=0.99;(如果滑鼠往左,則縮小)


沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...