From 142e00794097dfb78c4b758a2d39d26fae070092 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 13 Mar 2021 07:25:23 -0500 Subject: Created Interpolation abstraction This simplifies EffectSystem quite a bit, and will be useful in other classes. --- src/interpolation.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/interpolation.cpp (limited to 'src/interpolation.cpp') diff --git a/src/interpolation.cpp b/src/interpolation.cpp new file mode 100644 index 0000000..3c9bcf8 --- /dev/null +++ b/src/interpolation.cpp @@ -0,0 +1,19 @@ +#include "interpolation.h" + +void Interpolation::start(int length, double amount) { + start_ = progress_; + dest_ = amount; + length_ = length; + thus_ = 0; +} + +void Interpolation::tick(double dt) { + if (progress_ != dest_) { + thus_ += dt; + if (thus_ >= length_) { + thus_ = length_; + } + + progress_ = (dest_ - start_) / length_ * thus_ + start_; + } +} -- cgit 1.4.1