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

Changed the way the rotation of a curve at a point is evaluated to match PathFollow2D #78378

Merged

Conversation

0xafbf
Copy link
Contributor

@0xafbf 0xafbf commented Jun 17, 2023

Fixes #78361

@AThousandShips
Copy link
Member

This breaks PathFollow2D though, you need to update it as well, and the unit tests

@0xafbf
Copy link
Contributor Author

0xafbf commented Jun 17, 2023

merging this would also benefit this other PR I'm working on #77819

@0xafbf
Copy link
Contributor Author

0xafbf commented Jun 17, 2023

This breaks PathFollow2D though, you need to update it as well, and the unit tests

You're right, I'll do that now

@0xafbf 0xafbf requested a review from a team as a code owner June 17, 2023 20:08
@0xafbf 0xafbf marked this pull request as draft June 17, 2023 20:09
@0xafbf
Copy link
Contributor Author

0xafbf commented Jun 17, 2023

I fixed the PathFollow2D code, but I have to leave now, I'll come back later to update tests and docs.

@0xafbf 0xafbf force-pushed the curve-evaluate-correct-transform branch from e2beedc to 1eeb039 Compare June 18, 2023 05:17
@0xafbf 0xafbf marked this pull request as ready for review June 18, 2023 05:21
@0xafbf 0xafbf requested review from a team as code owners June 18, 2023 05:21
@capnm
Copy link
Contributor

capnm commented Jun 18, 2023

Well, you need to tell your kids to paint rockets horizontally. In any case, better than in mirrored shape :)
LGTM

@fire fire changed the title changed the way the rotation of a curve at a point is evaluated to match PathFollow2D Changed the way the rotation of a curve at a point is evaluated to match PathFollow2D Jun 18, 2023
@Calinou Calinou added this to the 4.1 milestone Jun 19, 2023
doc/classes/Curve2D.xml Outdated Show resolved Hide resolved
@Calinou
Copy link
Member

Calinou commented Jun 21, 2023

I tested this PR locally (rebased on top of master f2ce0b6) with the MRP. While it fixes the issue mentioned in #78361, It breaks rendering of "fish bones" in the editor:

This PR

image

master

image

This is likely resolved by rotating the fish bone rendering, but it does highlight the compatibility-breaking nature of this PR. As a result, I removed the cherry-pick label.

@capnm
Copy link
Contributor

capnm commented Jun 21, 2023

IIRC if I tested the initial commit the fish direction path was was ok.

@capnm
Copy link
Contributor

capnm commented Jun 22, 2023

This is likely resolved by rotating the fish bone rendering

Where is this actually painted? curve_editor_plugin is a non-functioning piece of code.

@AThousandShips
Copy link
Member

AThousandShips commented Jun 22, 2023

It's in Path2D directly, so scene/2d/path_2d.cpp:

godot/scene/2d/path_2d.cpp

Lines 141 to 159 in e74bf83

// Draw fish bones
{
PackedVector2Array v2p;
v2p.resize(3);
Vector2 *w = v2p.ptrw();
for (int i = 0; i < sample_count; i++) {
const Vector2 p = r[i].get_origin();
const Vector2 side = r[i].columns[0];
const Vector2 forward = r[i].columns[1];
// Fish Bone.
w[0] = p + (side - forward) * 5;
w[1] = p;
w[2] = p + (-side - forward) * 5;
draw_polyline(v2p, get_tree()->get_debug_paths_color(), line_width * 0.5, false);
}
}

Fix should be to swap:

const Vector2 side = r[i].columns[0];
const Vector2 forward = r[i].columns[1];

For:

const Vector2 side = r[i].columns[1];
const Vector2 forward = r[i].columns[0];

But haven't tested

@akien-mga akien-mga modified the milestones: 4.1, 4.2 Jun 22, 2023
@capnm
Copy link
Contributor

capnm commented Jun 22, 2023

Screenshot from 2023-06-22 19-13-45

@0xafbf needs squash and rebase.

@0xafbf 0xafbf force-pushed the curve-evaluate-correct-transform branch from 1eeb039 to bba2956 Compare June 24, 2023 01:24
@0xafbf 0xafbf force-pushed the curve-evaluate-correct-transform branch from bba2956 to c7830a5 Compare June 24, 2023 20:07
@0xafbf 0xafbf requested a review from AThousandShips June 24, 2023 20:09
@AThousandShips AThousandShips removed their request for review July 25, 2023 16:31
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! 👍

Changed the way the rotation of a curve at a point is evaluated to match PathFollow2D

To precise, this PR rather makes Curve2D::sample_baked_with_rotation1 return a Transform2D compliant with the Godot's 2D coordinate system (previously it was returning a transform with the basis axes swapped). This implicates it makes it compliant with all other things compliant with the Godot's 2D coordinate system, including e.g. PathFollow2D.

All usages of Curve2D::sample_baked_with_rotation within the codebase were changed appropriately (including more tests added).

The previous behavior was documented in #78362, so it can be considered a compatibility breaking change. I do consider this as a bugfix though (a buggy documented behavior is still a bug).
Sure there are probably some users using Curve2D::sample_baked_with_rotation and thus using some workarounds for the previous behavior. Their code would indeed break after merging this PR and thus they would need to get rid of the mentioned workarounds (shouldn't be a big deal).

So in case of merging this PR the change in Curve2D::sample_baked_with_rotation's behavior needs to be clearly stated out in the changelog (or some other relevant place).


@0xafbf Rebasing would be probably a good idea.

Footnotes

  1. The changed Curve2D::_sample_posture is used internally only by Curve2D::sample_baked_with_rotation.

doc/classes/Curve2D.xml Outdated Show resolved Hide resolved
@akien-mga akien-mga modified the milestones: 4.2, 4.3 Oct 27, 2023
@akien-mga
Copy link
Member

Since this changes behavior and might surprise users, I'd prefer waiting for 4.3 so we have enough dev snapshots to get this tested and users to report any unexpected breakage in their projects.

@0xafbf 0xafbf force-pushed the curve-evaluate-correct-transform branch from c7830a5 to acae382 Compare October 28, 2023 06:25
@0xafbf
Copy link
Contributor Author

0xafbf commented Oct 28, 2023

Rebased :) also took the colon from the docs example as requested.

Yeah, too bad this was approved a bit late for this release, but its great that its approved nonetheless 💯

Thanks for your efforts

@akien-mga akien-mga merged commit b88eddb into godotengine:master Jan 4, 2024
@akien-mga
Copy link
Member

Thanks!

@0xafbf 0xafbf deleted the curve-evaluate-correct-transform branch August 16, 2024 01:47
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.

sample_baked_with_rotation gives wrong transform
6 participants