我有以下场景。
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(45, w/h,.1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(cameraX,cameraY,cameraZ,0.0,0.0,0.0,0.0,1.0,0.0);
drawtheBOT();
drawUserTrackedBall(); // This ball moves in 3d with user controlling it.
当我更改cameraX,cameraY,cameraZ的值时,球的移动也会根据glulookat值而改变。例如,如果我从正x方向看,我的原始左右运动现在将变为近和远的运动。
如何取消外观转换?
答案 0 :(得分:0)
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
drawUserTrackedBall();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
或
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
gluLookAt(cameraX,cameraY,cameraZ,0.0,0.0,0.0,0.0,1.0,0.0);
drawtheBOT();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
drawUserTrackedBall(); // This ball moves in 3d with user controlli
或
glMatrixMode(GL_MODELVIEW);
glLoadMatrix(bot_modelview);
drawtheBOT();
glMatrixMode(GL_MODELVIEW);
glLoadMatrix(ball_modelview);
drawUserTrackedBall();
glMatrixMode的调用并不多余,因为我不知道绘图函数内部会发生什么。