shooter/engine/animation/Animation.h

61 lines
1.4 KiB
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 26.01.2021.
//
#ifndef ENGINE_ANIMATION_H
#define ENGINE_ANIMATION_H
#include "../utils/Time.h"
#include "../Triangle.h"
#include "Interpolation.h"
#include "../Vec2D.h"
2021-09-13 15:53:43 +03:00
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
// If '_waitFor' == true then we need to finish all animation before starting this one. (for example for a_wait() or a_scale())
2021-10-28 16:58:02 +03:00
const bool _waitFor = false;
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-09-13 15:53:43 +03:00
public:
2021-10-28 16:58:02 +03:00
Animation(double duration, LoopOut looped, InterpolationType intType, bool _waitFor = false);
2021-10-31 11:39:08 +03:00
2021-09-13 15:53:43 +03:00
virtual ~Animation() = default;
[[nodiscard]] bool waitFor() const { return _waitFor; }
2021-10-28 16:58:02 +03:00
bool updateState();
2021-09-13 15:53:43 +03:00
2021-10-28 16:58:02 +03:00
[[nodiscard]] double progress() const { return _progress; }
2021-10-31 11:39:08 +03:00
2021-10-28 16:58:02 +03:00
[[nodiscard]] double dprogress() const { return _dprogress; }
2021-10-31 11:39:08 +03:00
void stop() { _finished = true; }
2021-09-13 15:53:43 +03:00
};
#endif //INC_3DZAVR_ANIMATION_H