diff options
Diffstat (limited to 'src/crepe/ParticleSystem.cpp')
-rw-r--r-- | src/crepe/ParticleSystem.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/crepe/ParticleSystem.cpp b/src/crepe/ParticleSystem.cpp index f0220a1..af6c550 100644 --- a/src/crepe/ParticleSystem.cpp +++ b/src/crepe/ParticleSystem.cpp @@ -1,14 +1,14 @@ -#include "ParticleSystem.h" -#include "ComponentManager.h" -#include "Particle.h" -#include "api/ParticleEmitter.h" #include <cmath> #include <ctime> +#include "api/ParticleEmitter.h" + +#include "ComponentManager.h" +#include "ParticleSystem.h" + using namespace crepe; -ParticleSystem::ParticleSystem() - : m_elapsed_time(0.0f) {} // Initialize m_elapsedTime to 0 +ParticleSystem::ParticleSystem() : elapsed_time(0.0f) {} void ParticleSystem::update() { ComponentManager & mgr = ComponentManager::get_instance(); @@ -16,7 +16,7 @@ void ParticleSystem::update() { = mgr.get_components_by_type<ParticleEmitter>(); float delta_time = 0.10; for (ParticleEmitter & emitter : emitters) { - float update_amount = 1 / static_cast<float>(emitter.m_emission_rate); + float update_amount = 1 / static_cast<float>(emitter.emission_rate); for (float i = 0; i < delta_time; i += update_amount) { emit_particle(emitter); } @@ -29,32 +29,32 @@ void ParticleSystem::update() { } void ParticleSystem::emit_particle(ParticleEmitter & emitter) { - Position initial_position = {emitter.m_position.x, emitter.m_position.y}; + Position initial_position = {emitter.position.x, emitter.position.y}; float random_angle = 0.0f; - if (emitter.m_max_angle < emitter.m_min_angle) { - random_angle = ((emitter.m_min_angle - + (std::rand() - % (static_cast<uint32_t>(emitter.m_max_angle + 360 - - emitter.m_min_angle + 1)))) - % 360); + if (emitter.max_angle < emitter.min_angle) { + random_angle = ((emitter.min_angle + + (std::rand() + % (static_cast<uint32_t>(emitter.max_angle + 360 + - emitter.min_angle + 1)))) + % 360); } else { - random_angle = emitter.m_min_angle - + (std::rand() - % (static_cast<uint32_t>(emitter.m_max_angle - - emitter.m_min_angle + 1))); + random_angle = emitter.min_angle + + (std::rand() + % (static_cast<uint32_t>(emitter.max_angle + - emitter.min_angle + 1))); } float angle_in_radians = random_angle * (M_PI / 180.0f); float random_speed_offset = (static_cast<float>(std::rand()) / RAND_MAX) - * (2 * emitter.m_speed_offset) - - emitter.m_speed_offset; + * (2 * emitter.speed_offset) + - emitter.speed_offset; float velocity_x - = (emitter.m_speed + random_speed_offset) * std::cos(angle_in_radians); + = (emitter.speed + random_speed_offset) * std::cos(angle_in_radians); float velocity_y - = (emitter.m_speed + random_speed_offset) * std::sin(angle_in_radians); + = (emitter.speed + random_speed_offset) * std::sin(angle_in_radians); Position initial_velocity = {velocity_x, velocity_y}; for (size_t i = 0; i < emitter.particles.size(); i++) { if (!emitter.particles[i].active) { - emitter.particles[i].reset(emitter.m_end_lifespan, initial_position, + emitter.particles[i].reset(emitter.end_lifespan, initial_position, initial_velocity); break; } |