2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 29.01.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_ATRANSLATETOPOINT_H
|
|
|
|
#define ENGINE_ATRANSLATETOPOINT_H
|
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
#include "Animation.h"
|
2021-10-09 13:41:12 +03:00
|
|
|
#include "../Object.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-12 20:18:56 +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-10-31 11:39:08 +03:00
|
|
|
if (_object.expired()) {
|
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();
|
|
|
|
}
|
|
|
|
_object.lock()->translate(_translationValue * dprogress());
|
|
|
|
}
|
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
|