Add utility function to clamp a vector to a maximum magnitude.
parent
09450448b0
commit
8ecf6ed08e
|
@ -299,6 +299,18 @@ namespace OpenSim.Framework
|
||||||
x;
|
x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clamp the maximum magnitude of a vector
|
||||||
|
public static Vector3 ClampV(Vector3 x, float max)
|
||||||
|
{
|
||||||
|
Vector3 ret = x;
|
||||||
|
float lenSq = x.LengthSquared();
|
||||||
|
if (lenSq > (max * max))
|
||||||
|
{
|
||||||
|
x = x / x.Length() * max;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
// Inclusive, within range test (true if equal to the endpoints)
|
// Inclusive, within range test (true if equal to the endpoints)
|
||||||
public static bool InRange<T>(T x, T min, T max)
|
public static bool InRange<T>(T x, T min, T max)
|
||||||
where T : IComparable<T>
|
where T : IComparable<T>
|
||||||
|
|
Loading…
Reference in New Issue