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

Include the follow-viewport-transform into CanvasLayer transform calculations #59682

Merged

Conversation

Sauermann
Copy link
Contributor

@Sauermann Sauermann commented Mar 29, 2022

The follow-viewport-transform was missing from several calculations
resolve #35965

Update 2022-10-07: fix merge conflict

@Sauermann Sauermann requested review from a team as code owners March 29, 2022 23:53
@Chaosus Chaosus added this to the 4.0 milestone Mar 30, 2022
@Sauermann Sauermann changed the title Include the following-viewport-transform into CanvasLayer transform calculations Include the follow-viewport-transform into CanvasLayer transform calculations Mar 31, 2022
Copy link
Member

@kleonc kleonc left a comment

Choose a reason for hiding this comment

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

Added in docs descriptions are all inverted. Also probably other transform-getting methods omitted in this PR should be precised in a similar way as well (e.g. CanvasItem::get_global_transform: "Transforms from local coordinate system of this [CanvasItem] to the to the coordinate system of the canvas, this item is in.

Regarding the code changes they look good (besides the comments). Can't tell if there are any more places where CanvasLayer::get_final_transform() would need to be used now.

doc/classes/CanvasItem.xml Outdated Show resolved Hide resolved
doc/classes/CanvasItem.xml Outdated Show resolved Hide resolved
doc/classes/CanvasItem.xml Outdated Show resolved Hide resolved
doc/classes/CanvasLayer.xml Outdated Show resolved Hide resolved
Comment on lines +93 to +96
follow.scale(Vector2(get_follow_viewport_scale(), get_follow_viewport_scale()));
if (vp) {
follow = vp->get_canvas_transform() * follow;
}
Copy link
Member

Choose a reason for hiding this comment

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

Should follow scale be applied if vp is invalid? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a philosophical question. I would be happy to adjust the PR, acording to the preference of the maintainers.

scene/main/canvas_layer.cpp Outdated Show resolved Hide resolved
@Sauermann Sauermann force-pushed the fix-following-viewport-transform branch from fc02c8b to 3fe7b50 Compare September 13, 2022 09:55
@Sauermann
Copy link
Contributor Author

Added in docs descriptions are all inverted. Also probably other transform-getting methods omitted in this PR should be precised in a similar way as well (e.g. CanvasItem::get_global_transform: "Transforms from local coordinate system of this [CanvasItem] to the to the coordinate system of the canvas, this item is in.

That sounds like a good idea, however that should be done in a separate PR, since this is solely about the referenced issue.

Regarding the code changes they look good (besides the comments). Can't tell if there are any more places where CanvasLayer::get_final_transform() would need to be used now.

When I created this PR half a year ago, I investigated all places, where CanvasLayer::get_transform was used, so I am quite certain, that i found all relevant places. I can not be sure, if there were other changes made in the meantime that make would make additional changes necessary.

@Sauermann
Copy link
Contributor Author

When I created this PR half a year ago, I investigated all places, where CanvasLayer::get_transform was used, so I am quite certain, that i found all relevant places. I can not be sure, if there were other changes made in the meantime that make would make additional changes necessary.

Now I have double checked all locations, where CanvasLayer::get_transform is used and found that no additional adjustments are needed. This function apperars otherwise only in CanvasItemEditor where follow-viewport is not used, so it makes sense to keep using CanvasLayer::get_transform there.

Copy link
Member

@kleonc kleonc left a comment

Choose a reason for hiding this comment

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

LGTM.

Still not sure about that follow scale part which I've commented on above but also not sure if it's anyhow relevant.

Regarding the docs consistency for different transform obtaining methods: these descriptions can be improved/unified properly later, after other related bug fixes and after/alongside fixing the approprite tutorial (see: godotengine/godot-docs#6277). So docs in here are fine as they're correct.

And most importantly: big thanks @Sauermann! Great work on this and other related PRs/issues!

@jasonleeholm
Copy link

Is this fix in v3.5.2.rc1.official [f5f0543]? I'm still having a problem with a CollisionObject2D inside a CanvasLayer in reference to the camera position.

@Sauermann
Copy link
Contributor Author

No, at this time it is neither in 3.x nor in 4.

@jasonleeholm
Copy link

Is there a workaround to this? Clicking on things in a moving world is a major mechanic of my game. I tried moving the nodes inside the CanvasLayer with combinations of camera.get_global_position() and display/window/size/ with partial success, but it seems to cut off parts of the screen the mouse can be detected on.

@Sauermann
Copy link
Contributor Author

A workaround, I can think of is to replace the CanvasLayer by a Node2D and calculate the follow-viewport-transform yourself and apply it to the Node2D.

The following-viewport-transform was missing from several calculations
@Sauermann Sauermann force-pushed the fix-following-viewport-transform branch from 6bc0f0f to 2da2220 Compare December 18, 2022 21:45
@akien-mga akien-mga merged commit f29f3db into godotengine:master Dec 19, 2022
@akien-mga
Copy link
Member

Thanks!

@Sauermann Sauermann deleted the fix-following-viewport-transform branch December 19, 2022 15:34
@kleonc
Copy link
Member

kleonc commented Dec 19, 2022

@akien-mga #35965 which this PR fixes still needs to be fixed in 3.x, I guess it's fine to cherry-pick this PR as it only adds a new method?

@akien-mga akien-mga added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Dec 19, 2022
@akien-mga
Copy link
Member

Yeah I suppose so, if it works :)

@Sauermann
Copy link
Contributor Author

It would be prudent to check, if CanvasLayer::get_transform is used elsewhere in 3.x, where it should be replaced by CanvasLayer::get_final_transform.
I will have a look at this.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Dec 19, 2022
akien-mga pushed a commit that referenced this pull request Dec 22, 2022
…ulations

The follow-viewport-transform was missing from several calculations

3.x version of #59682
Deozaan pushed a commit to Deozaan/godot that referenced this pull request Jan 6, 2023
…ulations

The follow-viewport-transform was missing from several calculations

3.x version of godotengine#59682
Riordan-DC pushed a commit to Riordan-DC/godot that referenced this pull request Jan 23, 2023
…ulations

The follow-viewport-transform was missing from several calculations

3.x version of godotengine#59682
Riordan-DC pushed a commit to Riordan-DC/godot that referenced this pull request Jan 24, 2023
…ulations

The follow-viewport-transform was missing from several calculations

3.x version of godotengine#59682
akien-mga pushed a commit to akien-mga/godot that referenced this pull request Aug 18, 2023
…ulations

The follow-viewport-transform was missing from several calculations

3.x version of godotengine#59682

(cherry picked from commit 608cbd8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CanvasLayer's Follow Viewport doesn't translate inputs correctly
5 participants