diff --git a/Engine/Source/Editor/UILayers/EntityList.cpp b/Engine/Source/Editor/UILayers/EntityList.cpp index 03b10e8c..e33c859b 100644 --- a/Engine/Source/Editor/UILayers/EntityList.cpp +++ b/Engine/Source/Editor/UILayers/EntityList.cpp @@ -223,6 +223,10 @@ void EntityList::AddEntity(engine::SceneWorld* pSceneWorld) engine::Entity entity = AddNamedEntity("ParticleEmitter"); auto& particleEmitterComponent = pWorld->CreateComponent(entity); // TODO : Some initialization here. + + engine::ParticleSystem particles; + particles.Init(); + particleEmitterComponent.SetParticleSystem(particles); } } diff --git a/Engine/Source/Runtime/ECWorld/ParticleEmitterComponent.h b/Engine/Source/Runtime/ECWorld/ParticleEmitterComponent.h index a0a6d636..5feba549 100644 --- a/Engine/Source/Runtime/ECWorld/ParticleEmitterComponent.h +++ b/Engine/Source/Runtime/ECWorld/ParticleEmitterComponent.h @@ -25,7 +25,7 @@ class ParticleEmitterComponent final ParticleEmitterComponent& operator=(ParticleEmitterComponent&&) = default; ~ParticleEmitterComponent() = default; - engine::ParticleSystem GetParticleSystem() { return m_particleSystem; } + engine::ParticleSystem &GetParticleSystem() { return m_particleSystem; } void SetParticleSystem(engine::ParticleSystem& system) { m_particleSystem = system; } uint16_t& GetParticleVBH(){ return m_particleVBH; } diff --git a/Engine/Source/Runtime/ParticleSystem/ParticleSystem.cpp b/Engine/Source/Runtime/ParticleSystem/ParticleSystem.cpp index 172530cf..54f979ca 100644 --- a/Engine/Source/Runtime/ParticleSystem/ParticleSystem.cpp +++ b/Engine/Source/Runtime/ParticleSystem/ParticleSystem.cpp @@ -33,7 +33,7 @@ void engine::ParticleSystem::AllocateParticleIndex() void engine::ParticleSystem::Reset(int index) { m_pos[index] = cd::Vec3f(0.0f, 0.0f, 0.0f); - m_velocity[index] = cd::Vec3f(rand() % 41, 0.0f, 0.0f); + m_velocity[index] = cd::Vec3f(rand() % 41, rand() % 7, rand() % 50); m_acceleration[index] = cd::Vec3f(0.0f, 0.0f, 0.0f); m_color[index] = cd::Vec3f{rand() %30, rand() %45,0.0f}; diff --git a/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp b/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp index 3bdcfa79..cb194ba9 100644 --- a/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp @@ -25,15 +25,10 @@ void ParticleRenderer::Render(float deltaTime) for (Entity entity : m_pCurrentSceneWorld->GetParticleEmitterEntities()) { engine::ParticleEmitterComponent* pEmitterComponent = m_pCurrentSceneWorld->GetParticleEmitterComponent(entity); + pEmitterComponent->GetParticleSystem().AllocateParticleIndex(); + pEmitterComponent->GetParticleSystem().UpdateActive(1 / deltaTime); - engine::ParticleSystem particles; - particles.Init(); - particles.AllocateParticleIndex(); - particles.UpdateActive(1/deltaTime); - - pEmitterComponent->SetParticleSystem(particles); pEmitterComponent->Build(); - bgfx::setVertexBuffer(0, bgfx::VertexBufferHandle{ pEmitterComponent->GetParticleVBH() }); bgfx::setIndexBuffer(bgfx::IndexBufferHandle{ pEmitterComponent->GetParticleIBH() });