feat(input): support callbacks in input manager#199
Merged
Divengerss merged 28 commits intomainfrom Apr 26, 2025
Merged
Conversation
…ngineSquared/EngineSquared into 195-support-callbacks-in-input-manager
Divengerss
reviewed
Apr 25, 2025
Comment on lines
+69
to
+93
| inputManager.RegisterCursorPosCallback([&](ES::Engine::Core &cbCore, double xpos, double ypos) { | ||
| auto &dragging = cbCore.GetResource<ES::Plugin::OpenGL::Utils::MouseDragging>(); | ||
| auto &camera = cbCore.GetResource<ES::Plugin::OpenGL::Resource::Camera>(); | ||
|
|
||
| if (ES::Plugin::Input::Utils::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_LEFT)) | ||
| { | ||
| float fractionChangeX = static_cast<float>(xpos - dragging.lastMousePos.x) / camera.size.x; | ||
| float fractionChangeY = static_cast<float>(dragging.lastMousePos.y - ypos) / camera.size.y; | ||
| camera.viewer.rotate(fractionChangeX, fractionChangeY); | ||
| } | ||
| else if (ES::Plugin::Input::Utils::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_MIDDLE)) | ||
| { | ||
| float fractionChangeY = static_cast<float>(dragging.lastMousePos.y - ypos) / camera.size.y; | ||
| camera.viewer.zoom(fractionChangeY); | ||
| } | ||
| else if (ES::Plugin::Input::Utils::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_RIGHT)) | ||
| { | ||
| float fractionChangeX = static_cast<float>(xpos - dragging.lastMousePos.x) / camera.size.x; | ||
| float fractionChangeY = static_cast<float>(dragging.lastMousePos.y - ypos) / camera.size.y; | ||
| camera.viewer.translate(-fractionChangeX, -fractionChangeY, true); | ||
| } | ||
|
|
||
| dragging.lastMousePos.x = xpos; | ||
| dragging.lastMousePos.y = ypos; | ||
| }); |
Contributor
There was a problem hiding this comment.
Perhaps you could use an array of function pointers or simply split each conditions into a single callback to reduce the lambda length?
Contributor
Author
There was a problem hiding this comment.
or maybe remove the two white spaces, but I'll try that :)
|
Divengerss
approved these changes
Apr 26, 2025
MasterLaplace
pushed a commit
that referenced
this pull request
Apr 29, 2025
Related to: - #195 Used in [RollingBall/use-new-input-plugin](https://github.com/EngineSquared/Rolling-Ball/tree/use-new-input-plugin) Notes: - Explaination about the glfw window user pointer [here](https://discourse.glfw.org/t/what-is-a-possible-use-of-glfwgetwindowuserpointer/1294), this can be useful later - The glfw joystick callback `glfwSetJoystickCallback` (which indicates when a controller (dis)connects) is not supported because of glfw's handling of user data pointers for joysticks (it is handled per joystick and not per window), but joystick operation can be handled through polling. - The `UpdateKey` system has been removed. Why would pressing "escape" always close the window ? --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Related to:
Used in RollingBall/use-new-input-plugin
Notes:
glfwSetJoystickCallback(which indicates when a controller (dis)connects) is not supported because of glfw's handling of user data pointers for joysticks (it is handled per joystick and not per window), but joystick operation can be handled through polling.UpdateKeysystem has been removed. Why would pressing "escape" always close the window ?