Added signed_angle_to for Vector3

This commit is contained in:
JestemStefan 2021-02-15 09:01:46 -05:00 committed by Aaron Franke
parent 7b2bad9571
commit 2c71ff1119
No known key found for this signature in database
GPG key ID: 40A1750B977E56BF
4 changed files with 40 additions and 3 deletions

View file

@ -111,10 +111,10 @@ namespace Godot
}
/// <summary>
/// Returns the minimum angle to the given vector, in radians.
/// Returns the unsigned minimum angle to the given vector, in radians.
/// </summary>
/// <param name="to">The other vector to compare this vector to.</param>
/// <returns>The angle between the two vectors, in radians.</returns>
/// <returns>The unsigned angle between the two vectors, in radians.</returns>
public real_t AngleTo(Vector3 to)
{
return Mathf.Atan2(Cross(to).Length(), Dot(to));
@ -468,6 +468,23 @@ namespace Godot
return v;
}
/// <summary>
/// Returns the signed angle to the given vector, in radians.
/// The sign of the angle is positive in a counter-clockwise
/// direction and negative in a clockwise direction when viewed
/// from the side specified by the `axis`.
/// </summary>
/// <param name="to">The other vector to compare this vector to.</param>
/// <param name="axis">The reference axis to use for the angle sign.</param>
/// <returns>The signed angle between the two vectors, in radians.</returns>
public 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;
}
/// <summary>
/// Returns the result of the spherical linear interpolation between
/// this vector and `to` by amount `weight`.