Problem directing camera with mouse.

I want to use the mouse to rotate my camera, e.g. moving the mouse left rotates the camera left.

The problem is that when the cursor reaches the edge of the window (or screen in game mode), further mouse movements in that directed are ignored, e.g. if the mouse x-coordinate reaches 0, moving the mouse left has no effect.

This happens even in game mode with no cursor. What gives?

How is this worked around? Is there a GL/GLUT function to allow mouse coordinates to exceed window coordinates? Do I have to programmatically re-center the mouse whenever the cursor reaches the edge of the window?

Easiest way is to define a delta angle with respect to mouse position on screen which you can set up however you like which is added to angle rotation about an axis. Rather than angle equal to mouse position from center.

I could, but that doesn’t get around the problem that once the mouse reaches the edge of a window, further movements in that direction are ignored.

For example, once the cursor (visible or invisible) gets to the very top left of the screen (0,0), moving the mouse up and/or left has no effect - the motion callback function is not even called.

What you want to do is set the cursor to the middle of the screen everytime you move the mouse. This is a snap from my terrain engine.

	// Get mouse position
	GetCursorPos( &cursorPos );
	// Set mouse position to the middle of the screen
	SetCursorPos( midX, midY );

	// Check for mouse movement
	if( (cursorPos.x != midX) | | (cursorPos.y != midY) )
	{
		// Obtaining the amount of movement
		x += (midX - cursorPos.x)/10.f;
		y += (midY - cursorPos.y)/10.f;

		// Checking X bounds for rotation
		if     ( x <    0 ) { x = 360; }
		else if( x >  360 ) { x =   0; }
		// Checking Y bounds for rotation
		if     ( y >  89.f) {y =  89.f;}
		else if( y < -89.f) {y = -89.f;}

		// Rotating camera
		DemoGame->m_Camera->RotateCamera( x, y, 0 );

	} // Endif for mouse movement detection

Miguel Castillo

That looks good - does anyone have a code snippet that does it in C on Linux? Don’t tell me I have to learn Xlib too…