diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2021-03-13 07:25:23 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2021-03-13 15:34:50 -0500 |
commit | 142e00794097dfb78c4b758a2d39d26fae070092 (patch) | |
tree | 72ca6327cf5d1658573ab112b397f2f28992062a /src/interpolation.cpp | |
parent | 3c505f6f7fa5d4fab7c2a2864a45c8f5d0b4d329 (diff) | |
download | tanetane-142e00794097dfb78c4b758a2d39d26fae070092.tar.gz tanetane-142e00794097dfb78c4b758a2d39d26fae070092.tar.bz2 tanetane-142e00794097dfb78c4b758a2d39d26fae070092.zip |
Created Interpolation abstraction
This simplifies EffectSystem quite a bit, and will be useful in other classes.
Diffstat (limited to 'src/interpolation.cpp')
-rw-r--r-- | src/interpolation.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
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 @@ | |||
1 | #include "interpolation.h" | ||
2 | |||
3 | void Interpolation::start(int length, double amount) { | ||
4 | start_ = progress_; | ||
5 | dest_ = amount; | ||
6 | length_ = length; | ||
7 | thus_ = 0; | ||
8 | } | ||
9 | |||
10 | void Interpolation::tick(double dt) { | ||
11 | if (progress_ != dest_) { | ||
12 | thus_ += dt; | ||
13 | if (thus_ >= length_) { | ||
14 | thus_ = length_; | ||
15 | } | ||
16 | |||
17 | progress_ = (dest_ - start_) / length_ * thus_ + start_; | ||
18 | } | ||
19 | } | ||