Made Interpolation functions look nicer
This commit is contained in:
@@ -24,7 +24,6 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
if(emitterComponent)
|
if(emitterComponent)
|
||||||
{
|
{
|
||||||
emitterComponent->TimeSinceLastSpawn += dt;
|
emitterComponent->TimeSinceLastSpawn += dt;
|
||||||
|
|
||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
|
if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
|
||||||
{
|
{
|
||||||
@@ -47,7 +46,6 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
//FIX: calculate once
|
//FIX: calculate once
|
||||||
float timeProgress = timeLived / particleComponent->LifeTime;
|
float timeProgress = timeLived / particleComponent->LifeTime;
|
||||||
//ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color);
|
//ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color);
|
||||||
@@ -132,46 +130,46 @@ float Systems::ParticleSystem::RandomizeAngle(float spreadAngle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Interpolates the scale of the particle
|
//Interpolates the scale of the particle
|
||||||
void Systems::ParticleSystem::ScaleInterpolation(double timeProgress, std::vector<float> scaleSpectrum, glm::vec3 &scale)
|
void Systems::ParticleSystem::ScaleInterpolation(double timeProgress, std::vector<float> spectrum, glm::vec3 &s)
|
||||||
{
|
{
|
||||||
float deltaScale = glm::abs(scaleSpectrum[0] - scaleSpectrum[1]);
|
float dScale = glm::abs(spectrum[0] - spectrum[1]);
|
||||||
if(scaleSpectrum[0] > scaleSpectrum[1])
|
if(spectrum[0] > spectrum[1])
|
||||||
deltaScale *= -1;
|
dScale *= -1;
|
||||||
scale = glm::vec3(scaleSpectrum[0] + deltaScale * timeProgress);
|
s = glm::vec3(spectrum[0] + dScale * timeProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Interpolates the velocity of the particle
|
//Interpolates the velocity of the particle
|
||||||
void Systems::ParticleSystem::VelocityInterpolation(double timeProgress, std::vector<glm::vec3> velocitySpectrum, glm::vec3 &velocity)
|
void Systems::ParticleSystem::VelocityInterpolation(double timeProgress, std::vector<glm::vec3> spectrum, glm::vec3 &v)
|
||||||
{
|
{
|
||||||
float deltaVelocity = glm::abs(velocitySpectrum[0].x - velocitySpectrum[1].x);
|
float dVelocity = glm::abs(spectrum[0].x - spectrum[1].x);
|
||||||
if(velocitySpectrum[0].x > velocitySpectrum[1].x)
|
if(spectrum[0].x > spectrum[1].x)
|
||||||
deltaVelocity *= -1;
|
dVelocity *= -1;
|
||||||
velocity.x = velocitySpectrum[0].x + deltaVelocity * timeProgress;
|
v.x = spectrum[0].x + dVelocity * timeProgress;
|
||||||
deltaVelocity = glm::abs(velocitySpectrum[0].y - velocitySpectrum[1].y);
|
dVelocity = glm::abs(spectrum[0].y - spectrum[1].y);
|
||||||
if (velocitySpectrum[0].y > velocitySpectrum[1].y)
|
if (spectrum[0].y > spectrum[1].y)
|
||||||
deltaVelocity *= -1;
|
dVelocity *= -1;
|
||||||
velocity.y = velocitySpectrum[0].y + deltaVelocity * timeProgress;
|
v.y = spectrum[0].y + dVelocity * timeProgress;
|
||||||
deltaVelocity = glm::abs(velocitySpectrum[0].z - velocitySpectrum[1].z);
|
dVelocity = glm::abs(spectrum[0].z - spectrum[1].z);
|
||||||
if(velocitySpectrum[0].z > velocitySpectrum[1].z)
|
if(spectrum[0].z > spectrum[1].z)
|
||||||
deltaVelocity *= -1;
|
dVelocity *= -1;
|
||||||
velocity.z = velocitySpectrum[0].z + deltaVelocity * timeProgress;
|
v.z = spectrum[0].z + dVelocity * timeProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::ParticleSystem::ColorInterpolation(double timeProgress, std::vector<Color> colorSpectrum, Color &color)
|
void Systems::ParticleSystem::ColorInterpolation(double timeProgress, std::vector<Color> spectrum, Color &c)
|
||||||
{
|
{
|
||||||
float deltaColor = glm::abs(colorSpectrum[0].r - colorSpectrum[1].r);
|
float dColor = glm::abs(spectrum[0].r - spectrum[1].r);
|
||||||
color.r = colorSpectrum[0].r + deltaColor * timeProgress;
|
c.r = spectrum[0].r + dColor * timeProgress;
|
||||||
deltaColor = glm::abs(colorSpectrum[0].g - colorSpectrum[1].g);
|
dColor = glm::abs(spectrum[0].g - spectrum[1].g);
|
||||||
color.g = colorSpectrum[0].g + deltaColor * timeProgress;
|
c.g = spectrum[0].g + dColor * timeProgress;
|
||||||
deltaColor = glm::abs(colorSpectrum[0].b - colorSpectrum[1].b);
|
dColor = glm::abs(spectrum[0].b - spectrum[1].b);
|
||||||
color.b = colorSpectrum[0].b + deltaColor * timeProgress;
|
c.b = spectrum[0].b + dColor * timeProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::ParticleSystem::AngularVelocityInterpolation(double timeProgress, std::vector<float> spectrum, float &angularVelocity)
|
void Systems::ParticleSystem::AngularVelocityInterpolation(double timeProgress, std::vector<float> spectrum, float &alpha)
|
||||||
{
|
{
|
||||||
float deltaAngularVelocity = glm::abs(spectrum[0] - spectrum[1]);
|
float dAlpha = glm::abs(spectrum[0] - spectrum[1]);
|
||||||
if(spectrum[0] > spectrum[1])
|
if(spectrum[0] > spectrum[1])
|
||||||
deltaAngularVelocity *= -1;
|
dAlpha *= -1;
|
||||||
angularVelocity = spectrum[0] + deltaAngularVelocity * timeProgress;
|
alpha = spectrum[0] + dAlpha * timeProgress;
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user