From 07ddceaa37dbbb9a31e16bf8c0bbe5b2d2e40f95 Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Tue, 19 Jul 2022 17:10:18 +0700 Subject: [PATCH] add ADecompose.h animation --- CMakeLists.txt | 1 + engine/animation/ADecompose.h | 50 +++++++++++++++++++++++++++++++++++ engine/animation/Animations.h | 1 + 3 files changed, 52 insertions(+) create mode 100644 engine/animation/ADecompose.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c6f7b7c..efda2fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,7 @@ add_executable(${CMAKE_PROJECT_NAME} engine/animation/AShowCreation.h engine/animation/AShowUncreation.h engine/animation/ARotateLeftUpLookAt.h + engine/animation/ADecompose.h engine/physics/RigidBody.cpp engine/physics/RigidBody.h engine/physics/Simplex.h diff --git a/engine/animation/ADecompose.h b/engine/animation/ADecompose.h new file mode 100644 index 0000000..3bd49a5 --- /dev/null +++ b/engine/animation/ADecompose.h @@ -0,0 +1,50 @@ +// +// Created by Иван Ильин on 23.02.2022. +// + +#ifndef INC_3DZAVR_ADECOMPOSE_H +#define INC_3DZAVR_ADECOMPOSE_H + +#include "Animation.h" +#include "../Mesh.h" +#include "../Consts.h" + +class ADecompose final : public Animation { +private: + const std::weak_ptr _mesh; + std::vector _triangles; + + double _value; + bool _started = false; + + void update() override { + auto mesh = _mesh.lock(); + + if (mesh == nullptr) { + stop(); + return; + } + + if (!_started) { + _started = true; + _triangles = _mesh.lock()->triangles(); + } + + std::vector newTriangles; + newTriangles.reserve(_triangles.size()); + + for(auto &t : _triangles) { + newTriangles.emplace_back((t * Matrix4x4::Translation(t.position().normalized()*progress()*_value))); + } + mesh->setTriangles(std::move(newTriangles)); + mesh->glFreeFloatArray(); + } + +public: + ADecompose(std::weak_ptr mesh, double value, double duration = 1, LoopOut looped = LoopOut::None, + InterpolationType interpolationType = InterpolationType::Bezier) : Animation(duration, looped, + interpolationType), + _value(value), _mesh(mesh) {} +}; + +#endif //INC_3DZAVR_ADECOMPOSE_H diff --git a/engine/animation/Animations.h b/engine/animation/Animations.h index 66fbabb..1106c3b 100644 --- a/engine/animation/Animations.h +++ b/engine/animation/Animations.h @@ -20,6 +20,7 @@ #include "AShowCreation.h" #include "AShowUncreation.h" #include "ARotateLeftUpLookAt.h" +#include "ADecompose.h" #endif //SHOOTER_ANIMATIONS_H