Jump to content
  • Advertisement
Sign in to follow this  
FreJa

glutWarpPointer on Mac

This topic is 3590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!!

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!