1_開啟上週作業
為了讓專案能夠順利執行,
先使用Notepad++開啟專案
將working_dir的路徑改為"."
將freeglut的路徑改為現在的路徑
2_Timer計時器
新增計時器
...
void timer(int t)
{
glutTimerFunc(100,timer,t+1);
angle++;
glutPostRedisplay();
}
void timer(int t)
{
glutTimerFunc(100,timer,t+1);
angle++;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
{
...
glutDisplayFunc(display);
//glutIdleFunc(display);
glutTimerFunc(2000,timer,0); //等待2000/1000秒之後,呼叫timer函式,參數
//glutIdleFunc(display);
glutTimerFunc(2000,timer,0); //等待2000/1000秒之後,呼叫timer函式,參數
...
}
按下F9執行,等待2秒後會開始轉動
3_簡化程式碼&T-R-T轉動
整理讀入模型的程式碼,並設定每個關節的T-R-T
按下F9執行,兩隻手的T-R-T
4_利用滑鼠控制角度
延續剛剛的程式碼,新增mouse函式及motion函式
...
int oldX=0,oldY=0;
void mouse(int button,int state,int x,int y)
{
oldX=x;
oldY=y;
glutPostRedisplay();
}
void motion(int x,int y)
{
angle+=(x-oldX);
oldX=x;
glutPostRedisplay();
}
int main()
{
....
glutMouseFunc(mouse);
glutMotionFunc(motion);
....
}
按下F9執行,便可透過滑鼠對兩隻手的旋轉角度進行調整
5_利用鍵盤&滑鼠控制角度
延續剛剛的程式碼,新增keyboard函式
把角度改為陣列,這樣才能分別控制不同的關節,並將各關節的T-R-T角度設定
...
void keyboard(unsigned char key,int x,int y)
{
if(key=='0') now=0;
if(key=='1') now=1;
if(key=='2') now=2;
if(key=='3') now=3;
if(key=='4') now=4;
}
void motion(int x,int y)
{
angle[now] += (x-oldX);
oldX=x;
glutPostRedisplay();
}
int main()
{
....
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
....
}
...
按下F9執行,便可利用數字鍵控制要旋轉哪一個部位

沒有留言:
張貼留言