2018年3月16日 星期五

Week03_吳幸俞

動手玩Shape.exe
(1)進入FB社團開啟老師給的網址:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

(2)下載 data.zip, windows.zip, glut32.dll 這3個檔案

(3)解壓縮windows.zip

(4)將glut32.dll放進windows.zip資料夾

(5)開啟Shape.exe

(6)滑鼠右鍵開啟選單可以看各種類型的圖案

(7)對著參數按著滑鼠左鍵移動可以調整數值

(8)放開滑鼠左鍵就可以看到圖形的變化

滑鼠寫程式
(1)到Moodle下載freeglut-MinGW-3.0.0-1.mp.zip
(2)解壓縮後開啟,在lib資料夾底下複製libfreeglut.a檔案到原路徑
(3) 重新命名為libglut32.a
(4)開啟Code::Blocks新增GLUT專案
移動茶壺
(1)新增GLUT專案
(2)打上以下程式碼
#include <stdio.h>
     #include <GL/glut.h>
     float teapotX=0, teapotY=0;
     void display()
    {
    glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();//備份矩陣
    glTranslatef(teapotX, teapotY, 0); //依照茶壺的座標移動
    glutSolidTeapot(0.3);
    glPopMatrix();//還原矩陣
    glutSwapBuffers(); //搭配GLUT_DOUBLE兩倍顯示
    }
    void motion(int x, int y) //mouse motion 事件
   {
    teapotX = (x-150)/150.0; // 依照motion時的x來改teapot的座標
    teapotY = (150-y)/150.0;// 依照motion時的y來改teapot的座標
    glutPostRedisplay(); //重畫畫面
   }
   int main(int argc, char** argv)
  {
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
   glutCreateWindow("Yee");
   glutDisplayFunc(display);
   //glutMouseFunc(mouse);
   glutMotionFunc(motion);
   glutMainLoop();//主要GLUT迴圈

  }
(3)執行後,在畫面中滑鼠左鍵按著茶壺可以隨意移動

沒有留言:

張貼留言