PDA

View Full Version : Rotate camera with mouse



RHINO
10-23-2006, 05:15 PM
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.

RHINO
10-23-2006, 05:20 PM
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?

10-23-2006, 06:37 PM
glutPassiveMotionFunc

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

RHINO
10-25-2006, 07:06 PM
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?

10-25-2006, 07:52 PM
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).

RHINO
10-26-2006, 02:19 PM
Then is there anyway to reposition the mouse??

Ehsan Kamrani
10-26-2006, 03:13 PM
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-