Add Vector2.Normalized

This commit is contained in:
Ruan Lucas
2023-01-19 20:52:20 -04:00
parent 8669a291fb
commit d20bce9967
3 changed files with 22 additions and 2 deletions

View File

@@ -301,6 +301,19 @@ namespace FlaxEngine
}
}
/// <summary>
/// Gets the normalized vector. Returned vector has length equal 1.
/// </summary>
public Vector2 Normalized
{
get
{
Vector2 result = this;
result.Normalize();
return result;
}
}
/// <summary>
/// Creates an array containing the elements of the vector.
/// </summary>

View File

@@ -223,6 +223,15 @@ public:
return Vector2Base(-X, -Y);
}
/// <summary>
/// Calculates a normalized vector that has length equal to 1.
/// </summary>
Vector2Base GetNormalized() const
{
const T rcp = 1.0f / Length();
return Vector2Base(X * rcp, Y * rcp);
}
public:
/// <summary>
/// Performs vector normalization (scales vector up to unit length).

View File

@@ -17,8 +17,6 @@
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Serialization/JsonTools.h"
#include "Engine/Debug/DebugLog.h"
struct AxisEvaluation
{
float RawValue;