title: Quaternion camera. How do I make it rotate correctly?
body: <p>I have a 3D camera with its current rotation stored as a quaternion, and I'm having trouble rotating it correctly. I want the camera to rotate incrementally around its local axes based on mouse movement each frame (first-person-shooter-style), but the rotation is wrong. It kind of works, but the camera seems to "roll" around its forward axis when it shouldn't.</p>
  
  <p>I update the rotation each frame with this function:</p>
  
  <pre><code>void Camera::rotate(const Quat&amp; q)
  {
      // m_rot is the current rotation
      m_rot = m_rot * q;
  }
  </code></pre>
  
  <p>Here's my quaternion multiplication function:</p>
  
  <pre><code>Quat Quat::operator*(const Quat &amp;rhs) const
  {
      // quaternion elements in w,x,y,z order
      Vector4d res;
  
      res[0] = m_q[0]*rhs.m_q[0] - m_q[1]*rhs.m_q[1] -
               m_q[2]*rhs.m_q[2] - m_q[3]*rhs.m_q[3];
      res[1] = m_q[0]*rhs.m_q[1] + m_q[1]*rhs.m_q[0] +
               m_q[2]*rhs.m_q[3] - m_q[3]*rhs.m_q[2];
      res[2] = m_q[0]*rhs.m_q[2] - m_q[1]*rhs.m_q[3] +
               m_q[2]*rhs.m_q[0] + m_q[3]*rhs.m_q[1];
      res[3] = m_q[0]*rhs.m_q[3] + m_q[1]*rhs.m_q[2] -
               m_q[2]*rhs.m_q[1] + m_q[3]*rhs.m_q[0];
  
      return Quat(res);
  }
  </code></pre>
  
  <p>Am I doing something wrong, or is this some kind of floating-point error thing?</p>