【发布时间】:2011-11-27 16:06:24
【问题描述】:
我有一个 opengl 程序,我正在使用 SDL 来创建窗口/事件处理等。现在,当我移动鼠标重新定位相机偏航/俯仰角时,我得到一个抖动的图像,旧位置闪烁在屏幕上停留片刻。
现在我认为这可能是我重新定位鼠标的方式的问题。在重新定位结束时,我将其设置回屏幕的中心。这是上述代码:
void handleMouseMove(int mouseX, int mouseY)
{
GLfloat vertMouseSensitivity = 10.0f;
GLfloat horizMouseSensitivity = 10.0f;
int horizMovement = mouseX - midWindowX;
int vertMovement = mouseY - midWindowY;
camXRot += vertMovement / vertMouseSensitivity;
camYRot += horizMovement / horizMouseSensitivity;
if (camXRot < -90.0f)
{
camXRot = -90.0f;
}
if (camXRot > 90.0f)
{
camXRot = 90.0f;
}
if (camYRot < -180.0f)
{
camYRot += 360.0f;
}
if (camYRot > 180.0f)
{
camYRot -= 360.0f;
}
// Reset the mouse to center of screen
SDL_WarpMouse(midWindowX, midWindowY);
}
现在,在我的主 while 循环中,这里是调用此函数的 SDL 代码:
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_KEYDOWN )
{
if( event.key.keysym.sym == SDLK_ESCAPE )
{
Game.running = false;
}
}
if( event.type == SDL_MOUSEMOTION )
{
int mouse_x, mouse_y;
SDL_GetMouseState(&mouse_x, &mouse_y);
handleMouseMove(mouse_x, mouse_y);
}
我发现获取像 event.motion.x 和 event.motion.x 这样的坐标导致的这种影响较小。
对如何避免这种“抖动”图像有什么想法吗?
【问题讨论】:
-
你绘制的表面是双缓冲的吗?