glutWarpPointer on Mac

Started by
0 comments, last by Uuugggg 15 years, 5 months ago
Hey, My intention is to make a first-person camera, meaning the user's mouse should be always at the center of the window. For this one would use glutWarpPointer. However, on Mac OS, this function doesn't work very well and so, the solution, is to use CGDisplayMoveCursorToPoint with CGGetLastMouseDelta. My question is: CGGetLastMouseDelta returns the references to two CGMouseDelta objects... how can I use these in some way useful? This is my working code, in Windows:

void Camera::onMousePassiveMotion(int x, int y) 
	{
		int middleX = (int)_winWidth  >> 1;				// This is a binary shift to get half the width
		int middleY = (int)_winHeight >> 1;				// This is a binary shift to get half the height
		float angleY = 0.0f;							// This is the direction for looking up or down
		float angleZ = 0.0f;							// This will be the value we need to rotate around the Y axis (Left and Right)
		static float currentRotX = 0.0f;
		
		// If our cursor is still in the middle, we never moved... so don't update the screen
		if( (x == middleX) && (y == middleY) ) return;
		
		// Set the mouse position to the middle of our window
		glutWarpPointer(middleX, middleY);
		
		// Get the direction the mouse moved in, but bring the number down to a reasonable amount
		angleY = (float)( (middleX - x) ) / 500.0f;		
		angleZ = (float)( (middleY - y) ) / 500.0f;		
		
		// Here we keep track of the current rotation (for up and down) so that
		// we can restrict the camera from doing a full 360 loop.
		currentRotX -= angleZ;  
		
		// If the current rotation (in radians) is greater than 1.0, we want to cap it.
		if(currentRotX > 1.0f)
			currentRotX = 1.0f;
		// Check if the rotation is below -1.0, if so we want to make sure it doesn't continue
		else if(currentRotX < -1.0f)
			currentRotX = -1.0f;
		// Otherwise, we can rotate the view around our position
		else
		{
			// To find the axis we need to rotate around for up and down
			// movements, we need to get a perpendicular vector from the
			// camera's view vector and up vector.  This will be the axis.
			Vector3f vAxis = cross(_lookAt - _position, _up);
			vAxis = normalize(vAxis);
			
			// Rotate around our perpendicular axis and along the y-axis
			RotateView(angleZ, vAxis[0], vAxis[1], vAxis[2]);
		}
		
		// Rotate around the y axis no matter what the currentRotX is
		RotateView(angleY, 0, 1, 0);
	}

Thanks!!
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
Advertisement
My FPS is like this:


int mouseDeltaX,mouseDeltaY;
CGGetLastMouseDelta(& mouseDeltaX, & mouseDeltaY);
float leftRightRotation = mouseDeltaX/150.0f;
float UoDownRotation = mouseDeltaY/150.0f;

and to start it all. keep the cursor in center:


CGDisplayHideCursor(kCGDirectMainDisplay);
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay,
CGPointMake(glutGet(GLUT_WINDOW_WIDTH)/2, glutGet(GLUT_WINDOW_HEIGHT)));
CGAssociateMouseAndMouseCursorPosition(false);

This topic is closed to new replies.

Advertisement