Improve the Vector2 rotated code in C#

This commit is contained in:
Aaron Franke 2020-10-06 15:43:47 -04:00
parent 07112b92a8
commit bea7d61fd9
No known key found for this signature in database
GPG Key ID: 40A1750B977E56BF
1 changed files with 5 additions and 2 deletions

View File

@ -437,8 +437,11 @@ namespace Godot
/// <returns>The rotated vector.</returns>
public Vector2 Rotated(real_t phi)
{
real_t rads = Angle() + phi;
return new Vector2(Mathf.Cos(rads), Mathf.Sin(rads)) * Length();
real_t sine = Mathf.Sin(phi);
real_t cosi = Mathf.Cos(phi);
return new Vector2(
x * cosi - y * sine,
x * sine + y * cosi);
}
/// <summary>