diff options
Diffstat (limited to 'src/interpolation.h')
| -rw-r--r-- | src/interpolation.h | 38 |
1 files changed, 38 insertions, 0 deletions
| diff --git a/src/interpolation.h b/src/interpolation.h new file mode 100644 index 0000000..68a6221 --- /dev/null +++ b/src/interpolation.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #ifndef INTERPOLATION_H_861230A8 | ||
| 2 | #define INTERPOLATION_H_861230A8 | ||
| 3 | |||
| 4 | class Interpolation { | ||
| 5 | public: | ||
| 6 | |||
| 7 | void start(int length) { | ||
| 8 | length_ = length; | ||
| 9 | thus_ = 0; | ||
| 10 | } | ||
| 11 | |||
| 12 | void tick(double dt) { | ||
| 13 | if (thus_ < length_) { | ||
| 14 | thus_ += dt; | ||
| 15 | if (thus_ >= length_) { | ||
| 16 | thus_ = length_; | ||
| 17 | } | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | // Info | ||
| 22 | |||
| 23 | double getProgress(double from, double to) const { | ||
| 24 | return (to - from) / length_ * thus_ + from; | ||
| 25 | } | ||
| 26 | |||
| 27 | bool isComplete() const { return thus_ == length_; } | ||
| 28 | |||
| 29 | private: | ||
| 30 | |||
| 31 | double progress_ = 0.0; | ||
| 32 | double dest_ = 0.0; | ||
| 33 | double start_ = 0.0; | ||
| 34 | double length_ = 0.0; | ||
| 35 | double thus_ = 0.0; | ||
| 36 | }; | ||
| 37 | |||
| 38 | #endif /* end of include guard: INTERPOLATION_H_861230A8 */ | ||
