【发布时间】:2015-12-20 05:15:34
【问题描述】:
我意识到这个问题之前在 stackoverflow 上被问过,但我还没有找到一个我完全理解的答案,所以我想我会得到一些针对我的具体情况的帮助。
我基本上希望能够使用鼠标绕 y 轴旋转。以下是我用于实际旋转的函数(角度以度为单位)。
void CCamera::RotateY (GLfloat Angle)
{
RotatedY += Angle;
//Rotate viewdir around the up vector:
ViewDir = Normalize3dVector(ViewDir*cos(Angle*PIdiv180)
- RightVector*sin(Angle*PIdiv180));
//now compute the new RightVector (by cross product)
RightVector = CrossProduct(&ViewDir, &UpVector);
}
由于我使用的是 GLUT,所以我使用被动函数来获取光标的 x,y 坐标。然后在我的显示中我有以下内容:
void display(void) {
...
mouseDisplacement = mouseX - oldMouseX;
if (mouseDisplacement > 0) Camera.RotateY(-1.0*abs(mouseDisplacement));
else if (mouseDisplacement < 0) Camera.RotateY(1.0*abs(mouseDisplacement));
oldMouseX = mouseX;
glutWarpPointer(centerWindowX, centerWindowY); // move the cursor to center of window
...
}
现在问题很明显,因为显示功能每秒运行 60 次,所以每当我尝试移动鼠标光标时,它就会卡在中间。如果我没有显示功能循环,那么旋转真的很滞后。那么这样做的正确方法是什么?
再次注意,我只是想让相机使用鼠标在左右方向移动。虽然如果我能让它像正常的 fps 一样工作那就太棒了,但这并不是必需的。
非常感谢任何帮助。
【问题讨论】:
标签: c++ opengl camera glut freeglut