2018年3月17日 星期六

Week03 邱顯傑

使用Shape看程式圖形

1.  先從 http://jsyeh.org/3dcg10 下載檔案
                data.zip, windows.zip, glut32.dll  且解壓縮


2.把glut32.dll 放入windows資料夾裡

3.啟用Shape.exe

4.在右邊框框內點選右鍵 可以換圖形模式(程式)
   右鍵可DRAG拖曳
5.觀察圖形變化

學習滑鼠(mouse)與鍵盤


1.先觀察鼠標

button 0:左鍵
           1:右鍵
           2:中鍵(滾輪)
           3:中鍵上滑
           4:中鍵下滑

void mouse(int button, int state, int x, int y)       ←函式  用來printf滑鼠鼠標資料
{
    printf("%d %d %d %d\n", button, state, x, y);
}
glutMouseFunc(mouse);                                     ←啟用滑鼠的東西



2.鼠標回傳座標

if(state == GLUT_DOWN) printf("    glVertex2f(%f, %f)\n",(x-150)/150.0, (150-y)/150.0);
↑換成這個的話,就是你的滑鼠按下去後,直接回傳一個座標值回來


3.讓物體拖曳移動(圖片已框起來)
float teapotX=0, teapotY=0;   ←要計算茶壺的座標

    glPushMatrix();    ←可以備份矩陣
        glTranslatef(teapotX,teapotY, 0);     ← 看茶壺怎麼動就給他在哪的座標
        glutSolidTeapot(0.3);
    glPopMatrix();       ←還原矩陣

void motion (int x, int y)
{
    teapotX=((x-150)/150.0); teapotY=((150-y)/150.0);      ←看motion的x y來改茶壺的座標
    glutPostRedisplay();    ← 當有空要redisplay()
}

    glutMotionFunc(motion); ←啟用有動作的東西


修改茶杯(讓他可以跟地圖一樣移動)
void  mouse ()裡面增加
 oldX=x; oldY=y;   ←要記得你按下的點在哪


void motion()裡面修改與增加
teapotX+=(x-oldX)/150.0; teapotY=(y-oldY)/150.0;     ←修改移動方式
oldX=x; oldY=y;   ←記下你移到哪去了

沒有留言:

張貼留言