当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - How to continue rotating the camera when cursor is at the edge?

问题描述:

I have a fullscreen OpenGL app and I have a Camera class that handles rotating and translating the camera with keyboard and mouse inputs.

The problem that I have is when the cursor at the edge of the screen, I want to continue rotating the camera but it stops rotating.

I tried to warp the cursor to center but when I do that it doesn't even rotate. How can I achieve this expected behaviour?

void Camera::mouseUpdate(const glm::vec2& newMousePosition)

{

//if (noUpdate)

//{

// noUpdate = false;

// return;

//}

glm::vec2 mouseDelta = newMousePosition - oldMousePosition;

if (glm::length(mouseDelta) > 50.0f)

{

oldMousePosition = newMousePosition;

return;

}

const float ROTATIONAL_SPEED = 0.5f;

strafeDirection = glm::cross(viewDirection, UP);

glm::mat4 rotator = glm::rotate(-mouseDelta.x * ROTATIONAL_SPEED, UP) *

glm::rotate(-mouseDelta.y * ROTATIONAL_SPEED, strafeDirection);

viewDirection = glm::mat3(rotator) * viewDirection;

oldMousePosition = newMousePosition;

//glutWarpPointer( 500, 500);

//noUpdate = true;

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: