Angular velocity support
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Components
|
|||||||
std::vector<float> ScaleSpectrum;
|
std::vector<float> ScaleSpectrum;
|
||||||
double LifeTime;
|
double LifeTime;
|
||||||
std::vector<glm::vec3> VelocitySpectrum;
|
std::vector<glm::vec3> VelocitySpectrum;
|
||||||
std::vector<glm::vec3> AngularVelocitySpectrum;
|
std::vector<float> AngularVelocitySpectrum;
|
||||||
|
|
||||||
virtual Particle* Clone() const override { return new Particle(*this); }
|
virtual Particle* Clone() const override { return new Particle(*this); }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ struct ParticleEmitter : Component
|
|||||||
float SpreadAngle;
|
float SpreadAngle;
|
||||||
double LifeTime;
|
double LifeTime;
|
||||||
std::vector<glm::vec3> VelocitySpectrum;
|
std::vector<glm::vec3> VelocitySpectrum;
|
||||||
std::vector<glm::vec3> AngularVelocitySpectrum;
|
std::vector<float> AngularVelocitySpectrum;
|
||||||
|
|
||||||
virtual ParticleEmitter* Clone() const override { return new ParticleEmitter(*this); }
|
virtual ParticleEmitter* Clone() const override { return new ParticleEmitter(*this); }
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -101,9 +101,9 @@ void GameWorld::Initialize()
|
|||||||
transform->Position = glm::vec3(i * 10, 20, 0);
|
transform->Position = glm::vec3(i * 10, 20, 0);
|
||||||
auto emitter = AddComponent<Components::ParticleEmitter>(ent, "ParticleEmitter");
|
auto emitter = AddComponent<Components::ParticleEmitter>(ent, "ParticleEmitter");
|
||||||
emitter->LifeTime = 4;
|
emitter->LifeTime = 4;
|
||||||
emitter->SpawnCount = 4;
|
emitter->SpawnCount = 1;
|
||||||
emitter->SpreadAngle = glm::pi<float>()/4;
|
emitter->SpreadAngle = glm::pi<float>()/20;
|
||||||
emitter->SpawnFrequency = 0.08;
|
emitter->SpawnFrequency = 0.008;
|
||||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
auto model = AddComponent<Components::Model>(ent, "Model");
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
||||||
|
|
||||||
|
|||||||
@@ -47,19 +47,18 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//FIX: calculate once
|
||||||
float timeProgress = timeLived / particleComponent->LifeTime;
|
float timeProgress = timeLived / particleComponent->LifeTime;
|
||||||
// The difference between the start and end value
|
//ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color);
|
||||||
/*float deltaColor = glm::abs(particleComponent->ColorSpectrum[0].r - particleComponent->ColorSpectrum[1].r);
|
if(particleComponent->ScaleSpectrum.size() > 1)
|
||||||
it->color.r = particleComponent->ColorSpectrum[0].r + deltaColor * timeProgress;
|
ScaleInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale);
|
||||||
deltaColor = glm::abs(particleComponent->ColorSpectrum[0].g - particleComponent->ColorSpectrum[1].g);
|
if(particleComponent->VelocitySpectrum.size() > 1)
|
||||||
it->color.g = particleComponent->ColorSpectrum[0].g + deltaColor * timeProgress;
|
VelocityInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity);
|
||||||
deltaColor = glm::abs(particleComponent->ColorSpectrum[0].b - particleComponent->ColorSpectrum[1].b);
|
if(particleComponent->AngularVelocitySpectrum.size() > 1)
|
||||||
it->color.b = particleComponent->ColorSpectrum[0].b + deltaColor * timeProgress;*/
|
AngularVelocityInterpolation(timeProgress, particleComponent->AngularVelocitySpectrum, it->AngularVelocity);
|
||||||
|
|
||||||
|
|
||||||
ScaleInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale);
|
|
||||||
VelocityInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity);
|
|
||||||
|
|
||||||
|
transformComponent->Orientation *= glm::angleAxis(it->AngularVelocity, glm::vec3(0, 0, 1));
|
||||||
transformComponent->Position += transformComponent->Velocity * (float)dt;
|
transformComponent->Position += transformComponent->Velocity * (float)dt;
|
||||||
|
|
||||||
it++;
|
it++;
|
||||||
@@ -103,12 +102,12 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
|||||||
|
|
||||||
auto particle = m_World->AddComponent<Components::Particle>(ent, "Particle");
|
auto particle = m_World->AddComponent<Components::Particle>(ent, "Particle");
|
||||||
particle->LifeTime = emitterComponent->LifeTime;
|
particle->LifeTime = emitterComponent->LifeTime;
|
||||||
particle->ScaleSpectrum.push_back(4); //TEMP
|
particle->ScaleSpectrum.push_back(1); //TEMP
|
||||||
particle->ScaleSpectrum.push_back(0); //TEMP
|
particle->ScaleSpectrum.push_back(1); //TEMP
|
||||||
particle->VelocitySpectrum.push_back(particleTransform->Velocity); //TEMP
|
particle->VelocitySpectrum.push_back(particleTransform->Velocity); //TEMP
|
||||||
particle->VelocitySpectrum.push_back(testVel); //TEMP
|
particle->VelocitySpectrum.push_back(testVel); //TEMP
|
||||||
// particle->AngularVelocitySpectrum.push_back();
|
//particle->AngularVelocitySpectrum.push_back(0.f);
|
||||||
// particle->AngularVelocitySpectrum.push_back();
|
particle->AngularVelocitySpectrum.push_back(-glm::pi<float>()/10);
|
||||||
|
|
||||||
// Color startColor = {.4f, .45f, .2f};
|
// Color startColor = {.4f, .45f, .2f};
|
||||||
// particle->ColorSpectrum.push_back(startColor);
|
// particle->ColorSpectrum.push_back(startColor);
|
||||||
@@ -120,8 +119,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
|||||||
ParticleData data;
|
ParticleData data;
|
||||||
data.ParticleID = ent;
|
data.ParticleID = ent;
|
||||||
data.SpawnTime = glfwGetTime();
|
data.SpawnTime = glfwGetTime();
|
||||||
// data.color = particle->ColorSpectrum[0];
|
data.AngularVelocity = particle->AngularVelocitySpectrum[0];
|
||||||
// data.Scale = particle->ScaleSpectrum[0];
|
|
||||||
|
|
||||||
m_ParticleEmitter[emitterID].push_back(data);
|
m_ParticleEmitter[emitterID].push_back(data);
|
||||||
}
|
}
|
||||||
@@ -158,3 +156,22 @@ void Systems::ParticleSystem::VelocityInterpolation(double timeProgress, std::ve
|
|||||||
deltaVelocity *= -1;
|
deltaVelocity *= -1;
|
||||||
velocity.z = velocitySpectrum[0].z + deltaVelocity * timeProgress;
|
velocity.z = velocitySpectrum[0].z + deltaVelocity * timeProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Systems::ParticleSystem::ColorInterpolation(double timeProgress, std::vector<Color> colorSpectrum, Color &color)
|
||||||
|
{
|
||||||
|
float deltaColor = glm::abs(colorSpectrum[0].r - colorSpectrum[1].r);
|
||||||
|
color.r = colorSpectrum[0].r + deltaColor * timeProgress;
|
||||||
|
deltaColor = glm::abs(colorSpectrum[0].g - colorSpectrum[1].g);
|
||||||
|
color.g = colorSpectrum[0].g + deltaColor * timeProgress;
|
||||||
|
deltaColor = glm::abs(colorSpectrum[0].b - colorSpectrum[1].b);
|
||||||
|
color.b = colorSpectrum[0].b + deltaColor * timeProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::ParticleSystem::AngularVelocityInterpolation(double timeProgress, std::vector<float> spectrum, float &angularVelocity)
|
||||||
|
{
|
||||||
|
float deltaAngularVelocity = glm::abs(spectrum[0] - spectrum[1]);
|
||||||
|
if(spectrum[0] > spectrum[1])
|
||||||
|
deltaAngularVelocity *= -1;
|
||||||
|
angularVelocity = spectrum[0] + deltaAngularVelocity * timeProgress;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ namespace Systems
|
|||||||
EntityID ParticleID;
|
EntityID ParticleID;
|
||||||
double SpawnTime;
|
double SpawnTime;
|
||||||
float Scale;
|
float Scale;
|
||||||
|
float AngularVelocity;
|
||||||
Color color;
|
Color color;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,6 +36,8 @@ private:
|
|||||||
float RandomizeAngle(float spreadAngle);
|
float RandomizeAngle(float spreadAngle);
|
||||||
void ScaleInterpolation(double timeProgress, std::vector<float> scaleSpectrum, glm::vec3 &scale);
|
void ScaleInterpolation(double timeProgress, std::vector<float> scaleSpectrum, glm::vec3 &scale);
|
||||||
void VelocityInterpolation(double timeProgress, std::vector<glm::vec3> velocitySpectrum, glm::vec3 &velocity);
|
void VelocityInterpolation(double timeProgress, std::vector<glm::vec3> velocitySpectrum, glm::vec3 &velocity);
|
||||||
|
void ColorInterpolation(double timeProgress, std::vector<Color> colorSpectrum, Color &color);
|
||||||
|
void AngularVelocityInterpolation(double timeProgress, std::vector<float> spectrum, float &angularVelocity);
|
||||||
void Billboard();
|
void Billboard();
|
||||||
std::map<EntityID, std::list<ParticleData>> m_ParticleEmitter;
|
std::map<EntityID, std::list<ParticleData>> m_ParticleEmitter;
|
||||||
std::map<EntityID, double> m_TimeSinceLastSpawn;
|
std::map<EntityID, double> m_TimeSinceLastSpawn;
|
||||||
|
|||||||
Reference in New Issue
Block a user