2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 26.01.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_ANIMATION_H
|
|
|
|
#define ENGINE_ANIMATION_H
|
|
|
|
|
|
|
|
#include "Interpolation.h"
|
|
|
|
|
|
|
|
class Animation {
|
|
|
|
public:
|
2021-10-09 13:41:12 +03:00
|
|
|
enum class InterpolationType {
|
2021-10-28 16:58:02 +03:00
|
|
|
Linear,
|
|
|
|
Cos,
|
|
|
|
Bezier,
|
|
|
|
Bouncing
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
2021-10-09 13:41:12 +03:00
|
|
|
enum class LoopOut {
|
2021-09-13 15:53:43 +03:00
|
|
|
None,
|
|
|
|
Continue
|
|
|
|
};
|
2021-10-28 16:58:02 +03:00
|
|
|
private:
|
|
|
|
// normalized time (from 0 to 1)
|
|
|
|
double _time = 0;
|
2021-09-13 15:53:43 +03:00
|
|
|
double _dtime = 0;
|
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
bool _finished = false;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
double _progress = 0;
|
|
|
|
double _dprogress = 0;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-11-09 22:54:20 +03:00
|
|
|
// If '_waitForFinish' == true then we need to finish all animation before starting this one. (for example AWait)
|
|
|
|
// In addition new animations in particular animation list will be started only after finishing this animation.
|
2022-02-23 07:51:53 +03:00
|
|
|
const bool _waitForFinish;
|
2021-10-28 16:58:02 +03:00
|
|
|
const double _duration = 0;
|
|
|
|
const LoopOut _looped = LoopOut::None;
|
|
|
|
const InterpolationType _intType = InterpolationType::Bezier;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
// You should override this method for your particular animation
|
|
|
|
virtual void update() = 0;
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-11-09 22:54:20 +03:00
|
|
|
protected:
|
|
|
|
[[nodiscard]] double progress() const { return _progress; }
|
|
|
|
[[nodiscard]] double dprogress() const { return _dprogress; }
|
|
|
|
|
|
|
|
void stop() { _finished = true; }
|
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
public:
|
2022-02-23 07:51:53 +03:00
|
|
|
Animation(double duration, LoopOut looped, InterpolationType intType, bool waitForFinish = false);
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
virtual ~Animation() = default;
|
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
bool updateState();
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-11-09 22:54:20 +03:00
|
|
|
[[nodiscard]] bool isWaitingForFinish() const { return _waitForFinish; }
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //INC_3DZAVR_ANIMATION_H
|