From afa3f68f422c4d26e56a24d5986a0d8daa0b74ac Mon Sep 17 00:00:00 2001 From: TheNumbat Date: Tue, 4 May 2021 14:29:11 -0700 Subject: [PATCH] fix 0 particle/s --- src/scene/particles.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/scene/particles.cpp b/src/scene/particles.cpp index 80a2ce4..714da67 100644 --- a/src/scene/particles.cpp +++ b/src/scene/particles.cpp @@ -121,28 +121,31 @@ void Scene_Particles::step(const PT::BVH& scene, float dt) { float cos = std::cos(Radians(opt.angle) / 2.0f); - double cooldown = 1.0 / opt.pps; - while(particle_cooldown <= 0.0f) { + if(opt.pps > 0.0f) { + double cooldown = 1.0 / opt.pps; + while(particle_cooldown <= 0.0f) { - float z = lerp(cos, 1.0f, RNG::unit()); - float t = 2 * PI_F * RNG::unit(); - float r = std::sqrt(1 - z * z); - Vec3 dir = opt.velocity * Vec3(r * std::cos(t), z, r * std::sin(t)); + float z = lerp(cos, 1.0f, RNG::unit()); + float t = 2 * PI_F * RNG::unit(); + float r = std::sqrt(1 - z * z); + Vec3 dir = opt.velocity * Vec3(r * std::cos(t), z, r * std::sin(t)); - Particle p; - p.pos = pose.pos; - p.velocity = pose.rotation_mat().rotate(dir); - p.age = opt.lifetime; - next.push_back(p); + Particle p; + p.pos = pose.pos; + p.velocity = pose.rotation_mat().rotate(dir); + p.age = opt.lifetime; + next.push_back(p); - Mat4 T = Mat4{Vec4{S, 0.0f, 0.0f, 0.0f}, Vec4{0.0f, S, 0.0f, 0.0f}, - Vec4{0.0f, 0.0f, S, 0.0f}, Vec4{p.pos, 1.0f}}; - particle_instances.add(T); + Mat4 T = Mat4{Vec4{S, 0.0f, 0.0f, 0.0f}, Vec4{0.0f, S, 0.0f, 0.0f}, + Vec4{0.0f, 0.0f, S, 0.0f}, Vec4{p.pos, 1.0f}}; + particle_instances.add(T); + + particle_cooldown += cooldown; + } - particle_cooldown += cooldown; + particle_cooldown -= dt; } - particle_cooldown -= dt; particles = std::move(next); } -- GitLab