diff options
author | jaroWMR <jarorutjes07@gmail.com> | 2024-10-07 16:39:26 +0200 |
---|---|---|
committer | jaroWMR <jarorutjes07@gmail.com> | 2024-10-07 16:39:26 +0200 |
commit | 5cf5cf64d6f9597849ed5558da4f1bc201165fed (patch) | |
tree | b0b02e8b71c5e8e5afba4212daa999c5cc04bd26 /src/crepe/ParticleSystem.cpp | |
parent | 096e0d0a7199ec9a4059fd5ef8a06a3cf8fcae83 (diff) |
updated system
Diffstat (limited to 'src/crepe/ParticleSystem.cpp')
-rw-r--r-- | src/crepe/ParticleSystem.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/crepe/ParticleSystem.cpp b/src/crepe/ParticleSystem.cpp index 367f56c..f3cb939 100644 --- a/src/crepe/ParticleSystem.cpp +++ b/src/crepe/ParticleSystem.cpp @@ -10,13 +10,12 @@ ParticleSystem::ParticleSystem() : m_elapsedTime(0.0f) {} // Initialize m_elaps void ParticleSystem::update(float deltaTime, std::vector<ParticleEmitter>& emitters) { for (ParticleEmitter& emitter : emitters) { - m_elapsedTime = deltaTime; - - //spawn new particles if enough time passed and the max is not achieved - while (m_elapsedTime >= (1.0f / emitter.m_emissionRate) && emitter.particles.size() < emitter.m_maxParticles) { - m_elapsedTime -= (1.0f / emitter.m_emissionRate); + float updateAmount = 1/static_cast<float>(emitter.m_emissionRate); + for (float i = 0; i < deltaTime; i += updateAmount) + { emitParticle(emitter); } + //update/move particles afterwards delete if not alive. std::vector<Particle>::iterator it = emitter.particles.begin(); while (it != emitter.particles.end()) { @@ -32,7 +31,7 @@ void ParticleSystem::update(float deltaTime, std::vector<ParticleEmitter>& emitt } void ParticleSystem::emitParticle(ParticleEmitter& emitter) { - std::cout << "new emitter:" << std::endl; + // std::cout << "new emitter:" << std::endl; Particle::Position initialPosition = { emitter.m_position.x, emitter.m_position.y }; float randomAngle = 0.0f; //check if value is overthe 360 degrees @@ -45,18 +44,16 @@ void ParticleSystem::emitParticle(ParticleEmitter& emitter) { randomAngle = emitter.m_minAngle + (std::rand() % (static_cast<int>(emitter.m_maxAngle - emitter.m_minAngle + 1))); } - std::cout << "randomAngle:" << randomAngle << std::endl; + float angleInRadians = randomAngle * (M_PI / 180.0f); float randomSpeedOffset = (static_cast<float>(std::rand()) / RAND_MAX) * (2 * emitter.m_speedOffset) - emitter.m_speedOffset; float velocityX = (emitter.m_speed + randomSpeedOffset) * std::cos(angleInRadians); float velocityY = (emitter.m_speed + randomSpeedOffset) * std::sin(angleInRadians); - std::cout << "velocityX:" << velocityX << std::endl; - std::cout << "velocityY:" << velocityY << std::endl; Particle::Position initialVelocity = { velocityX, velocityY }; - std::cout << "initialVelocityX:" << initialVelocity.x << std::endl; - std::cout << "initialVelocityY:" << initialVelocity.y << std::endl; - emitter.particles.emplace_back(2.0f, initialPosition, initialVelocity); + // std::cout << "emitter.m_endLifespan:" << emitter.m_endLifespan << std::endl; + + emitter.particles.emplace_back(emitter.m_endLifespan, initialPosition, initialVelocity); } |