Add utility function to clamp a vector to a maximum magnitude.

user_profiles
Robert Adams 2013-01-17 14:44:54 -08:00
parent 8ee9daa121
commit caad1edabf
1 changed files with 12 additions and 0 deletions

View File

@ -299,6 +299,18 @@ namespace OpenSim.Framework
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)
public static bool InRange<T>(T x, T min, T max)
where T : IComparable<T>