The mouse look (or free look, i.e., move the mouse to change the view/camera) is common in RPG and FPS games. In my cloud game project, I tried to achieve this feature. Before programming, I tested an RPG game (Genshin) in Windows, I started it directly in my PC and used spy++ to check what happened when I moved the mouse. I got these results:

enter image description here

It seemed that however I moved the mouse, although the role's view changed, the positions in WM_MOUSEMOVE messages didn't change too much. Actually, 640 and 343 were about the half of the resolution sizes (1280*720).


How those games achieve this: move the mouse and change the role's view, but the positions in messages don't change? What bottom winapis are used? (I hooked ClipCursor and the input parameters of ClipCursor were just my screen's width and height.) In cloud games, I need to use remote mice (clients' inputs) to achieve this feature, what can I do?


1 Answer 1


How those games achieve this: move the mouse and change the role's view, but the positions in messages don't change?

See the WM_SETCURSOR messages immediately following the WM_MOUSEMOVE ones? That's how!

They will always reset the mouse cursor to the center of the viewport, i.e. SetCursorPos(iViewportWidth / 2, iViewportHeight / 2).

In your case that would be SetCursorPos(640,360) - c.f. SetCursorPos

The next time you move the mouse Windows sends the new cursor position in a WM_MOUSEMOVE message, like (628, 363) - and the program then calculates (628 - 640, 363 - 360), which is (-12,3) and is the relative mouse movement (in respect of the last value). So it will then calculate the new camera view of looking more to the left (because x = -12 is negative) and a little bit further down (y = +3). It then immediately resets the cursor position to the center via SetCursorPos(640,360) and the process repeats.

This way the mouse cursor will never reach the window borders and be clipped by Windows - which would lead to strange effects.

  • \$\begingroup\$ Thanks for your reply. I still have some questions: 1. According to ms document, parameters for SetCursorPos should be "screen" coordinates. Should I use ClientToScreen to change iViewportWidth / 2, iViewportHeight / 2 to screen coordinates? \$\endgroup\$
    – DerekLu
    May 13, 2021 at 12:55
  • \$\begingroup\$ 2. The whole procedure, according to your answer, is post WM_MOUSEMOVE-process this message-set the cursor to the center. In cloud game situations (client-server), the server side just has the inputs of the client. So I post the message and set the cursor, but how to process the message, i.e., get the relative mouse movement and change the camera view? \$\endgroup\$
    – DerekLu
    May 13, 2021 at 12:58
  • \$\begingroup\$ That sounds like a different question than the one you asked. "How do I implement camera movement in a client-server FPS" versus "Why the mouse doesn't move in mouse-look". You can create a new question post to explain your current situation in more detail and ask for help with the part you need. \$\endgroup\$
    – DMGregory
    May 14, 2021 at 10:43
  • \$\begingroup\$ @DMGregory Thanks for your advice. \$\endgroup\$
    – DerekLu
    May 14, 2021 at 12:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .