Added velocity interpolation
This commit is contained in:
@@ -90,6 +90,19 @@ void GameWorld::Initialize()
|
|||||||
emitter->Loop = true;
|
emitter->Loop = true;
|
||||||
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(emitter);
|
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(emitter);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
// {
|
||||||
|
// // Particle emitter
|
||||||
|
// auto ent = CreateEntity();
|
||||||
|
// auto transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
|
// transform->Position = glm::vec3(0);
|
||||||
|
// auto emitter = AddComponent<Components::ParticleEmitter>(ent, "ParticleEmitter");
|
||||||
|
// emitter->LifeTime = 4;
|
||||||
|
// emitter->SpawnCount = 3;
|
||||||
|
// emitter->SpreadAngle = 35;
|
||||||
|
// emitter->SpawnFrequency = 0.3;
|
||||||
|
// //emitter->
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameWorld::Update(double dt)
|
void GameWorld::Update(double dt)
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
|
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
|
|
||||||
|
Systems::ParticleSystem::ParticleSystem(World *m_World) : System(m_World)
|
||||||
|
{
|
||||||
|
m_TimeSinceLastSpawn = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Systems::ParticleSystem::Update(double dt)
|
void Systems::ParticleSystem::Update(double dt)
|
||||||
{
|
{
|
||||||
m_TimeSinceLastSpawn += dt;
|
m_TimeSinceLastSpawn += dt;
|
||||||
@@ -23,13 +28,14 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
SpawnParticles(entity, emitterComponent->SpawnCount, emitterComponent->SpreadAngle);
|
SpawnParticles(entity, emitterComponent->SpawnCount, emitterComponent->SpreadAngle);
|
||||||
m_TimeSinceLastSpawn = 0;
|
m_TimeSinceLastSpawn = 0;
|
||||||
}
|
}
|
||||||
|
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");
|
||||||
|
|
||||||
int 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);
|
||||||
@@ -51,9 +57,17 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
deltaColor = glm::abs(particleComponent->ColorSpectrum[0].b - particleComponent->ColorSpectrum[1].b);
|
deltaColor = glm::abs(particleComponent->ColorSpectrum[0].b - particleComponent->ColorSpectrum[1].b);
|
||||||
it->color.b = particleComponent->ColorSpectrum[0].b + deltaColor * timeProgress;
|
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]);
|
float deltaScale = glm::abs(particleComponent->ScaleSpectrum[0] - particleComponent->ScaleSpectrum[1]);
|
||||||
it->Scale = particleComponent->ScaleSpectrum[0] + deltaScale * timeProgress;
|
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);
|
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 = 4;
|
particle->LifeTime = 4000;
|
||||||
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};
|
||||||
particle->ColorSpectrum.push_back(endColor);
|
particle->ColorSpectrum.push_back(endColor);
|
||||||
particle->ScaleSpectrum.push_back(1);
|
particle->ScaleSpectrum.push_back(1);
|
||||||
particle->ScaleSpectrum.push_back(30);
|
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;
|
ParticleData data;
|
||||||
data.ParticleID = ent;
|
data.ParticleID = ent;
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ namespace Systems
|
|||||||
double SpawnTime;
|
double SpawnTime;
|
||||||
float Scale;
|
float Scale;
|
||||||
Color color;
|
Color color;
|
||||||
|
glm::vec3 Velocity;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ParticleSystem : public System
|
class ParticleSystem : public System
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ParticleSystem(World* world)
|
ParticleSystem(World* world);
|
||||||
:System(world) { };
|
|
||||||
void RegisterComponents(ComponentFactory* cf) override;
|
void RegisterComponents(ComponentFactory* cf) override;
|
||||||
|
|
||||||
void Update(double dt) override;
|
void Update(double dt) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user