shooter/engine/animation/Animation.h

61 lines
1.5 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-09-13 15:53:43 +03:00
linear,
cos,
bezier,
bouncing
};
2021-10-09 13:41:12 +03:00
enum class LoopOut {
2021-09-13 15:53:43 +03:00
None,
Cycle,
Continue
};
protected:
double _time = 0; // normalized time (from 0 to 1)
double _dtime = 0;
double _duration = 0;
bool _started = false;
2021-10-09 13:41:12 +03:00
LoopOut _looped = LoopOut::None;
// _p - animation progress
2021-09-13 15:53:43 +03:00
double _p = 0;
double _dp = 0;
2021-10-09 13:41:12 +03:00
InterpolationType _intType = InterpolationType::bezier;
std::unique_ptr<Vec2D> _bezier[2] = {std::make_unique<Vec2D>(Vec2D{0.8, 0}),
std::make_unique<Vec2D>(Vec2D{0.2, 1})};
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())
bool _waitFor = false;
bool updateState();
public:
Animation() = default;
virtual ~Animation() = default;
void setBezierPoints(const Vec2D& p1, const Vec2D& p2) {
_bezier[0] = std::make_unique<Vec2D>(p1);
_bezier[1] = std::make_unique<Vec2D>(p2);
}
2021-09-13 15:53:43 +03:00
[[nodiscard]] bool waitFor() const { return _waitFor; }
// You should override this method for your particular animation
2021-10-02 20:36:07 +03:00
virtual bool update() = 0;
2021-09-13 15:53:43 +03:00
};
#endif //INC_3DZAVR_ANIMATION_H