#include "Emitter.hpp" #include #include "graphics/core/Texture.hpp" Emitter::Emitter( std::variant origin, Particle prototype, const Texture* texture, float spawnInterval, int count ) : origin(std::move(origin)), prototype(std::move(prototype)), texture(texture), spawnInterval(spawnInterval), count(count), behaviour() { this->prototype.emitter = this; } const Texture* Emitter::getTexture() const { return texture; } void Emitter::update(float delta, std::vector& particles) { if (count == 0) { return; } glm::vec3 position {}; if (auto staticPos = std::get_if(&origin)) { position = *staticPos; } else { // TODO: implement for entity origin } timer += delta; while (count && timer > spawnInterval) { // spawn particle Particle particle = prototype; particle.emitter = this; particle.random = rand(); particle.position = position; particle.velocity += glm::ballRand(1.0f) * explosion; particles.push_back(std::move(particle)); timer -= spawnInterval; if (count > 0) { count--; } } } void Emitter::setExplosion(const glm::vec3& magnitude) { explosion = magnitude; } bool Emitter::isDead() const { return count == 0; }