Added linear interpolation (Lerp) to math module

Former-commit-id: 5920e21f25d42701a1895734eca492fdf5351669
This commit is contained in:
Lynix
2012-10-08 14:45:29 +02:00
parent 737f2a70bd
commit cfd54b859d
12 changed files with 141 additions and 49 deletions

View File

@@ -195,6 +195,26 @@ T NzRect<T>::operator[](unsigned int i) const
return *(&x+i);
}
template<typename T>
NzRect<T> NzRect<T>::Lerp(const NzRect& from, const NzRect& to, T interpolation)
{
#ifdef NAZARA_DEBUG
if (interpolation < F(0.0) || interpolation > F(1.0))
{
NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')');
return Zero();
}
#endif
NzRect rect;
rect.x = NzLerp(from.x, to.x, interpolation);
rect.y = NzLerp(from.y, to.y, interpolation);
rect.width = NzLerp(from.width, to.width, interpolation);
rect.height = NzLerp(from.height, to.height, interpolation);
return rect;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzRect<T>& rect)
{