0

I'm trying to do simple camera rotation through mouse trackball in OpenGL. Currently, I calculate the displacement of the mouse and use that to generate the rotation matrix, which I use to update the camera position and up vectors.

However, the camera only rotates along one single plane right now. For example, it will move left and right if I move my mouse in those directions at first, but if I turn it 90 degrees to one side, it will rotate up and down only even if I am stilling moving my mouse left to right.

The following code is used to calculate the viewpoint matrix. rotAxis and rotAngle are generated by trackball mapping which maps the mouse position to a sphere.

I know I need to multiply something by the rotation matrix that takes into account the location of the camera in respect to the world matrix. However, I have no idea what that matrix is.

cam_pos = [unknown_matrix] * glm::rotate(cam_pos, rotAngle / 180.0f * glm::pi<float>(), rotAxis);
cam_up = [unknown_matrix] * glm::rotate(cam_up, rotAngle / 180.0f * glm::pi<float>(), rotAxis);
V = glm::lookAt(cam_pos, cam_look_at, cam_up);
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Robert Lu
  • 441
  • 2
  • 7
  • 18
  • Most likely you [don't need `lookAt`](http://stackoverflow.com/a/40196692/277176). Can you show the calculations of `rotAxis`, `rotAngle` and `cam_look_at`? – Yakov Galka Nov 03 '16 at 10:10
  • Your problem looks very similar to that of [this question](http://stackoverflow.com/questions/40182783/control-of-orthographic-camera-position-and-orientation-from-euler-angles/40222955#40222955). – Nico Schertler Nov 03 '16 at 12:38

0 Answers0