Sign in to follow this  
jchmack

does mouse movement really take that much processing

Recommended Posts

im programming a game in opengl pretty much following the nehe tutorials. My game runs fine at like 1200 fps but when things start getting crazy and my fps drops mouse movement seems to make it drop alot faster. Even with things going crazy it keeps above 100 fps, but if i move my mouse wildly it drops to around 30. here is my mouse input code:
LRESULT CALLBACK WndProc(	HWND	hWnd,			// Handle For This Window
							UINT	uMsg,			// Message For This Window
							WPARAM	wParam,			// Additional Message Information
							LPARAM	lParam)			// Additional Message Information
{
	switch (uMsg)									// Check For Windows Messages
	{
		case WM_ACTIVATE:							// Watch For Window Activate Message
		{
			if (!HIWORD(wParam))					// Check Minimization State
			{
				active=TRUE;						// Program Is Active
			}
			else
			{
				active=FALSE;						// Program Is No Longer Active
			}

			return 0;								// Return To The Message Loop
		}

		case WM_SYSCOMMAND:							// Intercept System Commands
		{
			switch (wParam)							// Check System Calls
			{
				case SC_SCREENSAVE:					// Screensaver Trying To Start?
				case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?
				return 0;							// Prevent From Happening
			}
			break;									// Exit
		}

		case WM_CLOSE:								// Did We Receive A Close Message?
		{
			PostQuitMessage(0);						// Send A Quit Message
			return 0;								// Jump Back
		}

		case WM_KEYDOWN:							// Is A Key Being Held Down?
		{
			keys[wParam] = TRUE;					// If So, Mark It As TRUE
			return 0;								// Jump Back
		}

		case WM_KEYUP:								// Has A Key Been Released?
		{
			keys[wParam] = FALSE;					// If So, Mark It As FALSE
			return 0;								// Jump Back
		}

		case WM_SIZE:								// Resize The OpenGL Window
		{
			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
			return 0;										// Jump Back
		}

		case WM_LBUTTONDOWN:
		{
			leftmouse = true;
			return 0;
		}

		case WM_RBUTTONDOWN:
		{
			rightmouse = true;
			return 0;
		}

		case WM_LBUTTONUP:
		{
			leftmouse = false;
			return 0;
		}

		case WM_RBUTTONUP:
		{
			rightmouse = false;
			return 0;
		}

		case WM_MOUSEMOVE:
		{
			int a,b;
			a = LOWORD(lParam);
	        b = HIWORD(lParam);

			mousex=( (a)-(1024/2))/18.55;
			mousey=(-(b)+(768 /2))/18.55;
			return 0;
		}

		case FD_READ:	//winsock message waiting
		{
			message=true;
		}
	}

	// Pass All Unhandled Messages To DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

thanx in advance

Share this post


Link to post
Share on other sites
First thing that comes to my mind is that the mouse movements will generate
a lot of messages, and that could affect how often the "on idle" event happens.

EDIT: That wasnt very helpful I guess :/

Share this post


Link to post
Share on other sites
Normally mouse processing doesn't take many CPU cycles, but you are introducing 4 divisions which are CPU intensive, every mouse message. If you just tap your mouse with your hand you might of just done 80 divisions which will eat up a little CPU processing time and start slowing you done. if you hold your mouse and move it wildely around the screen you could end up doing a thousand divisions which will definitely hurt your frame rate.

To solution to your problem is an easy one, and that is to precalculate the difference your computing from your mouse coordinates.

(1024/2))/18.55 = 27.60107817;
(768 /2))/18.55 = 20.70080863;

thuse your code should look like this


case WM_MOUSEMOVE:
{
int a,b;
a = LOWORD(lParam);
b = HIWORD(lParam);

mousex=( (a)-27.60107817;
mousey=(-(b)+20.70080863;
return 0;
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this