1
\$\begingroup\$

I want to make a camera that can freely look and walk on X/Z plane and rotate 360 degrees. I'm using OpenGL and the lookAt function from the GLM library to create the view matrix. I've looked through tutorials but many of them use trigonometry and I can't quite understand why it's used like below:

glm::vec3 direction(
    cos(verticalAngle) * sin(horizontalAngle),
    sin(verticalAngle),
    cos(verticalAngle) * cos(horizontalAngle)
);

I tried to rotate the horizontal view of the camera by multiplying a rotation matrix of Y axis with the center vector (the vector that represents which point camera is looking at), but the result was that the objects in the scene kept on self-rotating. How can I achieving creating a camera that can walk on the X/Z plane and look around?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.