mirror of
https://github.com/opensim/opensim.git
synced 2026-08-01 06:06:06 +08:00
Add utility function to clamp a vector to a maximum magnitude.
This commit is contained in:
committed by
Justin Clark-Casey (justincc)
parent
09450448b0
commit
8ecf6ed08e
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user