1
Feature requests / Relative Mouse Movement (Mouse Capture)
« on: October 10, 2012, 03:41:22 am »
This proposal stems from an issue raised on the French forum.
http://fr.sfml-dev.org/forums/index.php?topic=9075.msg62994#msg62994
For first-person games with mouse control, developers need relative mouse movement, as opposed to absolute coordinates. SFML needs either a window style or a window method that locks the mouse, hides the cursor, and sends sf::Event::MouseMove events containing relative x and y updates.
Windows, X11, and OS X will all accomplish this differently, so this feature could take some time to fully implement. It's critical for providing mouse support in an FPS though, so it would be well worth the time spent.
To accomplish this on OS X, the mouse cursor has to be hidden, the mouse has to be disconnected from the cursor, and the mouse delta has to be polled by the application for changes. I've posted a sort of "starter kit" for accomplishing this over on Github (https://github.com/SFML/SFML/issues/290#issuecomment-9279071).
It's been so long since I did any WinAPI or X11 development that I don't have immediate suggestions for how to accomplish mouse locking on those platforms. Relative mouse movement is a feature common to many games, but its implementation is platform specific. It's the kind of input abstraction that belongs in SFML.
Developers would either call something like window.captureMouse(), or it would be passed as an option on window creation with a style like sf::Style::CaptureMouse. In either case, they'd receive a window that has essentially "captured" the mouse, locking the cursor down and hiding it so that all mouse movements are reported as some distance from zero. Anytime the mouse stops moving, it automatically returns to zero, and any further movement is again reported as some distance from zero.
As an example, on the X axis a reading of -5 would mean tell the game that the user moved the mouse slightly to the left. Another reading of -35 would mean the user moved the mouse to the left faster. A subsequent reading of 100 would indicate that the user has snapped the mouse quickly to the right. This is a rough example, but illustrates how relative mouse movements are helpful.
http://fr.sfml-dev.org/forums/index.php?topic=9075.msg62994#msg62994
For first-person games with mouse control, developers need relative mouse movement, as opposed to absolute coordinates. SFML needs either a window style or a window method that locks the mouse, hides the cursor, and sends sf::Event::MouseMove events containing relative x and y updates.
Windows, X11, and OS X will all accomplish this differently, so this feature could take some time to fully implement. It's critical for providing mouse support in an FPS though, so it would be well worth the time spent.
To accomplish this on OS X, the mouse cursor has to be hidden, the mouse has to be disconnected from the cursor, and the mouse delta has to be polled by the application for changes. I've posted a sort of "starter kit" for accomplishing this over on Github (https://github.com/SFML/SFML/issues/290#issuecomment-9279071).
It's been so long since I did any WinAPI or X11 development that I don't have immediate suggestions for how to accomplish mouse locking on those platforms. Relative mouse movement is a feature common to many games, but its implementation is platform specific. It's the kind of input abstraction that belongs in SFML.
Developers would either call something like window.captureMouse(), or it would be passed as an option on window creation with a style like sf::Style::CaptureMouse. In either case, they'd receive a window that has essentially "captured" the mouse, locking the cursor down and hiding it so that all mouse movements are reported as some distance from zero. Anytime the mouse stops moving, it automatically returns to zero, and any further movement is again reported as some distance from zero.
As an example, on the X axis a reading of -5 would mean tell the game that the user moved the mouse slightly to the left. Another reading of -35 would mean the user moved the mouse to the left faster. A subsequent reading of 100 would indicate that the user has snapped the mouse quickly to the right. This is a rough example, but illustrates how relative mouse movements are helpful.