2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 02.06.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_ACOLOR_H
|
|
|
|
#define ENGINE_ACOLOR_H
|
|
|
|
|
|
|
|
#include "Animation.h"
|
2021-10-09 13:41:12 +03:00
|
|
|
#include "../Mesh.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
class AColor final : public Animation {
|
2021-09-13 15:53:43 +03:00
|
|
|
private:
|
2021-10-28 16:58:02 +03:00
|
|
|
const std::weak_ptr<Mesh> _mesh;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
sf::Color _startColor;
|
|
|
|
const sf::Color _newColor;
|
|
|
|
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 mesh = _mesh.lock();
|
|
|
|
|
|
|
|
if (mesh == 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;
|
2021-11-09 22:54:20 +03:00
|
|
|
_startColor = mesh->color();
|
2021-10-28 16:58:02 +03:00
|
|
|
}
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
Vec4D start(_startColor.r, _startColor.g, _startColor.b, _startColor.a);
|
|
|
|
Vec4D end(_newColor.r, _newColor.g, _newColor.b, _newColor.a);
|
|
|
|
Vec4D mid = start + (end - start) * progress();
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-11-09 22:54:20 +03:00
|
|
|
mesh->setColor(sf::Color(static_cast<sf::Uint8>(mid.x()), static_cast<sf::Uint8>(mid.y()),
|
2021-10-31 11:39:08 +03:00
|
|
|
static_cast<sf::Uint8>(mid.z()), static_cast<sf::Uint8>(mid.w())));
|
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
|
|
|
AColor(std::weak_ptr<Mesh> mesh, const sf::Color &color, double duration = 1, LoopOut looped = LoopOut::None,
|
|
|
|
InterpolationType interpolationType = InterpolationType::Linear) : Animation(duration, looped,
|
|
|
|
interpolationType),
|
2021-11-09 22:54:20 +03:00
|
|
|
_mesh(mesh), _newColor(color) {
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //SHOOTER_3DZAVR_ACOLOR_H
|