Browse Source

Math: hint that lerpInverted() can be used for rane mapping.

pull/342/head
Vladimír Vondruš 7 years ago
parent
commit
2a9f4a1fed
  1. 12
      doc/snippets/MagnumMath.cpp
  2. 10
      src/Magnum/Math/Functions.h

12
doc/snippets/MagnumMath.cpp

@ -912,6 +912,18 @@ Math::min(Math::max(value, min), max)
;
}
{
Float a{};
/* [lerpInverted-map] */
Deg b = Math::lerp(5.0_degf, 15.0_degf,
Math::lerpInverted(-1.0f, 1.0f, a));
Deg bClamped = Math::lerp(5.0_degf, 15.0_degf, Math::clamp(
Math::lerpInverted(-1.0f, 1.0f, a), 0.0f, 1.0f));
/* [lerpInverted-map] */
static_cast<void>(b);
static_cast<void>(bClamped);
}
{
/* [Half-usage] */
using namespace Math::Literals;

10
src/Magnum/Math/Functions.h

@ -437,7 +437,15 @@ template<std::size_t size> inline BoolVector<size> lerp(const BoolVector<size>&
Returns interpolation phase *t*: @f[
t = \frac{\boldsymbol{v_{LERP}} - \boldsymbol{v_A}}{\boldsymbol{v_B} - \boldsymbol{v_A}}
@f]
@see @ref lerp(), @ref select()
Useful in combination with @ref lerp() for mapping values from one range to
another --- for example, the following snippet maps `a` from a range
@f$ [ -1; +1 ] @f$ to a range @f$ [ 5\degree; 15\degree ] @f$; the second
expression combines that with @ref clamp() to ensure the value is in bounds:
@snippet MagnumMath.cpp lerpInverted-map
@see @ref select()
*/
template<class T> inline UnderlyingTypeOf<typename std::enable_if<IsScalar<T>::value, T>::type> lerpInverted(T a, T b, T lerp) {
return (lerp - a)/(b - a);

Loading…
Cancel
Save