mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add 'spawn_spread' and 'spawn_shape'
This commit is contained in:
parent
86b83a5377
commit
39893ee940
4 changed files with 68 additions and 2 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue