Jump to content
  • Advertisement
Sign in to follow this  
akaitora

Mouse Look Input Problem

This topic is 2716 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

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);
...
}

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Ah I fixed it! Stupid error... I forgot to take out the


ScreenToClient(m_hWnd, &m_pntCurrentCursorPosition);


Everything works now. Thanks!

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!