From 6305261270b6e2dcada76dad057b1cd953e4ac4d Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 17 May 2012 14:17:42 +1000 Subject: [PATCH] Add trun, cubic, and quintic lerp methods --- lerp.cpp | 18 ++++++++++++++++++ lerp.hpp | 7 +++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lerp.cpp b/lerp.cpp index a8e89b56..d50b1de8 100644 --- a/lerp.cpp +++ b/lerp.cpp @@ -31,6 +31,10 @@ lerp::sigmoid (double val) { } +double lerp::trunc (double a, double, double) + { return a; } + + double lerp::linear (double a, double b, double weight) { CHECK (weight >= 0 && weight <= 1.0); @@ -47,3 +51,17 @@ lerp::cosine (double a, double b, double weight) { return a * (1.0 - f) + b * f; } + +double +lerp::cubic (double a, double b, double weight) { + CHECK (weight >= 0.0 && weight <= 1.0); + double t = weight * weight * (3.0 - 2.0 * weight); + return a * (1.0 - t) + b * t; +} + + +double +lerp::quintic (double a, double b, double weight) { + double t = weight * weight * weight * (weight * (weight * 6.0 - 15.0) + 10.0); + return a * (1.0 - t) + b * t; +} diff --git a/lerp.hpp b/lerp.hpp index 7bfd2a3e..88384874 100644 --- a/lerp.hpp +++ b/lerp.hpp @@ -23,8 +23,11 @@ namespace lerp { double sigmoid (double val); - double linear (double a, double b, double weight); - double cosine (double a, double b, double weight); + double linear (double a, double b, double weight); + double cosine (double a, double b, double weight); + double cubic (double a, double b, double weight); + double quintic (double a, double b, double weight); + double trunc (double a, double b, double weight); } #endif