2019-09-05 00:26:26 +08:00
|
|
|
#pragma once
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
/*
|
|
|
|
Usage:
|
2020-05-26 23:02:36 +08:00
|
|
|
When creating animation constructor takes one parameter - how long
|
2019-09-05 00:26:26 +08:00
|
|
|
should the animation take in seconds.
|
|
|
|
|
|
|
|
Call reset() when starting animation.
|
|
|
|
|
2020-05-26 23:02:36 +08:00
|
|
|
When rendering, call value() to get value from 0 to 1 - depending on animation
|
2019-09-05 00:26:26 +08:00
|
|
|
progress.
|
|
|
|
*/
|
2020-03-05 18:07:06 +08:00
|
|
|
class Animation
|
|
|
|
{
|
2019-09-05 00:26:26 +08:00
|
|
|
public:
|
2020-03-05 18:07:06 +08:00
|
|
|
enum AnimFunctions
|
|
|
|
{
|
|
|
|
LINEAR = 0,
|
|
|
|
EASE_OUT_EXPO
|
|
|
|
};
|
|
|
|
|
|
|
|
Animation(double duration = 1, double start = 0, double stop = 1);
|
|
|
|
void reset();
|
|
|
|
void reset(double duration);
|
|
|
|
void reset(double duration, double start, double stop);
|
|
|
|
double value(AnimFunctions apply_function) const;
|
|
|
|
bool done() const;
|
2019-09-05 00:26:26 +08:00
|
|
|
|
|
|
|
private:
|
2020-03-05 18:07:06 +08:00
|
|
|
static double apply_animation_function(double t, AnimFunctions apply_function);
|
|
|
|
std::chrono::high_resolution_clock::time_point start;
|
|
|
|
double start_value, end_value, duration;
|
2019-09-05 00:26:26 +08:00
|
|
|
};
|