小考 TRT
複習TRT
乾坤大挪移
利用滑鼠去控制手臂
int jointID=1;
void motion(int x, int y)
{
if(jointID==1) angle1 = x;
if(jointID==2) angle2 = x;
if(jointID==3) angle3 = x;
if(jointID==4) angle4 = x;
display();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') jointID=1;
if(key=='2') jointID=2;
if(key=='3') jointID=3;
if(key=='4') jointID=4;
}
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
加關節可以選擇要動哪個關節
float angle[20];
可以用陣列去取代宣告的很多變數
int oldX, oldY;
void mouse(int button, int state, int x, int y)///Now5!!!!
{///當mouse按下去時,要記下!! 要記得要讓它有作用!!
oldX = x; oldY = y;///Now5!!!!
}
void motion(int x, int y)///Now2!!!
{
angle[jointID] += x -oldX;///Now4!!!!///Now5!!!!
oldX = x;///Now5!!!!
///if(jointID==1) angle1 = x;///Now2!!!///Now3!!!
///if(jointID==2) angle2 = x;///Now2!!!///Now3!!!
///if(jointID==3) angle3 = x;///Now2!!!///Now3!!!
///if(jointID==4) angle4 = x;///Now2!!!///Now3!!!
display();///Now2!!!
}
void keyboard(unsigned char key, int x, int y)
{///Now3!!!
/// jointID = key - '0';///雖然可以這樣簡化,但下面易看
if(key=='1') jointID=1;///Now3!!!
if(key=='2') jointID=2;///Now3!!!
if(key=='3') jointID=3;///Now3!!!
if(key=='4') jointID=4;///Now3!!!
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 TRT");
glutIdleFunc(display);///Now!!!!
glutDisplayFunc(display);
glutMotionFunc(motion);///Now2!!!
glutMouseFunc(mouse);///Now5!!!!
glutKeyboardFunc(keyboard);///Now3!!!
glutMainLoop();
}
這樣改之後滑鼠按壓就不會再順移了
沒有留言:
張貼留言