vectozavr-shooter/engine/animation/ATranslateToPoint.h

39 lines
1.0 KiB
C++

//
// Created by Иван Ильин on 29.01.2021.
//
#ifndef ENGINE_ATRANSLATETOPOINT_H
#define ENGINE_ATRANSLATETOPOINT_H
#include <utility>
#include "Animation.h"
#include "../Object.h"
class ATranslateToPoint final : public Animation {
private:
const std::weak_ptr<Object> _object;
const Vec3D _targetPoint;
Vec3D _translationValue;
bool _started = false;
void update() override {
if(_object.expired()) {
stop();
return;
}
if(!_started) {
_started = true;
_translationValue = _targetPoint - _object.lock()->position();
}
_object.lock()->translate(_translationValue * dprogress());
}
public:
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) {
}
};
#endif //INC_3DZAVR_ATRANSLATETOPOINT_H