Rotate camera with mouse

How can I get the camera to rotate by using the mouse (using GLUT). I have tried using the glutMotionFunc(); But it seems to only give positive values, because it rotates the camera just fine, however it only rotates in the positive direction regardless of whether I move my mouse left or right. I have also tried the glutMouseFunc();, which seems to work perfectly, however it only updates the motion when I click my mouse.

Also, how can I get this to work without having to click.

Ok, I think I have fixed it. I can now rotate using the mouse with the glutMotionFunc();

But, how can I get it to work without clicking the mouse?

glutPassiveMotionFunc

http://www.opengl.org/documentation/specs/glut/spec3/node51.html

Thank you Dr^Nick.

However, I have one more question. glutPassiveMotionFunc only detects mouse position to the window borders. Is there a way to still detect mouse motion past the window border?

I don’t think you can do this with GLUT, directly.

Probably the most sensible way to do this is through the Windows API SetCapture/ReleaseCapture functions (or look at the Linux/Mac equivalents).

Then is there anyway to reposition the mouse??

With the following functions, you can get the mouse changes, however you should write an extra code to rotate and move the camera.

void repositionMouse(float& deltaMouseX, float& deltaMouseY)
{
int x = glutGet(GLUT_WINDOW_X);
int y = glutGet(GLUT_WINDOW_Y);
int width = glutGet(GLUT_WINDOW_WIDTH);
int height = glutGet(GLUT_WINDOW_HEIGHT);

int cx = (width>>1);
int cy = (height>>1);

glutWarpPointer(cx, cy);

deltaMouseX = float(cx - gMouseX);
deltaMouseY = float(cy - gMouseY);
}

void UpdateCameraVariables(int x, int y)
{
gMouseX = x;
gMouseY = y;

float dmx, dmy;
repositionMouse(dmx, dmy);

gTargetYaw	+= dmx; 
gTargetPitch	+= dmy;
}

void MotionCallback(int x, int y)
{
UpdateCameraVariables(x, y);
RenderCallback(); // Glut insanity
}

void PassiveMotionCallback(int x, int y)
{
UpdateCameraVariables(x, y);
RenderCallback(); // Glut insanity
}

-Ehsan-