Bug fix: fixed time to correct resolution, seconds.

This commit is contained in:
Stiffly
2014-04-23 22:46:19 +02:00
parent 100f8f5be4
commit 07bc49e3c1
3 changed files with 17 additions and 16 deletions
+3 -3
View File
@@ -49,7 +49,7 @@ void GameWorld::Initialize()
model->ModelFile = "Models/Placeholders/tank/Chassi.obj"; model->ModelFile = "Models/Placeholders/tank/Chassi.obj";
} }
for(int i = 0; i < 83; i++) for(int i = 0; i < 2; i++)
{ {
auto light = CreateEntity(); auto light = CreateEntity();
auto transform = AddComponent<Components::Transform>(light, "Transform"); auto transform = AddComponent<Components::Transform>(light, "Transform");
@@ -67,7 +67,7 @@ void GameWorld::Initialize()
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
} }
for(int i = 0; i < 500; i++) for(int i = 0; i < 3; i++)
{ {
auto ball = CreateEntity(); auto ball = CreateEntity();
auto transform = AddComponent<Components::Transform>(ball, "Transform"); auto transform = AddComponent<Components::Transform>(ball, "Transform");
@@ -100,7 +100,7 @@ void GameWorld::Initialize()
emitter->LifeTime = 4; emitter->LifeTime = 4;
emitter->SpawnCount = 3; emitter->SpawnCount = 3;
emitter->SpreadAngle = 35; emitter->SpreadAngle = 35;
emitter->SpawnFrequency = 0.3; emitter->SpawnFrequency = 0.01;
//emitter-> //emitter->
} }
} }
+14 -12
View File
@@ -25,23 +25,25 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
{ {
if(m_TimeSinceLastSpawn > emitterComponent->SpawnFrequency) if(m_TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
{ {
SpawnParticles(entity, emitterComponent->SpawnCount, emitterComponent->SpreadAngle); if(m_ParticleEmitter[entity].size() < 100)
m_TimeSinceLastSpawn = 0; {
SpawnParticles(entity, emitterComponent->SpawnCount, emitterComponent->SpreadAngle);
m_TimeSinceLastSpawn = 0;
}
std::cout<<"Particle count: "<<m_ParticleEmitter[entity].size()<<std::endl;
} }
std::cout<<m_TimeSinceLastSpawn<<std::endl;
std::list<ParticleData>::iterator it; std::list<ParticleData>::iterator it;
for(it = m_ParticleEmitter[entity].begin(); it == m_ParticleEmitter[entity].end();) for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();)
{ {
auto particleComponent = m_World->GetComponent<Components::Particle>(it->ParticleID, "Particle"); auto particleComponent = m_World->GetComponent<Components::Particle>(it->ParticleID, "Particle");
if(!particleComponent)
break;
double timeLived = glfwGetTime() - it->SpawnTime; double timeLived = glfwGetTime() - it->SpawnTime;
std::cout<<timeLived<<std::endl;
if(timeLived > particleComponent->LifeTime) if(timeLived > particleComponent->LifeTime)
{ {
m_ParticleEmitter[entity].erase(it); m_ParticleEmitter[entity].erase(it);
std::cout<<"Removed dead particle..."<<std::endl;
break; break;
} }
else else
@@ -50,7 +52,7 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
} }
// Interpolates the color for each color channel by the start and end value. Decides how much the color should be interpolated based on time. // Interpolates the color for each color channel by the start and end value. Decides how much the color should be interpolated based on time.
// How big fraction the color is multiplied with /*// How big fraction the color is multiplied with
float timeProgress = timeLived / particleComponent->LifeTime; float timeProgress = timeLived / particleComponent->LifeTime;
// The difference between the start and end value // The difference between the start and end value
float deltaColor = glm::abs(particleComponent->ColorSpectrum[0].r - particleComponent->ColorSpectrum[1].r); float deltaColor = glm::abs(particleComponent->ColorSpectrum[0].r - particleComponent->ColorSpectrum[1].r);
@@ -70,7 +72,7 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
deltaVelocity = glm::abs(particleComponent->VelocitySpectrum[0].y - particleComponent->VelocitySpectrum[1].y); deltaVelocity = glm::abs(particleComponent->VelocitySpectrum[0].y - particleComponent->VelocitySpectrum[1].y);
it->Velocity.y = particleComponent->VelocitySpectrum[0].y + deltaVelocity * timeProgress; it->Velocity.y = particleComponent->VelocitySpectrum[0].y + deltaVelocity * timeProgress;
deltaVelocity = glm::abs(particleComponent->VelocitySpectrum[0].z - particleComponent->VelocitySpectrum[1].z); deltaVelocity = glm::abs(particleComponent->VelocitySpectrum[0].z - particleComponent->VelocitySpectrum[1].z);
it->Velocity.z = particleComponent->VelocitySpectrum[0].z + deltaVelocity * timeProgress; it->Velocity.z = particleComponent->VelocitySpectrum[0].z + deltaVelocity * timeProgress;*/
} }
} }
} }
@@ -83,7 +85,6 @@ void Systems::ParticleSystem::RegisterComponents(ComponentFactory* cf)
void Systems::ParticleSystem::SpawnParticles(EntityID emitterID, float spawnCount, float spreadAngle) void Systems::ParticleSystem::SpawnParticles(EntityID emitterID, float spawnCount, float spreadAngle)
{ {
std::list<EntityID> particles;
for(int i = 0; i < spawnCount; i++) for(int i = 0; i < spawnCount; i++)
{ {
auto ent = m_World->CreateEntity(); auto ent = m_World->CreateEntity();
@@ -92,7 +93,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID, float spawnCoun
transform->Position = glm::vec3(0); transform->Position = glm::vec3(0);
auto particle = m_World->AddComponent<Components::Particle>(ent, "Particle"); auto particle = m_World->AddComponent<Components::Particle>(ent, "Particle");
particle->LifeTime = 4000; particle->LifeTime = 4;
Color startColor = {.4f, .45f, .2f}; Color startColor = {.4f, .45f, .2f};
particle->ColorSpectrum.push_back(startColor); particle->ColorSpectrum.push_back(startColor);
Color endColor = {0.f, 45.f, 23.f}; Color endColor = {0.f, 45.f, 23.f};
@@ -110,6 +111,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID, float spawnCoun
m_ParticleEmitter[emitterID].push_back(data); m_ParticleEmitter[emitterID].push_back(data);
} }
std::cout<<"Added "<<spawnCount<<" particles..."<<std::endl;
} }
void Systems::ParticleSystem::Draw(double dt) void Systems::ParticleSystem::Draw(double dt)
-1
View File
@@ -8,7 +8,6 @@
#include "Color.h" #include "Color.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
namespace Systems namespace Systems
{ {