Particle system up and running, but with bugged rendering

This commit is contained in:
tleety
2015-10-01 14:14:51 +02:00
parent 2491dd8b74
commit 52dec86925
6 changed files with 306 additions and 72 deletions
+46 -16
View File
@@ -52,6 +52,8 @@
#include "Physics/CRectangleShape.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CWaterVolume.h"
#include "Physics/CParticle.h"
#include "Physics/CParticleEmitter.h"
#include "Game/EGameStart.h"
#include "Sound/EPlaySound.h"
@@ -129,6 +131,8 @@ public:
m_World->ComponentFactory.Register<Components::Template>();
m_World->ComponentFactory.Register<Components::PointLight>();
m_World->ComponentFactory.Register<Components::WaterVolume>();
m_World->ComponentFactory.Register<Components::Particle>();
m_World->ComponentFactory.Register<Components::ParticleEmitter>();
m_World->Initialize();
@@ -165,7 +169,7 @@ public:
pl->Radius = 20.f;
pl->Diffuse = glm::vec3(0.8f, 0.7f, 0.05f);
auto model = m_World->AddComponent<Components::Model>(t_Light);
model->ModelFile = "Core/UnitSphere.obj";
model->ModelFile = "Models/Core/UnitSphere.obj";
m_World->CommitEntity(t_Light);
}
{
@@ -176,7 +180,7 @@ public:
pl->Radius = 15.f;
pl->Diffuse = glm::vec3(0.1f, 0.5f, 0.8f);
auto model = m_World->AddComponent<Components::Model>(t_Light);
model->ModelFile = "Core/UnitSphere.obj";
model->ModelFile = "Models/Core/UnitSphere.obj";
m_World->CommitEntity(t_Light);
}
@@ -188,7 +192,7 @@ public:
transform->Scale = glm::vec3(6.f, 6.f, 10.f);
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
model->Color = glm::vec4(1.f, 1.f, 1.f, 0.3f);
model->Color = glm::vec4(1.f, 0.f, 0.f, 0.3f);
m_World->CommitEntity(t_halfPipe);
}
@@ -203,16 +207,44 @@ public:
m_World->CommitEntity(background);
}
//Water test
{
auto t_waterBody = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
transform->Position = glm::vec3(0.f, -0.5f, -10.f);
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
auto water = m_World->AddComponent<Components::WaterVolume>(t_waterBody);
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
m_World->CommitEntity(t_waterBody);
}
//ParticleTest
// {
// auto Pe = m_World->CreateEntity();
// auto transform = m_World->AddComponent<Components::Transform>(Pe);
// auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(Pe);
//
// transform->Position = glm::vec3(0.f, -5.f, -10.f);
// particleEmitter->GravityScale = 0.0f;
// particleEmitter->SpawnRate = 1.0f;
//
// {
// auto Pt = m_World->CreateEntity(Pe);
// auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
// auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
// //auto PtModel = m_World->AddComponent<Components::Model>(Pt);
// auto PtParticle = m_World->AddComponent<Components::Particle>(Pt);
// auto PtTemplate = m_World->AddComponent<Components::Template>(Pt);
//
// PtTransform->Velocity = glm::vec3(1.0f, 0.f, 0.f);
// PtTransform->Position = transform->Position;
// PtSprite->SpriteFile = "Textures/Ball.png";
//
// //PtModel->ModelFile = "Models/Brick/Brick.obj";
// PtParticle->LifeTime = 1000.f;
// PtParticle->Flags = ParticleFlags::Type::powderParticle;
// }
// m_World->CommitEntity(Pe);
// }
// {
// auto Pt = m_World->CreateEntity();
// auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
// auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
//
// PtTransform->Position = glm::vec3(2.f, 0.f, -10.f);
// PtSprite->SpriteFile = "Textures/Ball.png";
// }
//Water test
{
auto t_waterBody = m_World->CreateEntity();
@@ -371,7 +403,7 @@ public:
// Swap event queues to get fresh input data in the read queue
//m_EventBroker->Swap();
ResourceManager::Update();
//ResourceManager::Update();
if (m_GameIsRunning) {
m_World->Update(dt);
}
@@ -460,7 +492,6 @@ public:
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
if (spriteComponent)
{
std::string normal = spriteComponent->NormalTexture;
std::string spec = spriteComponent->SpecularTexture;
@@ -483,7 +514,6 @@ public:
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
}
}
}
//TODO: Get this out of engine.h
+65
View File
@@ -0,0 +1,65 @@
#ifndef COMPONENTS_PARTICLE_H__
#define COMPONENTS_PARTICLE_H__
#include "Core/Component.h"
namespace dd {
namespace ParticleFlags {
enum Type {
waterParticle = 0,
zombieParticle = 1 << 1,
wallParticle = 1 << 2,
springParticle = 1 << 3,
elasticParticle = 1 << 4,
viscousParticle = 1 << 5,
powderParticle = 1 << 6,
tensileParticle = 1 << 7,
colorMixingParticle = 1 << 8,
destructionListenerParticle = 1 << 9,
barrierParticle = 1 << 10,
staticPressureParticle = 1 << 11,
reactiveParticle = 1 << 12,
repulsiveParticle = 1 << 13,
fixtureContactListenerParticle = 1 << 14,
particleContactListenerParticle = 1 << 15,
fixtureContactFilterParticle = 1 << 16,
particleContactFilterParticle = 1 << 17
};
}
namespace Components
{
struct Particle : public Component
{
float Radius = 0.5f;
float LifeTime = 5.0f;
ParticleFlags::Type Flags =
ParticleFlags::Type::waterParticle |
ParticleFlags::Type::zombieParticle |
ParticleFlags::Type::wallParticle |
ParticleFlags::Type::springParticle |
ParticleFlags::Type::elasticParticle |
ParticleFlags::Type::viscousParticle |
ParticleFlags::Type::powderParticle |
ParticleFlags::Type::tensileParticle |
ParticleFlags::Type::colorMixingParticle |
ParticleFlags::Type::destructionListenerParticle |
ParticleFlags::Type::barrierParticle |
ParticleFlags::Type::staticPressureParticle |
ParticleFlags::Type::reactiveParticle |
ParticleFlags::Type::repulsiveParticle |
ParticleFlags::Type::fixtureContactListenerParticle |
ParticleFlags::Type::particleContactListenerParticle |
ParticleFlags::Type::fixtureContactFilterParticle |
ParticleFlags::Type::particleContactFilterParticle;
};
}
}
#endif
+25
View File
@@ -0,0 +1,25 @@
#ifndef COMPONENTS_PARTICLEEMITTER_H__
#define COMPONENTS_PARTICLEEMITTER_H__
#include "Core/Component.h"
namespace dd
{
namespace Components
{
struct ParticleEmitter : public Component
{
int Amount = 10.f;
float InitialSpeed = 1.f;
double SpawnRate = 1.f;
double TimeSinceLastSpawn = 0;
//ParticleSystem variables
float GravityScale = 1.0f;
};
}
}
#endif
+18 -4
View File
@@ -18,6 +18,9 @@
#include "Physics/CWaterVolume.h"
#include "Game/CBall.h"
#include "Rendering/CSprite.h"
#include "Physics/CParticle.h"
#include "Physics/CParticleEmitter.h"
#include "Core/CTemplate.h"
namespace dd
@@ -66,18 +69,29 @@ private:
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
void CreateBody(EntityID entity);
void CreateParticleSystem(float radius);
std::vector<b2ParticleSystem*> m_ParticleSystem;
std::vector<b2ParticleGroup*> t_ParticleGroup;
std::unordered_map<EntityID, const b2ParticleHandle*> m_EntitiesToParticleHandle;
std::unordered_map<const b2ParticleHandle*, EntityID> m_ParticleHandleToEntities;
std::vector<std::unordered_map<EntityID, const b2ParticleHandle*>> m_EntitiesToParticleHandle;
std::vector<std::unordered_map<const b2ParticleHandle*, EntityID>> m_ParticleHandleToEntities;
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale);
void InitializeWater();
void SyncWater(); //TODO: Probably remove this
void CreateParticleGroup(EntityID entity);
void CreateParticleEmitter(EntityID entity);
void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed.
//TODO: Fill struct with info needed.
struct ParticleEmitter
{
std::vector<b2ParticleSystem*> ParticleSystem;
std::vector<EntityID> ParticleEmitter;
std::vector<EntityID> ParticleTemplate;
};
ParticleEmitter m_ParticleEmitters;
//TODO: Struct med listor är bättre än en lista med structs
struct Impulse
{
b2Body* Body;