Added models and temporary "fly everywhere" direction to particles

This commit is contained in:
Stiffly
2014-04-24 00:00:29 +02:00
parent 07bc49e3c1
commit 5997ee2320
4 changed files with 30 additions and 18 deletions
-2
View File
@@ -3,8 +3,6 @@
#include "System.h" #include "System.h"
#include "Component.h" #include "Component.h"
#include "Components/Transform.h"
#include "Components/ParticleEmitter.h"
#include "Color.h" #include "Color.h"
#include <vector> #include <vector>
+2 -2
View File
@@ -98,9 +98,9 @@ void GameWorld::Initialize()
transform->Position = glm::vec3(0); transform->Position = glm::vec3(0);
auto emitter = AddComponent<Components::ParticleEmitter>(ent, "ParticleEmitter"); auto emitter = AddComponent<Components::ParticleEmitter>(ent, "ParticleEmitter");
emitter->LifeTime = 4; emitter->LifeTime = 4;
emitter->SpawnCount = 3; emitter->SpawnCount = 1;
emitter->SpreadAngle = 35; emitter->SpreadAngle = 35;
emitter->SpawnFrequency = 0.01; emitter->SpawnFrequency = 0.05;
//emitter-> //emitter->
} }
} }
+26 -14
View File
@@ -25,31 +25,37 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
{ {
if(m_TimeSinceLastSpawn > emitterComponent->SpawnFrequency) if(m_TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
{ {
if(m_ParticleEmitter[entity].size() < 100) //if(m_ParticleEmitter[entity].size() < 100) // TEMP
{ {
SpawnParticles(entity, emitterComponent->SpawnCount, emitterComponent->SpreadAngle); SpawnParticles(entity, emitterComponent->SpawnCount, emitterComponent->SpreadAngle);
m_TimeSinceLastSpawn = 0; m_TimeSinceLastSpawn = 0;
} }
std::cout<<"Particle count: "<<m_ParticleEmitter[entity].size()<<std::endl; //std::cout<<"Particle count: "<<m_ParticleEmitter[entity].size()<<std::endl; // TEMP
} }
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(); it++)
{ {
auto particleComponent = m_World->GetComponent<Components::Particle>(it->ParticleID, "Particle"); EntityID particleID = it->ParticleID;
auto particleComponent = m_World->GetComponent<Components::Particle>(particleID, "Particle");
double timeLived = glfwGetTime() - it->SpawnTime; double timeLived = glfwGetTime() - it->SpawnTime;
if(timeLived > particleComponent->LifeTime) if(timeLived > particleComponent->LifeTime)
{ {
m_ParticleEmitter[entity].erase(it); m_ParticleEmitter[entity].erase(it);
std::cout<<"Removed dead particle..."<<std::endl; //std::cout<<"Removed dead particle..."<<std::endl; // TEMP
break; break;
} }
else /*else
{ {
it++; it++;
} }*/
auto transformComponent = m_World->GetComponent<Components::Transform>(particleID, "Transform");
float speed = 10 * dt;
transformComponent->Position.x += it->Direction.x * speed;
transformComponent->Position.y += it->Direction.y * speed;
transformComponent->Position.z += it->Direction.z * speed;
// Interpolates the color for each color channel by the start and end value. Decides how much the color should be interpolated based on time. // Interpolates the color for each color channel by the start and end value. Decides how much the color should be interpolated based on time.
/*// How big fraction the color is multiplied with /*// How big fraction the color is multiplied with
@@ -90,24 +96,30 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID, float spawnCoun
auto ent = m_World->CreateEntity(); auto ent = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(ent, "Transform"); auto transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(0); transform->Position = glm::vec3(0, 20, 0);
transform->Scale = glm::vec3(1, 1, 0);
auto particle = m_World->AddComponent<Components::Particle>(ent, "Particle"); auto particle = m_World->AddComponent<Components::Particle>(ent, "Particle");
particle->LifeTime = 4; particle->LifeTime = 4;
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, -.2, 0));
particle->VelocitySpectrum.push_back(glm::vec3(0, -3, 0)); particle->VelocitySpectrum.push_back(glm::vec3(0, -3, 0));*/
auto model = m_World->AddComponent<Components::Model>(ent, "Model");
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj";
ParticleData data; ParticleData data;
data.ParticleID = ent; data.ParticleID = ent;
data.SpawnTime = glfwGetTime(); data.SpawnTime = glfwGetTime();
data.color = particle->ColorSpectrum[0]; // data.color = particle->ColorSpectrum[0];
data.Scale = particle->ScaleSpectrum[0]; // data.Scale = particle->ScaleSpectrum[0];
data.Direction = glm::vec3(((double)rand() / ((double)RAND_MAX + 1) * 2) -1, ((double)rand() / ((double)RAND_MAX + 1) * 2) -1, ((double)rand() / ((double)RAND_MAX + 1) * 2) -1);
data.Direction = glm::normalize(data.Direction);
m_ParticleEmitter[emitterID].push_back(data); m_ParticleEmitter[emitterID].push_back(data);
} }
+2
View File
@@ -5,6 +5,7 @@
#include "Components/Transform.h" #include "Components/Transform.h"
#include "Components/ParticleEmitter.h" #include "Components/ParticleEmitter.h"
#include "Components/Particle.h" #include "Components/Particle.h"
#include "Components/Model.h"
#include "Color.h" #include "Color.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@@ -18,6 +19,7 @@ namespace Systems
float Scale; float Scale;
Color color; Color color;
glm::vec3 Velocity; glm::vec3 Velocity;
glm::vec3 Direction;
}; };
class ParticleSystem : public System class ParticleSystem : public System