|
|
|
@@ -46,17 +46,34 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//FIX: calculate once
|
|
|
|
|
// FIX: calculate once
|
|
|
|
|
float timeProgress = timeLived / particleComponent->LifeTime;
|
|
|
|
|
//ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color);
|
|
|
|
|
// ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color);
|
|
|
|
|
// Scale interpolation
|
|
|
|
|
if(particleComponent->ScaleSpectrum.size() > 1)
|
|
|
|
|
ScaleInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale);
|
|
|
|
|
VectorInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale);
|
|
|
|
|
// Velocity interpolation
|
|
|
|
|
if(particleComponent->VelocitySpectrum.size() > 1)
|
|
|
|
|
VelocityInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity);
|
|
|
|
|
VectorInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity);
|
|
|
|
|
// Angular velocity interpolation
|
|
|
|
|
if(particleComponent->AngularVelocitySpectrum.size() > 1)
|
|
|
|
|
AngularVelocityInterpolation(timeProgress, particleComponent->AngularVelocitySpectrum, it->AngularVelocity);
|
|
|
|
|
ScalarInterpolation(timeProgress, particleComponent->AngularVelocitySpectrum, it->AngularVelocity);
|
|
|
|
|
//Angular velocity interpolation
|
|
|
|
|
if(particleComponent->OrientationSpectrum.size() > 1)
|
|
|
|
|
VectorInterpolation(timeProgress, particleComponent->OrientationSpectrum, it->Orientation);
|
|
|
|
|
|
|
|
|
|
transformComponent->Orientation *= glm::angleAxis(it->AngularVelocity, glm::vec3(0, 0, 1));
|
|
|
|
|
// glm::vec3 v1 = particleComponent->OrientationSpectrum[0];
|
|
|
|
|
// glm::vec3 v2 = it->Orientation;
|
|
|
|
|
// glm::vec3 v3 = glm::normalize(glm::cross(v1,v2));
|
|
|
|
|
// float angle = glm::acos(glm::dot(v1, v2) / glm::length(v1) * glm::length(v2));
|
|
|
|
|
// float s = sin(angle / 2);
|
|
|
|
|
// transformComponent->Orientation.x = v3.x * s;
|
|
|
|
|
// transformComponent->Orientation.y = v3.y * s;
|
|
|
|
|
// transformComponent->Orientation.z = v3.z * s;
|
|
|
|
|
// transformComponent->Orientation.w = glm::cos(angle/2);
|
|
|
|
|
|
|
|
|
|
//float alpha = it->AngularVelocity * dt;
|
|
|
|
|
//transformComponent->Orientation = transformComponent->Orientation * it->Orientation;
|
|
|
|
|
transformComponent->Position += transformComponent->Velocity * (float)dt;
|
|
|
|
|
|
|
|
|
|
it++;
|
|
|
|
@@ -89,7 +106,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
|
|
|
|
particleTransform->Position = emitterTransform->Position;
|
|
|
|
|
particleTransform->Scale = glm::vec3(1, 1, 1);
|
|
|
|
|
|
|
|
|
|
//The emitter's orientation as "start value" times the default direction for quaternion. Times the speed, and then rotate on x and y axis with the randomized spread angle.
|
|
|
|
|
//The emitter's orientation as "start value" times the default direction for emitter. Times the speed, and then rotate on x and y axis with the randomized spread angle.
|
|
|
|
|
float spreadAngle = emitterComponent->SpreadAngle;
|
|
|
|
|
particleTransform->Velocity = emitterOrientation * glm::vec3(0, 0, -1) * speed *
|
|
|
|
|
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(1, 0, 0))) *
|
|
|
|
@@ -100,12 +117,13 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
|
|
|
|
|
|
|
|
|
auto particle = m_World->AddComponent<Components::Particle>(ent, "Particle");
|
|
|
|
|
particle->LifeTime = emitterComponent->LifeTime;
|
|
|
|
|
particle->ScaleSpectrum.push_back(1); //TEMP
|
|
|
|
|
particle->ScaleSpectrum.push_back(1); //TEMP
|
|
|
|
|
particle->ScaleSpectrum.push_back(glm::vec3(1)); //TEMP
|
|
|
|
|
//particle->ScaleSpectrum.push_back(glm::vec3(1,4,1)); //TEMP
|
|
|
|
|
particle->VelocitySpectrum.push_back(particleTransform->Velocity); //TEMP
|
|
|
|
|
particle->VelocitySpectrum.push_back(testVel); //TEMP
|
|
|
|
|
//particle->AngularVelocitySpectrum.push_back(0.f);
|
|
|
|
|
particle->AngularVelocitySpectrum.push_back(-glm::pi<float>()/10);
|
|
|
|
|
// particle->AngularVelocitySpectrum.push_back(0.f);
|
|
|
|
|
// particle->AngularVelocitySpectrum.push_back(-glm::pi<float>());
|
|
|
|
|
particle->OrientationSpectrum = particle->VelocitySpectrum;
|
|
|
|
|
|
|
|
|
|
// Color startColor = {.4f, .45f, .2f};
|
|
|
|
|
// particle->ColorSpectrum.push_back(startColor);
|
|
|
|
@@ -117,7 +135,8 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
|
|
|
|
ParticleData data;
|
|
|
|
|
data.ParticleID = ent;
|
|
|
|
|
data.SpawnTime = glfwGetTime();
|
|
|
|
|
data.AngularVelocity = particle->AngularVelocitySpectrum[0];
|
|
|
|
|
//data.AngularVelocity = particle->AngularVelocitySpectrum[0];
|
|
|
|
|
data.Orientation = particle->OrientationSpectrum[0];
|
|
|
|
|
|
|
|
|
|
m_ParticleEmitter[emitterID].push_back(data);
|
|
|
|
|
}
|
|
|
|
@@ -129,47 +148,37 @@ float Systems::ParticleSystem::RandomizeAngle(float spreadAngle)
|
|
|
|
|
return ((float)rand() / ((float)RAND_MAX + 1) * spreadAngle) - spreadAngle/2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Interpolates the scale of the particle
|
|
|
|
|
void Systems::ParticleSystem::ScaleInterpolation(double timeProgress, std::vector<float> spectrum, glm::vec3 &s)
|
|
|
|
|
{
|
|
|
|
|
float dScale = glm::abs(spectrum[0] - spectrum[1]);
|
|
|
|
|
if(spectrum[0] > spectrum[1])
|
|
|
|
|
dScale *= -1;
|
|
|
|
|
s = glm::vec3(spectrum[0] + dScale * timeProgress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Interpolates the velocity of the particle
|
|
|
|
|
void Systems::ParticleSystem::VelocityInterpolation(double timeProgress, std::vector<glm::vec3> spectrum, glm::vec3 &v)
|
|
|
|
|
void Systems::ParticleSystem::VectorInterpolation(double timeProgress, std::vector<glm::vec3> spectrum, glm::vec3 &v)
|
|
|
|
|
{
|
|
|
|
|
float dVelocity = glm::abs(spectrum[0].x - spectrum[1].x);
|
|
|
|
|
float dAxisValue = glm::abs(spectrum[0].x - spectrum[1].x);
|
|
|
|
|
if(spectrum[0].x > spectrum[1].x)
|
|
|
|
|
dVelocity *= -1;
|
|
|
|
|
v.x = spectrum[0].x + dVelocity * timeProgress;
|
|
|
|
|
dVelocity = glm::abs(spectrum[0].y - spectrum[1].y);
|
|
|
|
|
dAxisValue *= -1;
|
|
|
|
|
v.x = spectrum[0].x + dAxisValue * timeProgress;
|
|
|
|
|
dAxisValue = glm::abs(spectrum[0].y - spectrum[1].y);
|
|
|
|
|
if (spectrum[0].y > spectrum[1].y)
|
|
|
|
|
dVelocity *= -1;
|
|
|
|
|
v.y = spectrum[0].y + dVelocity * timeProgress;
|
|
|
|
|
dVelocity = glm::abs(spectrum[0].z - spectrum[1].z);
|
|
|
|
|
dAxisValue *= -1;
|
|
|
|
|
v.y = spectrum[0].y + dAxisValue * timeProgress;
|
|
|
|
|
dAxisValue = glm::abs(spectrum[0].z - spectrum[1].z);
|
|
|
|
|
if(spectrum[0].z > spectrum[1].z)
|
|
|
|
|
dVelocity *= -1;
|
|
|
|
|
v.z = spectrum[0].z + dVelocity * timeProgress;
|
|
|
|
|
dAxisValue *= -1;
|
|
|
|
|
v.z = spectrum[0].z + dAxisValue * timeProgress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Systems::ParticleSystem::ColorInterpolation(double timeProgress, std::vector<Color> spectrum, Color &c)
|
|
|
|
|
{
|
|
|
|
|
float dColor = glm::abs(spectrum[0].r - spectrum[1].r);
|
|
|
|
|
c.r = spectrum[0].r + dColor * timeProgress;
|
|
|
|
|
dColor = glm::abs(spectrum[0].g - spectrum[1].g);
|
|
|
|
|
c.g = spectrum[0].g + dColor * timeProgress;
|
|
|
|
|
dColor = glm::abs(spectrum[0].b - spectrum[1].b);
|
|
|
|
|
c.b = spectrum[0].b + dColor * timeProgress;
|
|
|
|
|
}
|
|
|
|
|
// void Systems::ParticleSystem::ColorInterpolation(double timeProgress, std::vector<Color> spectrum, Color &c)
|
|
|
|
|
// {
|
|
|
|
|
// float dColor = glm::abs(spectrum[0].r - spectrum[1].r);
|
|
|
|
|
// c.r = spectrum[0].r + dColor * timeProgress;
|
|
|
|
|
// dColor = glm::abs(spectrum[0].g - spectrum[1].g);
|
|
|
|
|
// c.g = spectrum[0].g + dColor * timeProgress;
|
|
|
|
|
// dColor = glm::abs(spectrum[0].b - spectrum[1].b);
|
|
|
|
|
// c.b = spectrum[0].b + dColor * timeProgress;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
void Systems::ParticleSystem::AngularVelocityInterpolation(double timeProgress, std::vector<float> spectrum, float &alpha)
|
|
|
|
|
void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vector<float> spectrum, float &alpha)
|
|
|
|
|
{
|
|
|
|
|
float dAlpha = glm::abs(spectrum[0] - spectrum[1]);
|
|
|
|
|
if(spectrum[0] > spectrum[1])
|
|
|
|
|
dAlpha *= -1;
|
|
|
|
|
alpha = spectrum[0] + dAlpha * timeProgress;
|
|
|
|
|
|
|
|
|
|
}
|