Skip to content

Conversation

syszery
Copy link

@syszery syszery commented Oct 12, 2025

Objective

Implements scaffolding for a 2D pan camera controller.

Fixes #21468

Solution

  • Introduced a PanCam component with settings for panning, zooming, and rotation via keyboard input, following the design of the existing FreeCam.
  • Added a PanCamPlugin to register the controller system.
  • Implemented keyboard-based panning and rotation.

TODOs

  • Movement is currently world-axis aligned.
    • TODO: Consider movement relative to camera rotation.
  • Zooming support is scaffolded with config fields but not yet implemented.

Testing

Unfortunately, I was unable to fully test this implementation due to issues running graphical output with GPU acceleration under WSL.
As a result, zoom behavior and rotation effects remain TODOs, and the whole code could not be fully verified.

Once I resolve the GPU passthrough issues, I plan to complete and test the remaining features (with a more meaningful example).


I'm happy to hear any suggestions or feedback in the meantime!

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added this to the 0.18 milestone Oct 12, 2025
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Camera User-facing camera APIs and controllers. M-Needs-Release-Note Work that should be called out in the blog due to impact labels Oct 12, 2025
@alice-i-cecile alice-i-cecile self-requested a review October 12, 2025 21:27
Copy link
Contributor

It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note.

Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes.

@alice-i-cecile alice-i-cecile added the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label Oct 12, 2025
@syszery
Copy link
Author

syszery commented Oct 13, 2025

Hi @alice-i-cecile, thank you for your quick and helpful feedback! I really appreciate it and have applied all of your suggestions.

Outstanding Questions:

  • Zoom Behavior: The current implementation uses linear zoom, whereas, for example, the implementation in examples/2d/2d_viewport_to_world.rs uses a non-linear zoom approach. Would you prefer I switch to the non-linear zoom, or is the current linear approach fine?
  • Default Settings: Do you think the current default settings for the PanCam controller make sense, and do they align with what you'd expect, or should I adjust them?
  • Sprite Choice: The chosen sprite in this example is extremely simple. Would you prefer a more complex example to better showcase the functionality?
  • Should I move the example? For example, in the camera or 2d folder?

Additionally, you added the needs-release-note label. Since this is just another feature module added to the crate introduced in #20215, should I append the release note to yours?

@alice-i-cecile
Copy link
Member

Zoom Behavior: The current implementation uses linear zoom, whereas, for example, the implementation in examples/2d/2d_viewport_to_world.rs uses a non-linear zoom approach. Would you prefer I switch to the non-linear zoom, or is the current linear approach fine?

I don't have strong preferences here. Linear zoom is fine to start: we can change that later.

Default Settings: Do you think the current default settings for the PanCam controller make sense, and do they align with what you'd expect, or should I adjust them?

This is about what I would expect. I think that 2D games have a lot more scale variance than in 3D, so I expect more per-game tuning.

Sprite Choice: The chosen sprite in this example is extremely simple. Would you prefer a more complex example to better showcase the functionality?

This is great for this particular example.

Should I move the example? For example, in the camera or 2d folder?

Yes please! Definitely belongs in the camera folder.

Copy link
Contributor

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

@syszery
Copy link
Author

syszery commented Oct 13, 2025

Thanks for the feedback! I've incorporated all of it.
I hope it's okay that I modified your release notes and adjusted the title to better reflect the new feature.

@syszery syszery marked this pull request as ready for review October 13, 2025 18:55
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Almost there! Just a couple of release note nits then I'm happy with this.

@janis-bhm
Copy link
Contributor

This looks like quite a specialised camera to me, mostly because of the WASD movement. That's not a bad thing since it's exactly what the related issue asks for, and I think this definitely fills the hole of having a 2d camera available, but I expect it's very easy to run into a situation where you can't really benefit from it as soon as you want to change one aspect of the controls:
If I wanted to control the movement by dragging with the mouse, I would have to bind the movement keys to some dummy key-codes if I wanted to keep the zooming functionality.
Maybe the movement, zooming and scroll-zooming could be enabled and disabled separately?
This is true for the FreeCam controller as well, but that one feels more versatile..

I also think a camera like this would be neat for 3D/2.5D as well, which I believe this will currently not correctly zoom for.

@alice-i-cecile
Copy link
Member

If I wanted to control the movement by dragging with the mouse, I would have to bind the movement keys to some dummy key-codes if I wanted to keep the zooming functionality.

I think that having a few bools for toggling the different behavior would be nice :) Or we could swap to Options for the keybindings.

I agree that better e.g. mouse and gamepad support would be nice, but I really don't want to embed mediocre input mapping tools into this crate.

implements review feedback

Co-authored-by: Janis <[email protected]>
@syszery
Copy link
Author

syszery commented Oct 14, 2025

Thank you @alice-i-cecile and @janis-bhm for your feedback.

I will think about a way to incorporate the request for toggling and also fix the rotation bug.

Additionally, do you think it would make sense to split this into two components, similar to the approach suggested in #21456 for FreeCam?

@alice-i-cecile
Copy link
Member

Additionally, do you think it would make sense to split this into two components, similar to the approach suggested in #21456 for FreeCam?

Yes, let's do that now :)

@syszery
Copy link
Author

syszery commented Oct 14, 2025

Additionally, do you think it would make sense to split this into two components, similar to the approach suggested in #21456 for FreeCam?

Yes, let's do that now :)

Alright, if you agree with the suggestion in #21538 I'll update the PanCam, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Camera User-facing camera APIs and controllers. C-Feature A new feature, making something new possible M-Needs-Release-Note Work that should be called out in the blog due to impact S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a simple 2D camera controller

3 participants