Recentering the mouse, fixed timestep

Recommended Posts

Hi all,

I'm struggling with an issue in the way I handle mouse input.
This is my current setup/ approach:

- I have a fixed timestep for updating game logics/ physics (i.e. 1/60th of a second
- rendering happens as fast as the conditions allow it
- I have an input system that takes RAW axis's on the input side, and provides logical ranges on the output side
(i.e. mouse axis X/Y in, and camera X/Y output)
- for the camera 'look'/ rotation, I use relative coordinates. Meaning that when the mouse moved 3 by 3 pixels the last frame, the camera is rotated using that as input
- after the game logics read/ retrieved the current logical range, it sets the raw axis input to 0, 0 (because it's relative) (*** A ***)

Now, the problem:
- depending on debug/ release or framerate, the number of times WM_MOUSEMOVE is called, differs
- in the handling of WM_MOUSEMOVE I update the RAW AXIS's values to the inputsystem
-- and I reset the mouse cursor

The symptom is that the mouselook/ rotation is slower when framerates are higher.
I also found out why, this is because the offsets/ relative movement of the mouse is very small, because after each WM_MOUSEMOVE, the cursor is reset (to center of the screen)

I thought of different solutions, for example resetting the mouse cursor at the point marked as ***A*** above. But then the game logics would know and act on something called a mouse. This is exactly what I want to prevent with the input handler. Because it could also be joypad or keyboard or whatsoever. Another solution could be that I add a GetRAWAxisValue function to the inputhandler, and check if this is 0, and if it isn't, then reset the mouse cursor (in WM_MOUSEMOVE handling).

I'm wondering if someone could point me in the right direction or suggest another solution.
Where possible I want to stay with relative, so no absolute mouse positions (because of going out of screen/window bounds etc., + the camera input system currently also expects 'changes', no absolute ranges).

Any input is appreciated.

Share this post


Link to post
Share on other sites
1 hour ago, cozzie said:

I thought of different solutions, for example resetting the mouse cursor at the point marked as ***A*** above. But then the game logics would know and act on something called a mouse.

You don't have to reset it inside your game logic do you? You know which frames will update game logic, reset in those frames after the game logic update.

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