title: How to move around camera using mouse in OpenGL?
body: <p>I realize this question has been asked before on stackoverflow, but I have yet to find an answer that I understand completely so I thought I'd get some help specific to my situation.</p>
  
  <p>I basically want to be able to use the mouse to rotate around the y-axis. Following is the function I'm using for the actual rotation (angles are in degrees).</p>
  
  <pre><code>void CCamera::RotateY (GLfloat Angle)
  {
      RotatedY += Angle;
  
      //Rotate viewdir around the up vector:
      ViewDir = Normalize3dVector(ViewDir*cos(Angle*PIdiv180)
                      - RightVector*sin(Angle*PIdiv180));
  
      //now compute the new RightVector (by cross product)
      RightVector = CrossProduct(&amp;ViewDir, &amp;UpVector);
  }
  </code></pre>
  
  <p>Since I'm using GLUT, I use the passive function to get the x,y coordinates of the cursor. And then in my display I have the following:</p>
  
  <pre><code>void display(void) {
      ...
      mouseDisplacement = mouseX - oldMouseX;
  
      if (mouseDisplacement &gt; 0) Camera.RotateY(-1.0*abs(mouseDisplacement));
      else if (mouseDisplacement &lt; 0) Camera.RotateY(1.0*abs(mouseDisplacement));
  
      oldMouseX = mouseX;
      glutWarpPointer(centerWindowX, centerWindowY);  // move the cursor to center of window
      ...    
  }
  </code></pre>
  
  <p>Now the problem is pretty obvious, since the display function runs 60 times a second, the mouse cursor just gets stuck in the middle whenever I try to move it. If I don't have the display function loop, the rotation is really laggy and stuff. So what is the proper way of doing this?</p>
  
  <p>Note again, I'm only looking to have the camera move around in right/left direction using the mouse. Although it'd be awesome if I could get it working like a proper fps, it's not really essential.</p>
  
  <p>Any help is greatly appreciated.</p>