Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Rotation camera LookAt point with quarternion problem

  1. #1
    Intern Contributor
    Join Date
    Sep 2014
    Location
    Tucson
    Posts
    62

    Rotation camera LookAt point with quarternion problem

    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.


    Code :
    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));
    }

  2. #2
    Intern Contributor
    Join Date
    Sep 2014
    Location
    Tucson
    Posts
    62
    OK, just wanted to post my solution, maybe i till help someone someday


    Code :
    		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));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •