add 'spawn_spread' and 'spawn_shape'

This commit is contained in:
MihailRis
2024-11-03 17:14:30 +03:00
parent 86b83a5377
commit 39893ee940
4 changed files with 68 additions and 2 deletions
+18 -1
View File
@@ -30,6 +30,19 @@ const Texture* Emitter::getTexture() const {
return texture;
}
static inline glm::vec3 generate_coord(ParticleSpawnShape shape) {
switch (shape) {
case ParticleSpawnShape::BALL:
return glm::ballRand(1.0f);
case ParticleSpawnShape::SPHERE:
return glm::sphericalRand(1.0f);
case ParticleSpawnShape::BOX:
return glm::linearRand(glm::vec3(-1.0f), glm::vec3(1.0f));
default:
return {};
}
}
void Emitter::update(
float delta,
const glm::vec3& cameraPosition,
@@ -66,7 +79,11 @@ void Emitter::update(
Particle particle = prototype;
particle.emitter = this;
particle.random = random.rand32();
particle.position = position;
glm::vec3 spawnOffset = generate_coord(preset.spawnShape);
spawnOffset *= preset.spawnSpread;
particle.position = position + spawnOffset;
particle.lifetime *= 1.0f - preset.lifetimeSpread * random.randFloat();
particle.velocity += glm::ballRand(1.0f) * preset.explosion;
if (preset.randomSubUV < 1.0f) {