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

Incorrect work of look_at function #89578

Open
Terinyo opened this issue Mar 16, 2024 · 5 comments · May be fixed by #90257 or #91787
Open

Incorrect work of look_at function #89578

Terinyo opened this issue Mar 16, 2024 · 5 comments · May be fixed by #90257 or #91787

Comments

@Terinyo
Copy link

Terinyo commented Mar 16, 2024

Tested versions

  • Reproducible in: 4.2-dev4 and later including 4.3-dev5
  • Not reproducible in: 4.2-dev3 and earlier

System information

Windows 10 - Godot v4.2.1.stable - Compatibility

Issue description

The bug occurs when:

  • "Compatibility" rendering method is used
  • "display/window/stretch/scale_mode" is an integer
  • "display/window/stretch/mode" is viewport or canvas_item.
  • "display/window/size/viewport" size does not equal the window size.

The bug manifests as if the rotation angle is being calculated not from the position of the node, but from some point with an offset from the node. This offset correlates with the difference between the viewport size in the project settings and the window size.

Steps to reproduce

To reproduces the bug, you can use the look_at(get_global_mouse_position()) function in any node, such as Sprite2D.

Minimal reproduction project (MRP)

Bug.zip

@kleonc
Copy link
Member

kleonc commented Mar 16, 2024

The issue happens for display/window/stretch/scale_mode == integer when "desired" viewport height is greater than the window size. In such case the viewport size is forced to the desired size (integer scale of 1) so it ends up bigger than the window. However, such viewport ends up being render-wise attached to the window's bottom-left corner, while it seems all other calculations assume it's attached to the window's top-left corner. Hence the discrepancy equal to the height difference between the window/viewport sizes.

zguDuR3qgv N4VeNOQNFF 3mv50jPLeQ Qf8mR3h4oC

MRP changed to produce the above: Bug2.zip

Happens since the addition in #75784 (cc @Riteo).

@Riteo
Copy link
Contributor

Riteo commented Mar 16, 2024

Mhh that's interesting. The integer scaling PR does not explicitly change the way the surface is attached AFAIK, although since it allows the buffer to "overflow" out of the window it might have exposed this discrepancy with the way input is scaled.

Maybe the input is scaled relative to the viewport, so by breaking the window-viewport connection it looks weird. Not sure.

I'll take a look at this as soon as I have some time.

@Sauermann
Copy link
Contributor

To me, it is not clear, what the bug is exactly:

  1. The Viewport should not be attached to the bottom-left corner, but to the top-left; the input-coordinates are correct
  2. The Viewport position at the bottom-left corner is correct; input-coordinates need to be adjusted

@Riteo
Copy link
Contributor

Riteo commented Apr 4, 2024

@Sauermann given our coordinate system (X+ = left; Y+ = down), I'd argue that the correct case is the first.

@Sauermann
Copy link
Contributor

I agree, that the Viewport should be attached to the top-left corner.
I believe, that Window::_update_viewport_size would be a good place to start investigating this. Not sure, but perhaps then this leads to RenderingServer::viewport_attach_to_screen.

sofia285 added a commit to sofia285/godot that referenced this issue Apr 5, 2024
When using "Compatibility" rendering method, "scale_mode"
set an integer and viewport height greater than the window height,
viewport becomes misaligned with window leading to a rendering offset.
This causes the engine's mouse position to no longer match the real
mouse position. To fix this issue, the viewport, which was previously
render-wise attached to the window's bottom-left corner was changed to
be attached to the window's center.
sofia285 added a commit to sofia285/godot that referenced this issue Apr 5, 2024
When using "Compatibility" rendering method, "scale_mode" set an integer and viewport height greater than the window height, viewport becomes misaligned with window leading to a rendering offset.
This causes the engine's mouse position to no longer match the real mouse position.
To fix this issue, the viewport, which was previously render-wise attached to the window's bottom-left corner was changed to be attached to the window's center.
@sofia285 sofia285 linked a pull request Apr 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment