소스 검색

Merge pull request #42606 from aaronfranke/cs-vec2-rotated

Improve the Vector2 rotated code in C#
Rémi Verschelde 5 년 전
부모
커밋
e93af13959
1개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 2
      modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs

+ 5 - 2
modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs

@@ -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>