Mouse Look Input Problem

Started by
5 comments, last by akaitora 13 years, 3 months ago
I wrote a mouse look feature that works similarly to most spectator camera systems. Every frame the mouse cursor is locked to the center of the viewport.
Whenever the mouse moves, I want to know the difference vector so I can determine how to orient the camera. I found myself having to use offsets such as -4 for the x value and -30 for the y value in order to get it to work. I am using the ScreenToClient Function so I would think that offsets wouldn't be needed. Furthermore, while my -30 offset works for all the windows platforms I have run my demo on, my X offset seems to need to be changed from platform to platform. For example, on Windows 7, the -4 offset works fine however on XP it causes the camera to be continually rotated. However on XP, a value of -8 works while on Windows 7 I get the same issue. I assume this is due to that fact that each OS has different sized menu bars which contribute to the overall position of the mouse however as I stated, I am using the ScreenToClient function which I thought was suppose to handle this issue. Any additional information would be highly appreciated!




if(GetAsyncKeyState(VK_RBUTTON) & 0x8000)
{
GetCursorPos(&m_pntCurrentCursorPosition);
ScreenToClient(m_hWnd, &m_pntCurrentCursorPosition);

double fXDiff = m_pntCurrentCursorPosition.x - ((iScreenWidth/2)-4); // On Windows 7, 4 should be 8 but on Windows XP, it should be 4.
double fYDiff = m_pntCurrentCursorPosition.y - ((iScreenHeight/2)-30);
...
}

xdpixel.com - Practical Computer Graphics

Advertisement
Where is the code that locks the cursor position - are you sure that's working correctly?
Where do you get iScreenWidth and iScreenHeight? From the client rect? If you get them from the window rect, that's where the extra offsets come from.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Hmm... ok so I modified the code to look like this but still to no avail...



if(GetAsyncKeyState(VK_RBUTTON) & 0x8000)
{
RECT rectWindow;
RECT rectScreen;
GetCursorPos(&m_pntCurrentCursorPosition);
ScreenToClient(m_hWnd, &m_pntCurrentCursorPosition);
GetWindowRect(m_hWnd, &rectWindow);
GetClientRect(m_hWnd, &rectScreen);

double dXOffset = rectWindow.right - rectScreen.right;
double dYOffset = rectWindow.bottom - rectScreen.bottom;

double fXDiff = m_pntCurrentCursorPosition.x - ((rectScreen.right/2) - dXOffset);
double fYDiff = m_pntCurrentCursorPosition.y - ((rectScreen.bottom/2) - dYOffset);
...
// Lock the cursor back in place.
SetCursorPos((rectScreen.right/2), (rectScreen.bottom/2));
}

xdpixel.com - Practical Computer Graphics

SetCursorPos takes screen coordiantes, but you're sending it client coordinates.

Try changing:
SetCursorPos((rectScreen.right/2), (rectScreen.bottom/2));

to
SetCursorPos((rectWindow.right/2), (rectWindow.bottom/2))

and get rid of the offset.
Thanks but the camera is still rotating with your proposed changes.

xdpixel.com - Practical Computer Graphics

Ah I fixed it! Stupid error... I forgot to take out the


ScreenToClient(m_hWnd, &m_pntCurrentCursorPosition);


Everything works now. Thanks!

xdpixel.com - Practical Computer Graphics

This topic is closed to new replies.

Advertisement