glm::lookAt vertical camera flips when z <= 0

前端 未结 1 1186
执念已碎
执念已碎 2021-01-16 11:10

I\'m working on a FPS style camera to fly around my 3D scene using OpenGL. I\'m using GLM for the mathmetics and I calculate a direction vector with a glm::rotate on the x-a

1条回答
  •  囚心锁ツ
    2021-01-16 11:40

    I'm not entirely sure what the problem is, but when I use LookAt for an FPS cam I also include a forward unit vector.

    E.g (copied relevant segments from some code I have) - using quaternions (orientation), but I'm sure matrices will have the same result)

    static glm::vec3 defaultUpVector() { return glm::vec3(0, 1, 0); }
    static glm::vec3 defaultForwardVector() { return glm::vec3(0, 0, -1); }
    
    pUpVector = defaultUpVector() * orientation;
    pLookAt = position + (defaultForwardVector() * orientation);
    pView = glm::lookAt(position, pLookAt, pUpVector);
    

    upvector and lookat are both vec3, and view is mat4

    Hope this helps.

    EDIT: I notice you are using a direction, so I would probably look at where you use rotate.

    This will set the quat for an FPS cam with no roll

    pLocalOrientation = 
        glm::angleAxis(pLocalEularAngles.x, glm::vec3(1, 0, 0)) *
        glm::angleAxis(pLocalEularAngles.y, glm::vec3(0, 1, 0));
    

    pLocalOrientation == orientation (for the example)

    If you decide to use quats.

    0 讨论(0)
提交回复
热议问题