Added InverseLerp to Math.h

Ported from C#
This commit is contained in:
intolerantape
2021-09-29 20:03:46 -07:00
parent eb928091b6
commit 81390cf860

View File

@@ -411,6 +411,15 @@ namespace Math
return (T)(a * (1.0f - alpha) + b * alpha);
}
// Calculates the linear parameter t that produces the interpolation value within the range [a, b].
template<class T, class U>
static T InverseLerp(const T& a, const T& b, const U& value)
{
if (a == b)
return (T)0;
return Saturate((value - a) / (b - a));
}
// Performs smooth (cubic Hermite) interpolation between 0 and 1
// @param amount Value between 0 and 1 indicating interpolation amount
static float SmoothStep(float amount)