mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-21 20:08:40 +03:00
Added simple radius gizmo
This commit is contained in:
@@ -40,6 +40,15 @@ public:
|
||||
ComponentTableReset(component.Amount, 10.0f);
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Rate");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##ParticleRate", &component.Rate, 0.1f, 0.0f, 10.0f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.Rate, 0.0f);
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Life");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <src/Scene/Components/CylinderColliderComponent.h>
|
||||
#include <src/Scene/Components/MeshCollider.h>
|
||||
#include <src/Scene/Components/ModelComponent.h>
|
||||
#include <src/Scene/Components/ParticleEmitterComponent.h>
|
||||
|
||||
|
||||
GizmoDrawer::GizmoDrawer()
|
||||
@@ -217,6 +218,18 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene)
|
||||
Nuake::RenderCommand::DrawLines(0, 264);
|
||||
}
|
||||
|
||||
auto particleView = scene->m_Registry.view<TransformComponent, ParticleEmitterComponent>();
|
||||
for (auto e : particleView)
|
||||
{
|
||||
auto [transform, particle] = scene->m_Registry.get<TransformComponent, ParticleEmitterComponent>(e);
|
||||
mLineShader->Bind();
|
||||
mLineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), transform.Translation), Vector3(particle.Radius)));
|
||||
mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
|
||||
mCircleBuffer->Bind();
|
||||
Nuake::RenderCommand::DrawLines(0, 128);
|
||||
}
|
||||
|
||||
auto meshColliderView = scene->m_Registry.view<TransformComponent, MeshColliderComponent, ModelComponent>();
|
||||
for (auto e : meshColliderView)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Nuake
|
||||
SERIALIZE_VEC4(ParticleColor);
|
||||
SERIALIZE_VAL(Amount);
|
||||
SERIALIZE_VAL(Life);
|
||||
SERIALIZE_VAL(Rate);
|
||||
SERIALIZE_VEC3(Gravity);
|
||||
SERIALIZE_VAL(GravityRandom);
|
||||
SERIALIZE_VAL(Radius);
|
||||
@@ -20,6 +21,10 @@ namespace Nuake
|
||||
DESERIALIZE_VEC4(j["ParticleColor"], ParticleColor);
|
||||
Amount = j["Amount"];
|
||||
Life = j["Life"];
|
||||
if (j.contains("Rate"))
|
||||
{
|
||||
Rate = j["Rate"];
|
||||
}
|
||||
DESERIALIZE_VEC3(j["Gravity"], Gravity);
|
||||
GravityRandom = j["GravityRandom"];
|
||||
Radius = j["Radius"];
|
||||
|
||||
@@ -16,7 +16,8 @@ namespace Nuake
|
||||
|
||||
Color ParticleColor;
|
||||
float Amount;
|
||||
float Life;
|
||||
float Life = 1.0f;
|
||||
float Rate = 0.0f;
|
||||
|
||||
Vector3 Gravity;
|
||||
float GravityRandom;
|
||||
|
||||
@@ -77,10 +77,10 @@ namespace Nuake {
|
||||
|
||||
Entity Scene::GetEntityByID(int id)
|
||||
{
|
||||
if (m_EntitiesIDMap.find(id) != m_EntitiesIDMap.end())
|
||||
{
|
||||
return m_EntitiesIDMap[id];
|
||||
}
|
||||
//if (m_EntitiesIDMap.find(id) != m_EntitiesIDMap.end())
|
||||
//{
|
||||
// return m_EntitiesIDMap[id];
|
||||
//}
|
||||
|
||||
auto idView = m_Registry.view<NameComponent>();
|
||||
for (auto e : idView)
|
||||
|
||||
@@ -5,7 +5,12 @@ namespace Nuake
|
||||
ParticleEmitter::ParticleEmitter()
|
||||
{
|
||||
m_MT = std::mt19937(std::random_device()());
|
||||
m_Random = std::uniform_real_distribution<float>(-Radius, Radius);
|
||||
SetRadius(1.0f);
|
||||
}
|
||||
|
||||
void ParticleEmitter::RecreateRandom()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ParticleEmitter::SpawnParticle()
|
||||
@@ -16,21 +21,31 @@ namespace Nuake
|
||||
return;
|
||||
}
|
||||
|
||||
const auto initialPosition = Vector3(m_Random(m_MT), m_Random(m_MT), m_Random(m_MT));
|
||||
const auto initialVelocity = Vector3();
|
||||
const auto initialColor = Color(1, 0, 0, 1); // TODO: Use color.
|
||||
const float initialLife = Life;
|
||||
if (Rate == 0.0f || RateTimer > Rate)
|
||||
{
|
||||
const auto initialPosition = Vector3(m_Random(m_MT), m_Random(m_MT), m_Random(m_MT));
|
||||
const auto initialVelocity = Vector3();
|
||||
const auto initialColor = ParticleColor;
|
||||
const float initialLife = Life;
|
||||
|
||||
Particles.push_back({
|
||||
initialPosition,
|
||||
initialVelocity,
|
||||
initialColor,
|
||||
initialLife
|
||||
});
|
||||
Particles.push_back({
|
||||
initialPosition,
|
||||
initialVelocity,
|
||||
initialColor,
|
||||
initialLife
|
||||
});
|
||||
|
||||
RateTimer = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleEmitter::Update(Timestep ts)
|
||||
{
|
||||
if (Rate != 0.0f)
|
||||
{
|
||||
RateTimer += ts;
|
||||
}
|
||||
|
||||
std::vector<uint32_t> deletionQueue;
|
||||
int i = 0;
|
||||
for (auto& p : Particles)
|
||||
@@ -60,4 +75,13 @@ namespace Nuake
|
||||
p.Position += p.Velocity * static_cast<float>(ts);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleEmitter::SetRadius(float radius)
|
||||
{
|
||||
if (Radius != radius)
|
||||
{
|
||||
Radius = radius;
|
||||
m_Random = std::uniform_real_distribution<float>(-Radius, Radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,16 @@ namespace Nuake
|
||||
Vector3 Gravity = Vector3(0, 0, 0);
|
||||
float GravityRandom = 0.0f;
|
||||
float Radius = 1.0f;
|
||||
float Rate = 0.0f;
|
||||
Color ParticleColor;
|
||||
|
||||
private:
|
||||
float RateTimer = 0.0f;
|
||||
std::mt19937 m_MT;
|
||||
std::uniform_real_distribution<float> m_Random;
|
||||
|
||||
void RecreateRandom();
|
||||
|
||||
public:
|
||||
ParticleEmitter();
|
||||
~ParticleEmitter() = default;
|
||||
@@ -29,6 +34,7 @@ namespace Nuake
|
||||
void SpawnParticle();
|
||||
void Update(Timestep ts);
|
||||
|
||||
void SetRadius(float radius);
|
||||
std::vector<Particle> Particles;
|
||||
};
|
||||
}
|
||||
@@ -28,10 +28,12 @@ namespace Nuake
|
||||
// Copy emitter settings from component to real emitter
|
||||
auto& emitter = emitterComponent.Emitter;
|
||||
emitter.Amount = emitterComponent.Amount;
|
||||
emitter.ParticleColor = emitterComponent.ParticleColor;
|
||||
emitter.Gravity = emitterComponent.Gravity;
|
||||
emitter.GravityRandom = emitterComponent.GravityRandom;
|
||||
emitter.Radius = emitterComponent.Radius;
|
||||
emitter.SetRadius(emitterComponent.Radius);
|
||||
emitter.Life = emitterComponent.Life;
|
||||
emitter.Rate = emitterComponent.Rate;
|
||||
|
||||
// Spawn particle if possible
|
||||
emitterComponent.Emitter.SpawnParticle();
|
||||
|
||||
Reference in New Issue
Block a user