Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectGUI : mouse position translator is not coupled to cam2d #654

Open
Nel-Fie opened this issue May 14, 2019 · 2 comments
Open

DirectGUI : mouse position translator is not coupled to cam2d #654

Nel-Fie opened this issue May 14, 2019 · 2 comments

Comments

@Nel-Fie
Copy link

Nel-Fie commented May 14, 2019

The system that translates the mouse's position to a location in aspect2d in order to interact with DirectGUI objects is not coupled with ShowBase.cam2d and its transformation.

As a result, modifying the camera or its lens node leads to a visually inverse transformation of the mouse position for detecting interactions with DirectGUI object.
E.g. if we create a DirectButton and leave it centered on aspect2d, then displace the camera with cam2d.set_pos(-.5,0,0), the button will not react with the mouse over its model. The user has to place the mouse on the center of the window, where the button would be without the camera's displacement, for the button to react.

Similar effects are observed when scaling or rotating the camera, or when modifying the lenses film size or film offset.

Here is an example file illustrating the effect, with additional interactions provided as commented code:
REPORT_cam2d_collision.zip

@rdb
Copy link
Member

rdb commented Jul 10, 2019

Hmm, this is a little trickier than I thought at first, because PGui (the GUI system underlying DirectGUI) relies on each item having a known position on screen. If we have to take the camera position into account, we can no longer know the position on screen for an item since the same GUI might be rendered by any number of cameras. So, when an item receives a mouse event, it has no way of knowing which camera. Worse than that, the camera may be associated with any number of (possibly overlapping) display regions on screen, so that's yet another way in which the mouse position can be misaligned with the position of the rendered button.

I think the only way of fixing this properly is to restructure Panda's code such that the mouse watcher is aware of the display regions on the window, and can therefore translate the mouse position appropriately based on the camera rendering to a region. Unfortunately, the input and rendering systems in Panda are separate components and not integrated to this degree. That said, we've been doing a lot of thinking lately about how we want to restructure Panda's windowing system, and such a change would fit in well with those plans.

For what it's worth, instead of moving the camera, moving a parent node of the GUI itself should still work fine.

@Nel-Fie
Copy link
Author

Nel-Fie commented Jul 11, 2019

@rdb Yea, I thought it'd probably be a harder thing to change than it seems.

If it's any reassurance, the reasons why I brought this up as a problem was mainly a matter of convenience; modifying the camera would have been a faster way to solve some issues with DirectGUI objects than modifying each of them instead. So, nothing unsolvable, just a bit more work.

Thank you very much for looking into it, though.

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

No branches or pull requests

3 participants