Angle and spread on particle system. Need to make them not collide.
This commit is contained in:
+11
-7
@@ -137,6 +137,7 @@ public:
|
||||
|
||||
|
||||
//OctoBall
|
||||
/*
|
||||
{
|
||||
auto ent = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
@@ -158,7 +159,7 @@ public:
|
||||
plight->Radius = 2.f;
|
||||
|
||||
m_World->CommitEntity(ent);
|
||||
}
|
||||
}*/
|
||||
|
||||
//PointLightTest
|
||||
{
|
||||
@@ -224,10 +225,13 @@ public:
|
||||
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);
|
||||
transform->Position = glm::vec3(0.f, 0.f, -10.f);
|
||||
particleEmitter->GravityScale = 0.0f;
|
||||
particleEmitter->SpawnRate = 1.0f;
|
||||
particleEmitter->NumberOfTicks = 3.f;
|
||||
particleEmitter->SpawnRate = 0.1f;
|
||||
particleEmitter->NumberOfTicks = 1000;
|
||||
particleEmitter->Speed = 2.f;
|
||||
particleEmitter->Spread = glm::pi<float>()/2;
|
||||
particleEmitter->EmittingAngle = glm::pi<float>();
|
||||
|
||||
{
|
||||
auto Pt = m_World->CreateEntity(Pe);
|
||||
@@ -236,11 +240,11 @@ public:
|
||||
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->Velocity = glm::vec3(1.0f, 0.f, 0.f);
|
||||
PtTransform->Position = transform->Position;
|
||||
PtSprite->SpriteFile = "Textures/Test/Water.png";
|
||||
PtParticle->LifeTime = 5.f;
|
||||
PtParticle->Flags = ParticleFlags::Type::powderParticle;
|
||||
PtParticle->Flags = ParticleFlags::Type::staticPressureParticle;
|
||||
}
|
||||
m_World->CommitEntity(Pe);
|
||||
}
|
||||
@@ -368,7 +372,7 @@ public:
|
||||
auto ent = m_World->CreateEntity();
|
||||
m_World->SetProperty(ent, "Name", "Pad");
|
||||
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
|
||||
ctransform->Position = glm::vec3(0.f, -3.5f, -10.f);
|
||||
ctransform->Position = glm::vec3(0.f, -13.5f, -10.f);
|
||||
ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f);
|
||||
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
|
||||
@@ -11,9 +11,12 @@ struct ParticleEmitter : public Component
|
||||
{
|
||||
int NumberOfTicks = 10.f;
|
||||
float InitialSpeed = 1.f;
|
||||
double SpawnRate = 1.f;
|
||||
double SpawnRate = 1;
|
||||
double TimeSinceLastSpawn = 0;
|
||||
int MaxCount = 0;
|
||||
float EmittingAngle = 0.f;
|
||||
float Spread = 0.f;
|
||||
float Speed = 2.f;
|
||||
|
||||
//ParticleSystem variables
|
||||
float GravityScale = 1.0f;
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#define DAYDREAM_PHYSICSSYSTEM_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <random>
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/World.h"
|
||||
@@ -65,6 +68,8 @@ private:
|
||||
|
||||
int m_VelocityIterations, m_PositionIterations;
|
||||
|
||||
std::mt19937 gen;
|
||||
|
||||
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
|
||||
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ void dd::Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||
|
||||
void dd::Systems::PhysicsSystem::Initialize()
|
||||
{
|
||||
std::random_device rd;
|
||||
gen = std::mt19937(rd());
|
||||
|
||||
m_ContactListener = new ContactListener(this);
|
||||
|
||||
m_Gravity = b2Vec2(0.f, -9.82f);
|
||||
@@ -24,6 +27,8 @@ void dd::Systems::PhysicsSystem::Initialize()
|
||||
|
||||
InitializeWater();
|
||||
|
||||
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, PhysicsSystem::SetImpulse);
|
||||
}
|
||||
|
||||
@@ -382,7 +387,8 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
LOG_INFO("ParticleTemplate Component is nil.");
|
||||
continue;
|
||||
}
|
||||
|
||||
auto TempTransform = m_World->GetComponent<Components::Transform>(e);
|
||||
TempTransform->Orientation = glm::rotate(glm::quat(), 3.f, glm::vec3(0.f, 0.f, -1.f));
|
||||
|
||||
emitter->TimeSinceLastSpawn += dt;
|
||||
if(emitter->TimeSinceLastSpawn < emitter->SpawnRate || emitter->NumberOfTicks < 1) {
|
||||
@@ -396,7 +402,15 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
particleDef.flags = particleTemplate->Flags;
|
||||
//particleDef.color TODO: Implement this if we want color mixing and shit.
|
||||
particleDef.lifetime = particleTemplate->LifeTime;
|
||||
particleDef.velocity = b2Vec2(templateTransform->Velocity.x, templateTransform->Velocity.y);
|
||||
float eAngle = emitter->EmittingAngle;
|
||||
float halfSpread = emitter->Spread / 2;
|
||||
|
||||
std::uniform_real_distribution<float> dis(eAngle-halfSpread, eAngle+halfSpread);
|
||||
float pAngle = dis(gen);
|
||||
LOG_INFO("Radian angle: %f", pAngle);
|
||||
glm::vec2 unitVec = glm::normalize(glm::vec2(glm::cos(pAngle), glm::sin(pAngle)));
|
||||
glm::vec2 vel = unitVec * emitter->Speed;
|
||||
particleDef.velocity = b2Vec2(vel.x, vel.y);
|
||||
particleDef.position = b2Vec2(templateTransform->Position.x, templateTransform->Position.y);
|
||||
|
||||
|
||||
@@ -405,7 +419,9 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
auto transform = m_World->GetComponent<Components::Transform>(particle);
|
||||
transform->Scale = glm::vec3 (particleTemplate->Radius * 2.f, particleTemplate->Radius * 2.f, 1);
|
||||
|
||||
|
||||
auto b2Particle = ps->CreateParticle(particleDef);
|
||||
|
||||
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
|
||||
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
|
||||
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
||||
|
||||
Reference in New Issue
Block a user