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

Reimplement SignedAngleTo to be invariant along the rotation axis #103074

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
#103022 reimplement Vector3.SignedAngleTo
  • Loading branch information
markdchurchill committed Feb 26, 2025
commit 6dc6b1b679e8ebde54dc0822ef5425c37739d7a5
8 changes: 4 additions & 4 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,10 @@ public readonly Vector3 Sign()
/// <returns>The signed angle between the two vectors, in radians.</returns>
public readonly real_t SignedAngleTo(Vector3 to, Vector3 axis)
{
Vector3 crossTo = Cross(to);
real_t unsignedAngle = Mathf.Atan2(crossTo.Length(), Dot(to));
real_t sign = crossTo.Dot(axis);
return (sign < 0) ? -unsignedAngle : unsignedAngle;
var axisNorm = axis.Normalized();
var vY = axis.Cross(this);
var vX = vY.Cross(axisNorm);
return Mathf.Atan2(to.Dot(vY), to.Dot(vX));
}

/// <summary>
Expand Down
Loading