From e284a88da41f03da0140e80085cf1aaad8818ab0 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 30 Aug 2021 20:30:22 +0200 Subject: [PATCH] Optimize utilities in `AnimationUtils` --- Source/Engine/Animations/AnimationUtils.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Animations/AnimationUtils.h b/Source/Engine/Animations/AnimationUtils.h index 121eaee57..3bae847fc 100644 --- a/Source/Engine/Animations/AnimationUtils.h +++ b/Source/Engine/Animations/AnimationUtils.h @@ -89,10 +89,19 @@ namespace AnimationUtils result = (T)(a + t * (b - a)); } + template<> + FORCE_INLINE void Interpolate(const Vector2& a, const Vector2& b, float t, Vector2& result) + { + result.X = Math::Lerp(a.X, b.X, t); + result.Y = Math::Lerp(a.Y, b.Y, t); + } + template<> FORCE_INLINE void Interpolate(const Vector3& a, const Vector3& b, float t, Vector3& result) { - Vector3::Lerp(a, b, t, result); + result.X = Math::Lerp(a.X, b.X, t); + result.Y = Math::Lerp(a.Y, b.Y, t); + result.Y = Math::Lerp(a.Z, b.Z, t); } template<> @@ -191,7 +200,7 @@ namespace AnimationUtils const float uu = u * u; const float uuu = uu * u; const float ttt = tt * t; - result = uuu * p0 + 3 * uu * t * p1 + 3 * u * tt * p2 + ttt * p3; + result = uuu * p0 + (3 * uu * t) * p1 + (3 * u * tt) * p2 + ttt * p3; } template<> @@ -202,7 +211,7 @@ namespace AnimationUtils const float uu = u * u; const float uuu = uu * u; const float ttt = tt * t; - result = uuu * p0 + 3 * uu * t * p1 + 3 * u * tt * p2 + ttt * p3; + result = uuu * p0 + (3 * uu * t) * p1 + (3 * u * tt) * p2 + ttt * p3; } template<>