shooter/engine/animation/ATranslateToPoint.h

42 lines
1.1 KiB
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 29.01.2021.
//
#ifndef ENGINE_ATRANSLATETOPOINT_H
#define ENGINE_ATRANSLATETOPOINT_H
#include "Animation.h"
2021-10-09 13:41:12 +03:00
#include "../Object.h"
2021-09-13 15:53:43 +03:00
class ATranslateToPoint final : public Animation {
2021-09-13 15:53:43 +03:00
private:
2021-10-28 16:58:02 +03:00
const std::weak_ptr<Object> _object;
const Vec3D _targetPoint;
Vec3D _translationValue;
2021-10-02 20:36:07 +03:00
2021-10-28 16:58:02 +03:00
bool _started = false;
2021-09-13 15:53:43 +03:00
2021-10-28 16:58:02 +03:00
void update() override {
2021-11-09 22:54:20 +03:00
auto obj = _object.lock();
if (obj == nullptr) {
2021-10-28 16:58:02 +03:00
stop();
return;
2021-09-13 15:53:43 +03:00
}
2021-10-31 11:39:08 +03:00
if (!_started) {
2021-10-28 16:58:02 +03:00
_started = true;
_translationValue = _targetPoint - _object.lock()->position();
}
2021-11-09 22:54:20 +03:00
obj->translate(_translationValue * dprogress());
2021-10-28 16:58:02 +03:00
}
2021-10-31 11:39:08 +03:00
2021-10-28 16:58:02 +03:00
public:
2021-10-31 11:39:08 +03:00
ATranslateToPoint(std::weak_ptr<Object> object, const Vec3D &p, double duration = 1, LoopOut looped = LoopOut::None,
InterpolationType interpolationType = InterpolationType::Bezier)
: Animation(duration, looped, interpolationType), _targetPoint(p), _object(object) {
2021-09-13 15:53:43 +03:00
}
};
#endif //INC_3DZAVR_ATRANSLATETOPOINT_H