diff --git a/Source/Engine/Core/Math/Math.h b/Source/Engine/Core/Math/Math.h index ee3b34b9a..e9bd6e58f 100644 --- a/Source/Engine/Core/Math/Math.h +++ b/Source/Engine/Core/Math/Math.h @@ -13,6 +13,7 @@ #define PI_OVER_2 1.57079632679f #define PI_OVER_4 0.78539816339f #define PI_HALF PI_OVER_2 +#define GOLDEN_RATIO 1.6180339887f // The value for which all absolute numbers smaller than are considered equal to zero. #define ZeroTolerance 1e-6f @@ -648,9 +649,9 @@ namespace Math { float delta = a2 - a1; if (delta > PI) - delta = delta - PI * 2.0f; + delta = delta - TWO_PI; else if (delta < -PI) - delta = delta + PI * 2.0f; + delta = delta + TWO_PI; return delta; } @@ -658,9 +659,9 @@ namespace Math static float UnwindRadians(float a) { while (a > PI) - a -= (float)PI * 2.0f; + a -= TWO_PI; while (a < -PI) - a += (float)PI * 2.0f; + a += TWO_PI; return a; } diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 2674b30e6..241865c21 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1245,6 +1245,17 @@ namespace FlaxEngine return new Vector3(Math.Abs(v.X), Math.Abs(v.Y), Math.Abs(v.Z)); } + /// + /// Given two points, will return the unit direction. + /// + /// The start position. + /// The target position. + /// The unit direction from a to b. + public static Vector3 UnitDirection(Vector3 a, Vector3 b) + { + return (b - a).Normalized; + } + /// /// Projects a vector onto another vector. /// diff --git a/Source/Engine/Core/Math/Vector3.h b/Source/Engine/Core/Math/Vector3.h index 1f4792e31..5d9c9b7b4 100644 --- a/Source/Engine/Core/Math/Vector3.h +++ b/Source/Engine/Core/Math/Vector3.h @@ -901,6 +901,17 @@ public: /// The third triangle vertex. /// The triangle area. static float TriangleArea(const Vector3& v0, const Vector3& v1, const Vector3& v2); + + /// + /// Given two points, will return the unit direction. + /// + /// The start position. + /// The target position. + /// The unit direction from a to b. + static Vector3 UnitDirection(const Vector3& a, const Vector3& b) + { + return (b - a).GetNormalized(); + } }; inline Vector3 operator+(float a, const Vector3& b)