add particles (WIP)

This commit is contained in:
MihailRis
2024-11-02 20:40:40 +03:00
parent a0f885e26a
commit 217176f74f
8 changed files with 280 additions and 4 deletions
+53
View File
@@ -0,0 +1,53 @@
#include "Emitter.hpp"
#include <glm/gtc/random.hpp>
#include "graphics/core/Texture.hpp"
Emitter::Emitter(
std::variant<glm::vec3, entityid_t> origin,
Particle prototype,
const Texture* texture,
float spawnInterval,
int count
)
: origin(std::move(origin)),
prototype(std::move(prototype)),
texture(texture),
spawnInterval(spawnInterval),
count(count) {
}
const Texture* Emitter::getTexture() const {
return texture;
}
void Emitter::update(float delta, std::vector<Particle>& particles) {
if (count == 0) {
return;
}
glm::vec3 position {};
if (auto staticPos = std::get_if<glm::vec3>(&origin)) {
position = *staticPos;
} else {
// TODO: implement for entity origin
}
timer += delta;
while (count && timer > spawnInterval) {
// spawn particle
Particle particle = prototype;
particle.position = position;
particle.velocity += glm::ballRand(1.0f) * explosion;
particles.push_back(std::move(particle));
timer -= spawnInterval;
count--;
}
}
void Emitter::setExplosion(const glm::vec3& magnitude) {
explosion = magnitude;
}
bool Emitter::isDead() const {
return count == 0;
}