diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 5d471b8..455c105 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -90,6 +90,19 @@ void GameWorld::Initialize() emitter->Loop = true; GetSystem("SoundSystem")->PlaySound(emitter); }*/ + +// { +// // Particle emitter +// auto ent = CreateEntity(); +// auto transform = AddComponent(ent, "Transform"); +// transform->Position = glm::vec3(0); +// auto emitter = AddComponent(ent, "ParticleEmitter"); +// emitter->LifeTime = 4; +// emitter->SpawnCount = 3; +// emitter->SpreadAngle = 35; +// emitter->SpawnFrequency = 0.3; +// //emitter-> +// } } void GameWorld::Update(double dt) diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index 8488d3d..d379ba9 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -4,6 +4,11 @@ #include "World.h" +Systems::ParticleSystem::ParticleSystem(World *m_World) : System(m_World) +{ + m_TimeSinceLastSpawn = 0; +} + void Systems::ParticleSystem::Update(double dt) { m_TimeSinceLastSpawn += dt; @@ -23,13 +28,14 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID SpawnParticles(entity, emitterComponent->SpawnCount, emitterComponent->SpreadAngle); m_TimeSinceLastSpawn = 0; } - + std::cout<::iterator it; for(it = m_ParticleEmitter[entity].begin(); it == m_ParticleEmitter[entity].end();) { auto particleComponent = m_World->GetComponent(it->ParticleID, "Particle"); - int timeLived = glfwGetTime() - it->SpawnTime; + double timeLived = glfwGetTime() - it->SpawnTime; + std::cout< particleComponent->LifeTime) { m_ParticleEmitter[entity].erase(it); @@ -51,9 +57,17 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID deltaColor = glm::abs(particleComponent->ColorSpectrum[0].b - particleComponent->ColorSpectrum[1].b); it->color.b = particleComponent->ColorSpectrum[0].b + deltaColor * timeProgress; - //Interpolates the scale for the particle + //Interpolates the scale of the particle float deltaScale = glm::abs(particleComponent->ScaleSpectrum[0] - particleComponent->ScaleSpectrum[1]); it->Scale = particleComponent->ScaleSpectrum[0] + deltaScale * timeProgress; + + //Interpolates the velocity of the particle + float deltaVelocity = glm::abs(particleComponent->VelocitySpectrum[0].x - particleComponent->VelocitySpectrum[1].x); + it->Velocity.x = particleComponent->VelocitySpectrum[0].x + deltaVelocity * timeProgress; + deltaVelocity = glm::abs(particleComponent->VelocitySpectrum[0].y - particleComponent->VelocitySpectrum[1].y); + it->Velocity.y = particleComponent->VelocitySpectrum[0].y + deltaVelocity * timeProgress; + deltaVelocity = glm::abs(particleComponent->VelocitySpectrum[0].z - particleComponent->VelocitySpectrum[1].z); + it->Velocity.z = particleComponent->VelocitySpectrum[0].z + deltaVelocity * timeProgress; } } } @@ -75,13 +89,15 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID, float spawnCoun transform->Position = glm::vec3(0); auto particle = m_World->AddComponent(ent, "Particle"); - particle->LifeTime = 4; + particle->LifeTime = 4000; Color startColor = {.4f, .45f, .2f}; particle->ColorSpectrum.push_back(startColor); Color endColor = {0.f, 45.f, 23.f}; particle->ColorSpectrum.push_back(endColor); particle->ScaleSpectrum.push_back(1); particle->ScaleSpectrum.push_back(30); + particle->VelocitySpectrum.push_back(glm::vec3(0, -.2, 0)); + particle->VelocitySpectrum.push_back(glm::vec3(0, -3, 0)); ParticleData data; data.ParticleID = ent; diff --git a/src/Systems/ParticleSystem.h b/src/Systems/ParticleSystem.h index 84674e6..3c24e79 100644 --- a/src/Systems/ParticleSystem.h +++ b/src/Systems/ParticleSystem.h @@ -18,13 +18,13 @@ namespace Systems double SpawnTime; float Scale; Color color; + glm::vec3 Velocity; }; class ParticleSystem : public System { public: - ParticleSystem(World* world) - :System(world) { }; + ParticleSystem(World* world); void RegisterComponents(ComponentFactory* cf) override; void Update(double dt) override;