shooter/engine/animation/AColor.h

44 lines
1.2 KiB
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 02.06.2021.
//
#ifndef ENGINE_ACOLOR_H
#define ENGINE_ACOLOR_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 "../Mesh.h"
2021-09-13 15:53:43 +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 {
if(_mesh.expired()) {
stop();
return;
}
2021-09-13 15:53:43 +03:00
2021-10-28 16:58:02 +03:00
if(!_started) {
_started = true;
_startColor = _mesh.lock()->color();
}
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-10-28 16:58:02 +03:00
_mesh.lock()->setColor(sf::Color(static_cast<sf::Uint8>(mid.x()), static_cast<sf::Uint8>(mid.y()), static_cast<sf::Uint8>(mid.z()), static_cast<sf::Uint8>(mid.w())));
}
public:
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), _mesh(std::move(mesh)), _newColor(color) {
2021-09-13 15:53:43 +03:00
}
};
#endif //SHOOTER_3DZAVR_ACOLOR_H