title: Quaternion based camera
body: <p>I try to implement an FPS camera based on quaternion math.
  I store a rotation quaternion variable called <code>_quat</code> and multiply it by another quaternion when needed. Here's some code:</p>
  
  <pre><code>void Camera::SetOrientation(float rightAngle, float upAngle)//in degrees
  {
      glm::quat q = glm::angleAxis(glm::radians(-upAngle), glm::vec3(1,0,0));
                q*= glm::angleAxis(glm::radians(rightAngle), glm::vec3(0,1,0));
  
      _quat = q;
  }
  
  void Camera::OffsetOrientation(float rightAngle, float upAngle)//in degrees
  {
      glm::quat q = glm::angleAxis(glm::radians(-upAngle), glm::vec3(1,0,0));
                q*= glm::angleAxis(glm::radians(rightAngle), glm::vec3(0,1,0));
  
      _quat *= q;
  }
  </code></pre>
  
  <p>The application can request the orientation matrix via <code>GetOrientation</code>, which simply casts the quaternion to a matrix.</p>
  
  <pre><code>glm::mat4 Camera::GetOrientation() const
  {
      return glm::mat4_cast(_quat);
  }
  </code></pre>
  
  <p>The application changes the orientation in the following way:</p>
  
  <pre><code>int diffX = ...;//some computations based on mouse movement
  int diffY = ...;
  
  camera.OffsetOrientation(g_mouseSensitivity * diffX, g_mouseSensitivity * diffY);
  </code></pre>
  
  <p>This results in bad, mixed rotations around pretty much all the axes. What am I doing wrong?</p>