Problem with input : Mouse too sensitive.

Started by
8 comments, last by lollan 15 years, 7 months ago
Hi, I have a class call CInputHandler, this class is just checking the input. I use WinAPI and the WM_MOUSEMOVE as fallow (in my msg treatment function):

	case WM_MOUSEMOVE:
	{
		event.type = EInputType::MOUSE ;
		event.MouseInput.type = EMouseInputType::MOVED ;
		event.MouseInput.x = (short)LOWORD(lParam);
		event.MouseInput.y = (short)HIWORD(lParam);
	
		gInput->notify(event) ;
		return 0;
	}


Then later in the code of a first person Camera (CBasicCamera) when I want to check the mouse I just do that:

	if ( gInput->hasMouseMoved() )
	{
		float pitch  = gInput->getMouseX() / 150.0f;
		float yAngle = gInput->getMouseY()  / 150.0f;
        }
        //REST of the code


I use the same kind of approach for keys and the wheel. My problem is that the mouse is still too sensitive, in fact even when I don't touch the mouse the camera is moving. Does anybody have an idea of what can cause this ? If you need some information, please let me know. Thanks
Advertisement
You must not use the mouse cursor position for this, you must use its 'displacement' instead, it is the last position minus the current position. Then, you add this displacement times a sensitivity (a configurable float which controls how much of the mouse movement is translated to the camera(or whatever) orientation.

You can keep the last cursor position into somewhere you can always get it when creating a new mouse event.

HTH

.
Quote:Original post by lollan
in fact even when I don't touch the mouse the camera is moving. Does anybody have an idea of what can cause this ?
Sounds liek a bug elsewhere in your code. If the mouse isn't moving, you won't get WM_MOUSEMOVE notifications, so your mouse position shouldn't change. I think you'll just have to debug this further and see why your camera is moving.
Have you tried using larger values?

In any case, a multiplication is cheaper than a division:

if ( gInput->hasMouseMoved() )	{		float pitch  = gInput->getMouseX() * 0.0001f;		float yAngle = gInput->getMouseY()  * 0.0001f;        }


"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

Hi all ^^

Quote:
Have you tried using larger values?
In any case, a multiplication is cheaper than a division

Posted by deadstar


Thanks for the multiplication trick ^^, I already tried that yes , but thanks

xissburg : Are you sure that WinAPI doesn't do this calculation for you ? I thought that the value return by WinAPI was this value. Otherwise I would need to calculate each time from the current pixel position no ? Thanks

Evil Steve: You are going to laugh but I did not think of that ... lol. I'm so used to misterious comportement with WinAPI that I their code instead of mine lol.I should know my place ^^. Thanks I'll do that.

I'll let you know when I fixed it what it was.

Cheers

Quote:
xissburg : Are you sure that WinAPI doesn't do this calculation for you ? I thought that the value return by WinAPI was this value. Otherwise I would need to calculate each time from the current pixel position no ?


The windows API gives you the current cursor position, I have never seen a function which returns the displacement. I always did that by myself, but that is very simple indeed. Then you need to 'add' the displacement times sensitivity to the current value of the yaw,pitch,roll of your camera or whatever..
.
xissburg: Ok thanks,
I will try that and post the reply.

Evil Steve: I went through the process of debugging and I couldn't find a thing, I'm still looking into it.
Hi,

I didn't have internet for a while so I couldn't post that I fixed the problem a week ago.

I had in fact multiple problem, the first one is that my input class was keep track of my mouse movement until another event erased ut. So I created a clear() method which I used after I checked the mouse input if it is successful.(Evil Steve : that is why my event was always repeating itself, it wasn't because of winAPI it was because I never restate the state of my input object).

The second problem was that winAPI don't return the mouse movement (like xissburg said) but just return the pixel it points to, I had to remember the last pixel location and then substract to it the new one, do have the delta movement of the mouse.

Finally my mouse was too sensitive I solve that by multiplying by 0.005 ( like deadstar said use smaller value).
So my first person camera works fine( of course it can be ameliorate ) I can do other stuff no.

Thanks all for the help.
[Resolved]
Quote:The windows API gives you the current cursor position, I have never seen a function which returns the displacement.


Actually, there is a nice way to retrieve mouse delta values (displacement) by registering WM_INPUT message:

    #ifndef HID_USAGE_PAGE_GENERIC    #define HID_USAGE_PAGE_GENERIC         ((USHORT) 0x01)    #endif    #ifndef HID_USAGE_GENERIC_MOUSE    #define HID_USAGE_GENERIC_MOUSE        ((USHORT) 0x02)    #endif    RAWINPUTDEVICE Rid[1];    Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC;     Rid[0].usUsage = HID_USAGE_GENERIC_MOUSE;     Rid[0].dwFlags = RIDEV_INPUTSINK;       Rid[0].hwndTarget = hWnd;    RegisterRawInputDevices(Rid, 1, sizeof(Rid[0]);



After that you can deal with WM_INPUT event in the message handler:

    case WM_INPUT:     {        UINT dwSize = 40;        static BYTE lpb[40];            GetRawInputData((HRAWINPUT)lParam, RID_INPUT,                         lpb, &dwSize, sizeof(RAWINPUTHEADER));            RAWINPUT* raw = (RAWINPUT*)lpb;            if (raw->header.dwType == RIM_TYPEMOUSE)         {            int xPosRelative = raw->data.mouse.lLastX;            int yPosRelative = raw->data.mouse.lLastY;        }         break;    }


For more information look into DirectX SDK documentation (article entitled: "Taking Advantage of High-Definition Mouse Movement").
I've read this article a while back and was planing to modify my mouse handling using this way later.

However I didn't notice in the article that I retrieved directly the displacement.

Thanks for pointing it out.

This topic is closed to new replies.

Advertisement