0

I am trying to rotate the camera using quarternions but i have problems doing it.

The first thing that I notices now is that when I execute this the Camera Position and Camera LookAt become almost the same and in some cases they are the same and then i get precision problems and all other problems relating to it when i try and move the camera.

if (Input::getInstance()->isMouseDown(SDL_BUTTON_RIGHT-1)){
        //log_.debug("Camera Mouse Left down");
        glm::vec2 mouseDelta = glm::ivec2(oldX, oldY) - Input::getInstance()->getMousePosition();
        glm::quat q1 = glm::quat(glm::vec3(glm::radians(mouseDelta.y), glm::radians(mouseDelta.x), 0.0f));
        cameraLook_ = q1 * (direction * mouseSensitivity_) * glm::conjugate(q1) + cameraPosition_;
        //cameraLook_ = glm::rotate(cameraLook_, mouseDelta.x  * delta, glm::vec3(0,1,0));
        //cameraLook_ = glm::rotate(cameraLook_, mouseDelta.y  * delta, glm::vec3(0, 0, 1));
}

1 Answer 1

0

I switched back to matrices for my solution, because for me they are easier to work with at the moment.

There are few things i need to understand about quarternions then I can fix my old problem.

    glm::mat4 rotationMatrix = glm::translate(cameraPosition_ - glm::vec3(1.0));
    rotationMatrix *= glm::rotate(mouseDelta.x, glm::vec3(0, 1, 0));
    rotationMatrix *= glm::rotate(mouseDelta.y, glm::vec3(0, 0, 1));
    rotationMatrix *= glm::translate(-cameraPosition_ + glm::vec3(1.0));
    cameraLook_ = glm::vec3(rotationMatrix * glm::vec4(cameraLook_, 1.0f));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.