Search code examples
c++openglcamerarotationglm-math

Opengl Camera rotation around X


Working on an opengl project in visual studio.Im trying to rotate the camera around the X and Y axis. Thats the math i should use

Im having trouble because im using glm::lookAt for camera position and it takes glm::vec3 as arguments. Can someone explain how can i implement this in opengl?

PS:i cant use quaternions


Solution

  • The lookAt function should take three inputs:

    vec3 cameraPosition
    vec3 cameraLookAt
    vec3 cameraUp 
    

    For my past experience, if you want to move the camera, first find the transform matrix of the movement, then apply the matrix onto these three vectors, and the result will be three new vec3, which are your new input into the lookAt function.

    vec3 newCameraPosition = movementMat4 * cameraPosition
    //Same for other two
    

    Another approach could be finding the inverse movement of the one you want the camera to do and applying it to the whole scene. Since moving the camera is kind of equals to move the object onto inverse movement while keep the camera not move :)