vectozavr-shooter/engine/animation/Animation.h

59 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"
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 _timeOld = 0;
double _endAnimationPoint = 0;
double _startAnimationPoint = 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;
2021-09-13 15:53:43 +03:00
Point4D _bezier[2] = {Point4D{0.8, 0}, Point4D{0.2, 1}};
// 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 setBezierParams(const Point4D& p1, const Point4D& p2) { _bezier[0] = p1; _bezier[1] = p2; }
[[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