Added velocity interpolation

This commit is contained in:
Stiffly
2014-04-22 18:58:41 +02:00
parent 78d4dbf8c2
commit bdac6fa9f9
3 changed files with 35 additions and 6 deletions
+20 -4
View File
@@ -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<<m_TimeSinceLastSpawn<<std::endl;
std::list<ParticleData>::iterator it;
for(it = m_ParticleEmitter[entity].begin(); it == m_ParticleEmitter[entity].end();)
{
auto particleComponent = m_World->GetComponent<Components::Particle>(it->ParticleID, "Particle");
int timeLived = glfwGetTime() - it->SpawnTime;
double timeLived = glfwGetTime() - it->SpawnTime;
std::cout<<timeLived<<std::endl;
if(timeLived > 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<Components::Particle>(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;