Skip to content

feat(input): support callbacks in input manager#199

Merged
Divengerss merged 28 commits intomainfrom
195-support-callbacks-in-input-manager
Apr 26, 2025
Merged

feat(input): support callbacks in input manager#199
Divengerss merged 28 commits intomainfrom
195-support-callbacks-in-input-manager

Conversation

@ripel2
Copy link
Contributor

@ripel2 ripel2 commented Apr 23, 2025

Related to:

Used in RollingBall/use-new-input-plugin

Notes:

  • Explaination about the glfw window user pointer here, 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 ?

@ripel2 ripel2 requested a review from a team April 23, 2025 07:41
@ripel2 ripel2 self-assigned this Apr 23, 2025
@ripel2 ripel2 linked an issue Apr 23, 2025 that may be closed by this pull request
@ripel2 ripel2 added the enhancement New feature or request label Apr 24, 2025
@ripel2 ripel2 marked this pull request as ready for review April 24, 2025 06:59
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;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could use an array of function pointers or simply split each conditions into a single callback to reduce the lambda length?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe remove the two white spaces, but I'll try that :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@sonarqubecloud
Copy link

@Divengerss Divengerss merged commit 9f2fbb0 into main Apr 26, 2025
13 checks passed
@Divengerss Divengerss deleted the 195-support-callbacks-in-input-manager branch April 26, 2025 04:45
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support callbacks in Input Manager

2 participants