Skip to content

Conversation

Korijn
Copy link
Collaborator

@Korijn Korijn commented Mar 1, 2024

Closes #664

Adds a basic Input class with an example demonstrating how to implement simple FPS controls with it

fps_input

@kushalkolar
Copy link
Contributor

kushalkolar commented Mar 1, 2024

You guys are epic and so fast! With pointer events I can already see how it can simplify our drag PR ! I didn't realize we can just do things like that and keep performance.

@Korijn
Copy link
Collaborator Author

Korijn commented Mar 1, 2024

I'm working to at least include all the basic functionality in this PR with pointer state as well.

@almarklein Eventually we could consider rebasing the controllers on the input class. The main benefit is that you can isolate most of the event handling logic in the input class, and support configurable key maps there as well, so that controller's don't need to be aware of all of that stuff.

@Korijn
Copy link
Collaborator Author

Korijn commented Mar 1, 2024

This is now working. Could one of you give it a try locally and review?

@almarklein I was thinking to move the FPS controls into a controller class, but it will have a different architecture and design than the other controllers. I also don't want to refactor all of them. Do you have any ideas on how to deal with that? I was thinking about creating another subpackage pygfx.input...


@property
def delta(self):
"""Returns the time in seconds since the last frame."""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is actually the time the previous frame took to render 🤦‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

It's likely even longer than the time it took to render the frame (fps limiting).

Would we want to perhaps smooth this value, to avoid variations in it from affecting the way the interaction feels?

Copy link
Collaborator Author

@Korijn Korijn Mar 5, 2024

Choose a reason for hiding this comment

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

After thinking about this some more, I think it's correctly implemented:

  • For every after_flush event, there is only 1 call to perf_counter(), so we don't "lose time"
  • The delta should have the same value for all update handlers running in a given frame
  • The delta should be equal to the time since the previous point in time where update handlers were executed, which is usually right after after_flush

Also see https://docs.unity3d.com/ScriptReference/Time-deltaTime.html

@almarklein
Copy link
Member

Tried it and it works really nice! Also feels immersive because the mouse is grabbed.

I was thinking about creating another subpackage pygfx.input...

Yes, I think that makes the most sense. I think controllers are quite different because they closely relate to cameras. Perhaps we can (later) refactor the controllers to make use of the input class(es) to make them simpler. I think wrapping makes more sense than subclassing here, what do you think?

@kushalkolar
Copy link
Contributor

The example works well for me along with small modifications to try out various things (moving the torus and the view, sensitivities, etc.) 😄

@Korijn
Copy link
Collaborator Author

Korijn commented Mar 5, 2024

  • Added escape/mouse click handlers to release/capture the mouse
  • Added acceleration to make movement smoother

The example is "done" I think, next step is reorganizing the code into a pygfx.inputs folder.

First person shooter controls with GLFW GUI
=========================================

Example showing how to use the Input class to implement FPS controls.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Explain the controls here in the docstring

@Korijn
Copy link
Collaborator Author

Korijn commented Mar 7, 2024

The more I think about this the more I feel like it should be a part of wgpu-py's GUI layer... I will see what that feels like by trying it out on a branch.

@kushalkolar
Copy link
Contributor

I'll give this a shot in wgpu if you can hint me at where it would go!

@Korijn
Copy link
Collaborator Author

Korijn commented May 16, 2024

I'll give this a shot in wgpu if you can hint me at where it would go!

wgpu/gui/input.py :)

@almarklein almarklein mentioned this pull request Jul 19, 2024
10 tasks
@almarklein
Copy link
Member

Closing. We will get back to this when we work on #495. We see two approaches, but we'll have to see at the time:

  • The animation event has info on what buttons are down.
  • The canvas has API to check what buttons are down.

@almarklein almarklein closed this Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Input state object
3 participants