2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 29.01.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_ASCALE_H
|
|
|
|
#define ENGINE_ASCALE_H
|
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
#include "Animation.h"
|
2021-10-28 16:58:02 +03:00
|
|
|
#include "../physics/RigidBody.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
class AScale final : public Animation {
|
2021-09-13 15:53:43 +03:00
|
|
|
private:
|
2021-10-28 16:58:02 +03:00
|
|
|
const std::weak_ptr<RigidBody> _object;
|
|
|
|
const Vec3D _scalingValue;
|
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
|
|
|
|
|
|
|
std::vector<Triangle> newTriangles;
|
2021-10-31 11:39:08 +03:00
|
|
|
for (auto &t : _object->triangles()) {
|
|
|
|
newTriangles.emplace_back(
|
|
|
|
t * Matrix4x4::Scale(Vec3D{1, 1, 1} + (_scalingValue - Vec3D{1, 1, 1}) * progress()));
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
2021-10-28 16:58:02 +03:00
|
|
|
_object.lock()->setTriangles(newTriangles);
|
2021-09-13 15:53:43 +03:00
|
|
|
return updateState();
|
|
|
|
}
|
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
|
|
|
AScale(std::weak_ptr<RigidBody> object, const Vec3D &s, double duration = 1, LoopOut looped = LoopOut::None,
|
|
|
|
InterpolationType interpolationType = InterpolationType::Bezier) : Animation(duration, looped,
|
|
|
|
interpolationType),
|
|
|
|
_object(object), _scalingValue(s) {
|
2021-10-28 16:58:02 +03:00
|
|
|
}
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //INC_3DZAVR_ASCALE_H
|