我正在编写一个基本的 OpenGL 游戏,并且我有一些代码可以在移动相机方面处理鼠标。
我正在使用以下方法:
int windowWidth = 640;
int windowHeight = 480;
int oldMouseX = -1;
int oldMouseY = -1;
void mousePassiveHandler(int x, int y)
{
int snapThreshold = 50;
if (oldMouseX != -1 && oldMouseY != -1)
{
cam.yaw((x - oldMouseX)/10.0);
cam.pitch((y - oldMouseY)/10.0);
oldMouseX = x;
oldMouseY = y;
if ((fabs(x - (windowWidth / 2)) > snapThreshold) || (fabs(y - (windowHeight / 2)) > snapThreshold))
{
oldMouseX = windowWidth / 2;
oldMouseY = windowHeight / 2;
glutWarpPointer(windowWidth / 2, windowHeight / 2);
}
}
else
{
oldMouseX = windowWidth / 2;
oldMouseY = windowHeight / 2;
glutWarpPointer(windowWidth / 2, windowHeight / 2);
}
glutPostRedisplay();
}
但是,环顾四周后,您会发现相机开始“滚动”(旋转)。因为我只打电话给 Pitch 和 Yaw,我不明白这是怎么可能的。
这是我用于我的相机类的代码:http: //pastebin.com/m20d2b01e
据我所知,我的相机“滚动”不应该发生。它应该简单地上下俯仰或左右偏航。不滚动。
这可能是什么原因造成的?