2018年3月12日 星期一

WEEK03 QAQ筆記

WEEK03:滑鼠、鍵盤、移動

任務一:複習上禮拜 (改變背景顏色及茶壺顏色)

1.改茶壺顏色












2.改背景顏色













3.加入滑鼠事件












void mouse(int button,int state,int x,int y)  ///滑鼠函式
{
    if(state==GLUT_DOWN) printf("glVertex2f(%f, %f);\n",(x-150)/150.0,-(y-150)/150.0);
}

在main裡加入
glutMouseFunc(mouse);


4.加入移動事件


void motion(int x,int y)
{
    teapotX= (x-150)/150.0; teapotY=-(y-150)/150.0;  ///把mouse位置,設成teapot的位置
    printf("%d %d \n",x,y);  ///印出位置
    glutPostRedisplay();
}

在main裡加入
glutMotionFunc(motion);

5.執行就可以移動滑鼠並印出位置啦~



沒有留言:

張貼留言