Merge branch 'patch-2' of git://github.com/honzapatCZ/FlaxEngine into honzapatCZ-patch-2
This commit is contained in:
@@ -832,7 +832,53 @@ namespace FlaxEngine
|
||||
value.Normalize();
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Makes sure that Length of the output vector is always below max and above 0.
|
||||
/// </summary>
|
||||
/// <param name="vector">Input Vector.</param>
|
||||
/// <param name="max">Max Length</param>
|
||||
public static Vector2 ClampLength(Vector2 vector, float max)
|
||||
{
|
||||
return ClampLength(vector, 0, max);
|
||||
}
|
||||
/// <summary>
|
||||
/// Makes sure that Length of the output vector is always below max and above min.
|
||||
/// </summary>
|
||||
/// <param name="vector">Input Vector.</param>
|
||||
/// <param name="min">Min Length</param>
|
||||
/// <param name="max">Max Length</param>
|
||||
public static Vector2 ClampLength(Vector2 vector, float min, float max)
|
||||
{
|
||||
ClampLength(ref vector, min, max, out Vector2 retVect);
|
||||
return retVect;
|
||||
}
|
||||
/// <summary>
|
||||
/// Makes sure that Length of the output vector is always below max and above min.
|
||||
/// </summary>
|
||||
/// <param name="vector">Input Vector.</param>
|
||||
/// <param name="min">Min Length</param>
|
||||
/// <param name="max">Max Length</param>
|
||||
/// <param name="retVect">The Return Vector</param>
|
||||
public static void ClampLength(ref Vector2 vector, float min, float max, out Vector2 retVect)
|
||||
{
|
||||
retVect.X = vector.X;
|
||||
retVect.Y = vector.Y;
|
||||
|
||||
float lenSq = retVect.LengthSquared;
|
||||
if (lenSq > max * max)
|
||||
{
|
||||
float scaleFactor = max / (float)Math.Sqrt(lenSq);
|
||||
retVect.X = retVect.X * scaleFactor;
|
||||
retVect.Y = retVect.Y * scaleFactor;
|
||||
}
|
||||
if (lenSq < min * min)
|
||||
{
|
||||
float scaleFactor = min / (float)Math.Sqrt(lenSq);
|
||||
retVect.X = retVect.X * scaleFactor;
|
||||
retVect.Y = retVect.Y * scaleFactor;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the vector with components rounded to the nearest integer.
|
||||
/// </summary>
|
||||
|
||||
@@ -991,7 +991,56 @@ namespace FlaxEngine
|
||||
value.Normalize();
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Makes sure that Length of the output vector is always below max and above 0.
|
||||
/// </summary>
|
||||
/// <param name="vector">Input Vector.</param>
|
||||
/// <param name="max">Max Length</param>
|
||||
public static Vector3 ClampLength(Vector3 vector, float max)
|
||||
{
|
||||
return ClampLength(vector, 0, max);
|
||||
}
|
||||
/// <summary>
|
||||
/// Makes sure that Length of the output vector is always below max and above min.
|
||||
/// </summary>
|
||||
/// <param name="vector">Input Vector.</param>
|
||||
/// <param name="min">Min Length</param>
|
||||
/// <param name="max">Max Length</param>
|
||||
public static Vector3 ClampLength(Vector3 vector, float min, float max)
|
||||
{
|
||||
ClampLength(ref vector, min, max, out Vector3 retVect);
|
||||
return retVect;
|
||||
}
|
||||
/// <summary>
|
||||
/// Makes sure that Length of the output vector is always below max and above min.
|
||||
/// </summary>
|
||||
/// <param name="vector">Input Vector.</param>
|
||||
/// <param name="min">Min Length</param>
|
||||
/// <param name="max">Max Length</param>
|
||||
/// <param name="retVect">The Return Vector</param>
|
||||
public static void ClampLength(ref Vector3 vector, float min, float max, out Vector3 retVect)
|
||||
{
|
||||
retVect.X = vector.X;
|
||||
retVect.Y = vector.Y;
|
||||
retVect.Z = vector.Z;
|
||||
|
||||
float lenSq = retVect.LengthSquared;
|
||||
if (lenSq > max * max)
|
||||
{
|
||||
float scaleFactor = max / (float)Math.Sqrt(lenSq);
|
||||
retVect.X = retVect.X * scaleFactor;
|
||||
retVect.Y = retVect.Y * scaleFactor;
|
||||
retVect.Z = retVect.Z * scaleFactor;
|
||||
}
|
||||
if (lenSq < min * min)
|
||||
{
|
||||
float scaleFactor = min / (float)Math.Sqrt(lenSq);
|
||||
retVect.X = retVect.X * scaleFactor;
|
||||
retVect.Y = retVect.Y * scaleFactor;
|
||||
retVect.Z = retVect.Z * scaleFactor;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Performs a linear interpolation between two vectors.
|
||||
/// </summary>
|
||||
|
||||
@@ -792,6 +792,58 @@ namespace FlaxEngine
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes sure that Length of the output vector is always below max and above 0.
|
||||
/// </summary>
|
||||
/// <param name="vector">Input Vector.</param>
|
||||
/// <param name="max">Max Length</param>
|
||||
public static Vector4 ClampLength(Vector4 vector, float max)
|
||||
{
|
||||
return ClampLength(vector, 0, max);
|
||||
}
|
||||
/// <summary>
|
||||
/// Makes sure that Length of the output vector is always below max and above min.
|
||||
/// </summary>
|
||||
/// <param name="vector">Input Vector.</param>
|
||||
/// <param name="min">Min Length</param>
|
||||
/// <param name="max">Max Length</param>
|
||||
public static Vector4 ClampLength(Vector4 vector, float min, float max)
|
||||
{
|
||||
ClampLength(ref vector, min, max, out Vector4 retVect);
|
||||
return retVect;
|
||||
}
|
||||
/// <summary>
|
||||
/// Makes sure that Length of the output vector is always below max and above min.
|
||||
/// </summary>
|
||||
/// <param name="vector">Input Vector.</param>
|
||||
/// <param name="min">Min Length</param>
|
||||
/// <param name="max">Max Length</param>
|
||||
/// <param name="retVect">The Return Vector</param>
|
||||
public static void ClampLength(ref Vector4 vector, float min, float max, out Vector4 retVect)
|
||||
{
|
||||
retVect.X = vector.X;
|
||||
retVect.Y = vector.Y;
|
||||
retVect.Z = vector.Z;
|
||||
retVect.W = vector.W;
|
||||
|
||||
float lenSq = retVect.LengthSquared;
|
||||
if (lenSq > max * max)
|
||||
{
|
||||
float scaleFactor = max / (float)Math.Sqrt(lenSq);
|
||||
retVect.X = retVect.X * scaleFactor;
|
||||
retVect.Y = retVect.Y * scaleFactor;
|
||||
retVect.Z = retVect.Z * scaleFactor;
|
||||
retVect.W = retVect.W * scaleFactor;
|
||||
}
|
||||
if (lenSq < min * min)
|
||||
{
|
||||
float scaleFactor = min / (float)Math.Sqrt(lenSq);
|
||||
retVect.X = retVect.X * scaleFactor;
|
||||
retVect.Y = retVect.Y * scaleFactor;
|
||||
retVect.Z = retVect.Z * scaleFactor;
|
||||
retVect.W = retVect.W * scaleFactor;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Performs a linear interpolation between two vectors.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user