PDA

View Full Version : Rotation camera LookAt point with quarternion problem



lummxx
02-12-2016, 10:18 PM
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));
}

lummxx
02-13-2016, 04:00 PM
OK, just wanted to post my solution, maybe i till help someone someday :angel:




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