Add initial support for mouse and gamepad input#29
Add initial support for mouse and gamepad input#29Nostritius merged 24 commits intoOpenAWE-Project:masterfrom
Conversation
f7ac940 to
fdc2a7d
Compare
|
Noticed something weird: I cannot use my laptop's trackpad together with the keyboard - looks like mouse movement events get suppresed. External mouse works okay though. Edit: after some research, it appears that this behaviour comes from OS settings and has nothing to do with the engine itself. |
86bccab to
57191ef
Compare
Use vertical mouse scroll for Y movement to test 1D mouse bindings
16b768a to
4c9c278
Compare
There was a problem hiding this comment.
Here is my first review for this one. Apart from the things, already pointed out, I would like to see one Controlled freecamera instead of two separate, ideally in a modular way, so you have methods like "setMouseInputDisabled".
I have not yet tested, the functionality of the camera in practice, I will probably follow up with comments when I have done that.
|
|
||
| typedef std::variant< | ||
| AxisEvent<float>, | ||
| AxisEvent<double>, |
There was a problem hiding this comment.
Did you use this one somewhere? If not, it should be deleted
That removes getMouseLastPosiiton() as a public method since its used only within Window class now. Also renames lock/unlock mouse functions for clarity.
InputManager is used to expand upon GLFW callbacks, adding button hold state and some stub code for future gamepad support
|
Commit a520a7e changes the keyboard layout: |
src/platform/gamepadconversion.cpp
Outdated
| Events::Gamepad2DAxis convertGamepadStick(int stick) { | ||
| switch (stick) { | ||
| case 0: return Events::Gamepad2DAxis::kGamepadAxisLeft; | ||
| case 1: return Events::Gamepad2DAxis::kGamepadAxisRight; |
There was a problem hiding this comment.
Could you use the glfw nacros in these functions?
There was a problem hiding this comment.
GLFW does not distinguish gamepad sticks and triggers by default - it treats them all as 1D axes, so library macros are weird to use here (like GLFW_GAMEPAD_AXIS_LEFT_X for the whole left stick?). I can create an enum for them, though, and switch to using macros for triggers axes.
src/game.cpp
Outdated
| EventMan.setActionCallback({ kLockMouse }, [&](Events::Event event){_window->hideMouseCursor();}); | ||
| EventMan.setActionCallback({ kUnlockMouse }, [&](Events::Event event){_window->showMouseCursor();}); | ||
| EventMan.addBinding(kLockMouse, Events::kMouseLeft); | ||
| EventMan.addBinding(kUnlockMouse, Events::kKeyEscape); |
There was a problem hiding this comment.
If you want to keep the lock/unlock mouse mechanic on the layer of the game class, it would probably be simpler to jus put this into the callback. And please define a unified key combination to lock the camera, one which is probably never used in the game, for example alt + l.
- Formatting and typos - Add useRawMouseMotion() - Use GLFW macros for gamepad axes
4d2594f to
94d1d75
Compare
Nostritius
left a comment
There was a problem hiding this comment.
I tested the new freecamera today and I like it so far. I think it would be beneficial to have a README hint, which keys control the camera how.
As I have written in the last Review , I'm not really happy with adding a new event type where we have to do all the injecting by ourselves which adds a lot of code. So I would prefer a solution which would be able to work without this hold event. As I have written, would the utilizing of the update function help?
src/platform/window.cpp
Outdated
| glfwSetFramebufferSizeCallback(_window, &Window::callbackFramebufferSize); | ||
| GamepadMan.setGamepadButtonCallback(_window, &Window::callbackGamepadButton); | ||
| GamepadMan.setGamepadTriggerCallback(_window, &Window::callbackGamepadTrigger); | ||
| GamepadMan.setGamepadStickCallback(_window, &Window::callbackGamepadStick); |
There was a problem hiding this comment.
The Gamepad code should stay independent of the window, since the gamepads are in no way associated with it. The gamepad callbacks should be initialized in the game class directly over the GamepadMan singleton.
src/events/event.h
Outdated
| */ | ||
| enum KeyState { | ||
| kPress, | ||
| kHold, |
There was a problem hiding this comment.
I see your point especially with the mouse stuff. Would it be an option if you rather implement the update(float delta) method?
FreeCamera now has flags for whether to clear direction/rotation after update(delta) or not. This allows to handle both keyboard and mouse/gamepad events without KeyManager. Also includes some tweaks according to the PR's feedback.
Removes hold state from both event.h and GamepadManager, since keyboard keys don't have hold state now.
CI failed because, apparently, fmt cannot format an Enum (see prev. two commits). Don't know why it started to fail now (code's been there for a while), but a simple conversion to an int should hopefully suffice.
Nostritius
left a comment
There was a problem hiding this comment.
The code crashes at my laptop when executed in the gamepad manager. furthermore I have some additional comments,
src/platform/gamepadman.h
Outdated
| void pollGamepadEvents(); | ||
| void setGamepadButtonCallback(GLFWwindow *window, InputGamepadButtonCallback function); | ||
| void setGamepadTriggerCallback(GLFWwindow *window, InputGamepadTriggerCallback function); | ||
| void setGamepadStickCallback(GLFWwindow *window, InputGamepadStickCallback function); |
There was a problem hiding this comment.
The gamepad callbacks do not need a reference to the GLFWwindow
src/platform/window.cpp
Outdated
| w->_mouseButtonCallback(button, action, mods); | ||
| } | ||
|
|
||
| void Window::callbackGamepadButton(GLFWwindow *window, int button, int action) { |
There was a problem hiding this comment.
I think you misunderstood me here, the gamepad callbacks should be moved into the GamepadMan and the Window should have absolutely nothing to do with the gamepads.
Also adds debug messages for gamepad connection
Since both movement and camera rotation should have worked with them from the beginning in this case
Nostritius
left a comment
There was a problem hiding this comment.
I have left three comments for the code. One thing I have to add, it would be nice if the locking of the mouse cursor is off by default, just to prevent someone inexperienced being caught in the window.
| } | ||
| } | ||
|
|
||
| void EventManager::injectMouse1DAxisInput(Events::Mouse1DAxis axis, float position, float delta) { |
There was a problem hiding this comment.
From what I see in the current state, you are not using the 1D Axis inputs. Do we need them in the future? If not, I would prefer to remove them for simplifying the whole interface
There was a problem hiding this comment.
Actually, they are used for separating mouse scroll inputs (that are 2D by default) into horizontal and vertical components. Here is a snippet for callback assignment from game.cpp:
_window->setMouseScrollCallback([&](glm::vec2 absolute, glm::vec2 delta){
EventMan.injectMouse1DAxisInput(Events::kMouseScrollHorizontal, absolute.x, delta.x);
EventMan.injectMouse1DAxisInput(Events::kMouseScrollVertical, absolute.y, delta.y);
});| - [TG] to increase/decrease movement speed | ||
| # Camera | ||
| - [←→↑↓] to look left/right/up/down | ||
| - [YH] to increase/decrease camera speed |
There was a problem hiding this comment.
I assume you use a QWERTY keyboard? Since I am using a german QWERTZ keyboard this combination is a little bit counter intuitive for me. Maybe you have an idea how to handle this better, if not we can leave it this way for now.
There was a problem hiding this comment.
Yes, when I'm referring to keys here, I imply QWERTY layout. Also not sure yet of what can be done here for now.
Also makes mouse lock disabled by default
|
Merged, Thanks :) |
|
If you are interested, I have recently added support for moving Alan with very basic animations. If you want you could try to implement his Orbital Cam. |
Adds support for capturing and adding bindings to mouse movement and button clicks. Also adds an option to lock mouse inside game's window. Includes a modified ControlledFreeCamera that uses mouse movement for camera rotation.
Related to #13