How to restrict vertical angle? FPS glm::lookAt camera?
I am following along with this tutorial: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/ , but I can't seem to be able to restrict the vertical angle of my camera in such a way so I can not bend backwards... if my camera yaw is 156 for example and i look around and the yaw becomes 158 degrees my scene rotates 3-4 times. How do I restrict it?
I calculate my direction vector like this:
glm::vec3 direction(
cos(verticalAngle) * sin(horizontalAngle),
sin(verticalAngle),
cos(verticalAngle) * cos(horizontalAngle)
);
And calculate my up vector like this:
// Right vector
glm::vec3 right = glm::vec3(
sin(horizontalAngle - 3.14f/2.0f),
0,
cos(horizontalAngle - 3.14f/2.0f)
);
glm::vec3 up = glm::cross( right, direction );
Then just pass the position and up vectors to to glm::lookAt. It doesn't work as expected however - I can look around and move perfectly but horizontal angle does not match the actual scene rotation.
A better question will be: how to make horizontalAngle and verticalAngle match the actual scene rotation.
EDIT: I am a genius! :DI "cout" my rotation in radians... if I cout it in degrees everythings fine.
链接地址: http://www.djcxy.com/p/81754.html上一篇: 如何避免相机翻转四元数旋转?