Browse Source

Math: Vector::lerp() can take `t` of arbitrary type.

Usable when interpolating e.g. colors in denormalized integral form, as
`t` could be only `0` or `1` in that case, which is pretty unusable.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
b7b955289a
  1. 5
      src/Math/Test/VectorTest.cpp
  2. 6
      src/Math/Vector.h

5
src/Math/Test/VectorTest.cpp

@ -160,6 +160,11 @@ void VectorTest::lerp() {
Vector3 b(3.0f, -2.0f, 11.0f);
CORRADE_COMPARE(Vector3::lerp(a, b, 0.25f), Vector3(0.0f, 1.0f, 5.0f));
typedef Math::Vector<3, std::int32_t> Vector3ub;
Vector3ub c(0, 128, 64);
Vector3ub d(16, 0, 32);
CORRADE_COMPARE(Vector3ub::lerp(c, d, 0.25f), Vector3ub(4, 96, 56));
}
void VectorTest::debug() {

6
src/Math/Vector.h

@ -79,8 +79,8 @@ template<std::size_t size, class T> class Vector: public RectangularMatrix<1, si
* @todo http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
* (when SIMD is in place)
*/
inline static Vector<size, T> lerp(const Vector<size, T>& a, const Vector<size, T>& b, T t) {
return (T(1) - t)*a + t*b;
template<class U> inline static Vector<size, T> lerp(const Vector<size, T>& a, const Vector<size, T>& b, U t) {
return (U(1) - t)*a + t*b;
}
/** @brief Default constructor */
@ -358,7 +358,7 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit
template<class U> inline constexpr static Type<T> from(const Math::Vector<size, U>& other) { \
return Math::Vector<size, T>::from(other); \
} \
inline static const Type<T> lerp(const Math::Vector<size, T>& a, const Math::Vector<size, T>& b, T t) { \
template<class U> inline static const Type<T> lerp(const Math::Vector<size, T>& a, const Math::Vector<size, T>& b, U t) { \
return Math::Vector<size, T>::lerp(a, b, t); \
} \
\

Loading…
Cancel
Save