"Lightening" particle bugg fixed. Scale and alpha interpolation implemented through ScalarInterpolation-funtion
This commit is contained in:
@@ -33,8 +33,10 @@ namespace Components
|
|||||||
|
|
||||||
struct Particle : public Component
|
struct Particle : public Component
|
||||||
{
|
{
|
||||||
|
EntityID ParticleSystem;
|
||||||
float Radius = 0.5f;
|
float Radius = 0.5f;
|
||||||
float LifeTime = 5.0f;
|
double TimeLived = 0;
|
||||||
|
double LifeTime = 5;
|
||||||
|
|
||||||
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(
|
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(
|
||||||
ParticleFlags::Water
|
ParticleFlags::Water
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ struct ParticleEmitter : public Component
|
|||||||
float Speed = 2.f;
|
float Speed = 2.f;
|
||||||
double LifeTime = 100;
|
double LifeTime = 100;
|
||||||
|
|
||||||
|
//values to interpolate between.
|
||||||
|
std::vector<float> RadiusValues;
|
||||||
|
std::vector<float> AlphaValues;
|
||||||
|
|
||||||
//System variables
|
//System variables
|
||||||
float GravityScale = 1.0f;
|
float GravityScale = 1.0f;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,12 +24,15 @@ struct CreateParticleSequence : public Event
|
|||||||
float MaxCount = 0;
|
float MaxCount = 0;
|
||||||
glm::vec4 Color = glm::vec4(0);
|
glm::vec4 Color = glm::vec4(0);
|
||||||
EntityID parent = 0;
|
EntityID parent = 0;
|
||||||
|
// values to interpolate between.
|
||||||
|
std::vector<float> RadiusValues;
|
||||||
|
std::vector<float> AlphaValues;
|
||||||
|
|
||||||
//Particle
|
//Particle
|
||||||
std::string SpriteFile = "";
|
std::string SpriteFile = "";
|
||||||
double ParticleLifeTime = 3.f;
|
double ParticleLifeTime = 3.f;
|
||||||
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(ParticleFlags::Powder | ParticleFlags::ParticleContactFilter | ParticleFlags::FixtureContactFilter);
|
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(ParticleFlags::Powder | ParticleFlags::ParticleContactFilter | ParticleFlags::FixtureContactFilter);
|
||||||
float Radius = 1.f;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace dd
|
|||||||
class PhysicsSystem : public System
|
class PhysicsSystem : public System
|
||||||
{
|
{
|
||||||
friend class ContractListener;
|
friend class ContractListener;
|
||||||
friend class DestructionListener;
|
//friend class DestructionListener;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||||
@@ -107,6 +107,7 @@ namespace dd
|
|||||||
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale, int maxCount);
|
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale, int maxCount);
|
||||||
void CreateParticleEmitter(EntityID entity);
|
void CreateParticleEmitter(EntityID entity);
|
||||||
void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed.
|
void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed.
|
||||||
|
float ScalarInterpolation(float timeProgress, std::vector<float> spectrum);
|
||||||
|
|
||||||
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
|
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
|
||||||
bool SetImpulse(const Events::SetImpulse &event);
|
bool SetImpulse(const Events::SetImpulse &event);
|
||||||
@@ -131,36 +132,36 @@ namespace dd
|
|||||||
std::list<Impulse> m_Impulses;
|
std::list<Impulse> m_Impulses;
|
||||||
|
|
||||||
|
|
||||||
class DestructionListener : public b2DestructionListener
|
// class DestructionListener : public b2DestructionListener
|
||||||
{
|
// {
|
||||||
public:
|
// public:
|
||||||
DestructionListener(PhysicsSystem* physicsSystem)
|
// DestructionListener(PhysicsSystem* physicsSystem)
|
||||||
: m_PhysicsSystem(physicsSystem) { }
|
// : m_PhysicsSystem(physicsSystem) { }
|
||||||
|
//
|
||||||
void SayGoodbye(b2Joint*) {LOG_INFO("joint körs");};
|
// void SayGoodbye(b2Joint*) {LOG_INFO("joint körs");};
|
||||||
void SayGoodbye(b2Fixture*) {/*LOG_INFO("Fixture körs");*/};
|
// void SayGoodbye(b2Fixture*) {/*LOG_INFO("Fixture körs");*/};
|
||||||
|
//
|
||||||
void SayGoodbye(b2ParticleSystem* particleSystem, int32 index) override
|
// void SayGoodbye(b2ParticleSystem* particleSystem, int32 index) override
|
||||||
{
|
// {
|
||||||
LOG_INFO("Particle ded");
|
// // LOG_INFO("Particle ded");
|
||||||
|
// //
|
||||||
|
// //
|
||||||
const b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index);
|
// // const b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index);
|
||||||
for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) {
|
// // for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) {
|
||||||
if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) {
|
// // if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) {
|
||||||
std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle);
|
// // std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle);
|
||||||
if(it != m_PhysicsSystem->m_ParticleHandleToEntities[i].end()) {
|
// // if(it != m_PhysicsSystem->m_ParticleHandleToEntities[i].end()) {
|
||||||
EntityID id = it->second;
|
// // EntityID id = it->second;
|
||||||
m_PhysicsSystem->m_World->RemoveEntity(id);
|
// // m_PhysicsSystem->m_World->RemoveEntity(id);
|
||||||
m_PhysicsSystem->m_ParticleHandleToEntities[i].erase(it);
|
// // m_PhysicsSystem->m_ParticleHandleToEntities[i].erase(it);
|
||||||
LOG_INFO("Removing from list");
|
// // LOG_INFO("Removing from list");
|
||||||
}
|
// // }
|
||||||
}
|
// // }
|
||||||
}
|
// // }
|
||||||
}
|
// }
|
||||||
private:
|
// private:
|
||||||
PhysicsSystem* m_PhysicsSystem;
|
// PhysicsSystem* m_PhysicsSystem;
|
||||||
};
|
// };
|
||||||
|
|
||||||
class ParticleContactDisabler : public b2ContactFilter
|
class ParticleContactDisabler : public b2ContactFilter
|
||||||
{
|
{
|
||||||
@@ -198,7 +199,7 @@ namespace dd
|
|||||||
PhysicsSystem* m_PhysicsSystem;
|
PhysicsSystem* m_PhysicsSystem;
|
||||||
};
|
};
|
||||||
|
|
||||||
DestructionListener* m_DestructionListener;
|
//DestructionListener* m_DestructionListener;
|
||||||
ParticleContactDisabler* m_ParticleContactDisabler;
|
ParticleContactDisabler* m_ParticleContactDisabler;
|
||||||
ContactListener* m_ContactListener;
|
ContactListener* m_ContactListener;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -314,9 +314,12 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
ep.EmittingAngle = glm::half_pi<float>();
|
ep.EmittingAngle = glm::half_pi<float>();
|
||||||
ep.Spread = 1.5f;
|
ep.Spread = 1.5f;
|
||||||
ep.Position = transformComponentBrick->Position;
|
ep.Position = transformComponentBrick->Position;
|
||||||
ep.Radius = 0.05;
|
//ep.Radius = 0.05;
|
||||||
ep.SpriteFile = "Textures/Particles/FadeBall.png";
|
ep.SpriteFile = "Textures/Particles/FadeBall.png";
|
||||||
ep.Color = brickModel->Color + glm::vec4(0.3f);
|
ep.Color = brickModel->Color + glm::vec4(0.3f);
|
||||||
|
ep.AlphaValues.push_back(1.f);
|
||||||
|
ep.AlphaValues.push_back(0.f);
|
||||||
|
ep.RadiusValues.push_back(0.05);
|
||||||
ep.Speed = 50;
|
ep.Speed = 50;
|
||||||
EventBroker->Publish(ep);
|
EventBroker->Publish(ep);
|
||||||
|
|
||||||
@@ -369,9 +372,12 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
ep.EmittingAngle = glm::half_pi<float>();
|
ep.EmittingAngle = glm::half_pi<float>();
|
||||||
ep.Spread = 1.5f;
|
ep.Spread = 1.5f;
|
||||||
ep.Position = transformComponentBrick->Position;
|
ep.Position = transformComponentBrick->Position;
|
||||||
ep.Radius = 0.05;
|
//ep.Radius = 0.05;
|
||||||
ep.SpriteFile = "Textures/Particles/FadeBall.png";
|
ep.SpriteFile = "Textures/Particles/FadeBall.png";
|
||||||
ep.Color = brickModel->Color + glm::vec4(0.3f);
|
ep.Color = brickModel->Color + glm::vec4(0.3f);
|
||||||
|
ep.AlphaValues.push_back(1.f);
|
||||||
|
ep.AlphaValues.push_back(0.f);
|
||||||
|
ep.RadiusValues.push_back(0.05f);
|
||||||
ep.Speed = 50;
|
ep.Speed = 50;
|
||||||
EventBroker->Publish(ep);
|
EventBroker->Publish(ep);
|
||||||
|
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ void dd::Systems::PhysicsSystem::Initialize()
|
|||||||
{
|
{
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
gen = std::mt19937(rd());
|
gen = std::mt19937(rd());
|
||||||
m_DestructionListener = new DestructionListener(this);
|
// m_DestructionListener = new DestructionListener(this);
|
||||||
m_ContactListener = new ContactListener(this);
|
m_ContactListener = new ContactListener(this);
|
||||||
m_PhysicsWorld = new b2World(m_Gravity);
|
m_PhysicsWorld = new b2World(m_Gravity);
|
||||||
m_ParticleContactDisabler = new ParticleContactDisabler();
|
m_ParticleContactDisabler = new ParticleContactDisabler();
|
||||||
m_PhysicsWorld->SetContactListener(m_ContactListener);
|
m_PhysicsWorld->SetContactListener(m_ContactListener);
|
||||||
m_PhysicsWorld->SetContactFilter(m_ParticleContactDisabler);
|
m_PhysicsWorld->SetContactFilter(m_ParticleContactDisabler);
|
||||||
m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
|
// m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
|
||||||
|
|
||||||
InitializeWater();
|
InitializeWater();
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
|
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
|
||||||
@@ -241,12 +241,14 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
parentTransform = tp->Position;
|
parentTransform = tp->Position;
|
||||||
}
|
}
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
|
auto particle = m_World->GetComponent<Components::Particle>(entity);
|
||||||
|
|
||||||
transform->Position = glm::vec3(position.x, position.y, transform->Position.z);
|
transform->Position = glm::vec3(position.x, position.y, transform->Position.z);
|
||||||
|
transform->Scale = glm::vec3(particle->Radius * 2.f, particle->Radius * 2.f, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Accumulator -= dt;
|
m_Accumulator -= m_TimeStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,8 +270,9 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
|||||||
|
|
||||||
|
|
||||||
if (particle && !pTemplate) {
|
if (particle && !pTemplate) {
|
||||||
particle->LifeTime -= dt;
|
particle->TimeLived += dt;
|
||||||
if (particle->LifeTime <= 0) {
|
//Delete particles
|
||||||
|
if (particle->TimeLived >= particle->LifeTime - 0.1) {
|
||||||
for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) {
|
for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) {
|
||||||
const b2ParticleHandle* handle = m_EntitiesToParticleHandle[i][entity];
|
const b2ParticleHandle* handle = m_EntitiesToParticleHandle[i][entity];
|
||||||
std::unordered_map<EntityID, const b2ParticleHandle*>::iterator iter1;
|
std::unordered_map<EntityID, const b2ParticleHandle*>::iterator iter1;
|
||||||
@@ -285,10 +288,20 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
|||||||
m_World->RemoveEntity(entity);
|
m_World->RemoveEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Update alpha
|
||||||
auto sprite = m_World->GetComponent<Components::Sprite>(entity);
|
auto sprite = m_World->GetComponent<Components::Sprite>(entity);
|
||||||
sprite->Color.w = particle->LifeTime;
|
float timeProgress = particle->TimeLived / particle->LifeTime;
|
||||||
|
if (timeProgress > particle->LifeTime) {
|
||||||
|
timeProgress = particle->LifeTime;
|
||||||
|
}
|
||||||
|
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(particle->ParticleSystem);
|
||||||
|
if (emitter) {
|
||||||
|
sprite->Color.w = ScalarInterpolation(timeProgress, emitter->AlphaValues);
|
||||||
|
particle->Radius = ScalarInterpolation(timeProgress, emitter->RadiusValues);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Particlesystem relative to parent
|
||||||
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(entity);
|
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(entity);
|
||||||
if (emitter) {
|
if (emitter) {
|
||||||
EntityID emitterParent = emitter->Parent;
|
EntityID emitterParent = emitter->Parent;
|
||||||
@@ -302,6 +315,26 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float dd::Systems::PhysicsSystem::ScalarInterpolation(float timeProgress, std::vector<float> spectrum)
|
||||||
|
{
|
||||||
|
int alphaVecSize = spectrum.size();
|
||||||
|
if (alphaVecSize == 0) {
|
||||||
|
return 0.01f;
|
||||||
|
}
|
||||||
|
if (alphaVecSize == 1) {
|
||||||
|
return spectrum[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
float dValue = glm::abs(spectrum[0] - spectrum[1]);
|
||||||
|
if (spectrum[0] > spectrum[1]) {
|
||||||
|
dValue *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
float scalar = spectrum[0] + dValue * timeProgress;
|
||||||
|
|
||||||
|
return scalar;
|
||||||
|
}
|
||||||
|
|
||||||
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
|
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
|
||||||
{
|
{
|
||||||
if (event.Type != "PhysicsSystem" && event.Type != "All") {
|
if (event.Type != "PhysicsSystem" && event.Type != "All") {
|
||||||
@@ -354,7 +387,6 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
|
|||||||
m_BodiesToEntities.erase(it->second);
|
m_BodiesToEntities.erase(it->second);
|
||||||
m_EntitiesToBodies.erase(entity);
|
m_EntitiesToBodies.erase(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -504,11 +536,13 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
if(emitter->TimeSinceLastSpawn < emitter->SpawnRate || emitter->NumberOfTicks < 1) {
|
if(emitter->TimeSinceLastSpawn < emitter->SpawnRate || emitter->NumberOfTicks < 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
//Create new particle
|
||||||
emitter->NumberOfTicks--;
|
emitter->NumberOfTicks--;
|
||||||
emitter->TimeSinceLastSpawn -= emitter->SpawnRate;
|
emitter->TimeSinceLastSpawn -= emitter->SpawnRate;
|
||||||
auto templateTransform = m_World->GetComponent<Components::Transform>(pt);
|
auto templateTransform = m_World->GetComponent<Components::Transform>(pt);
|
||||||
b2ParticleDef particleDef;
|
|
||||||
for ( int j = 0; j < emitter->ParticlesPerTick; j++) {
|
for ( int j = 0; j < emitter->ParticlesPerTick; j++) {
|
||||||
|
b2ParticleDef particleDef;
|
||||||
particleDef.flags = particleTemplate->Flags;
|
particleDef.flags = particleTemplate->Flags;
|
||||||
//particleDef.color TODO: Implement this if we want color mixing and shit.
|
//particleDef.color TODO: Implement this if we want color mixing and shit.
|
||||||
particleDef.lifetime = particleTemplate->LifeTime;
|
particleDef.lifetime = particleTemplate->LifeTime;
|
||||||
@@ -527,21 +561,21 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
|
|
||||||
auto particle = m_World->CloneEntity(pt, 0);
|
auto particle = m_World->CloneEntity(pt, 0);
|
||||||
m_World->RemoveComponent<Components::Template>(particle);
|
m_World->RemoveComponent<Components::Template>(particle);
|
||||||
auto transform2 = m_World->GetComponent<Components::Transform>(particle);
|
auto particleTransform = m_World->GetComponent<Components::Transform>(particle);
|
||||||
|
|
||||||
|
|
||||||
std::uniform_real_distribution<float> dist(0, 1);
|
std::uniform_real_distribution<float> dist(0, 1);
|
||||||
float zDistribution = dist(gen);
|
float zDistribution = dist(gen);
|
||||||
transform2->Position = glm::vec3(emitterTransform->Position.x, emitterTransform->Position.y, -9.5f + zDistribution);
|
particleTransform->Position = glm::vec3(emitterTransform->Position.x, emitterTransform->Position.y, -9.5f + zDistribution);
|
||||||
transform2->Scale = glm::vec3(particleTemplate->Radius * 2.f / speedMultiplier, particleTemplate->Radius * 2.f / speedMultiplier, 1);
|
particleTransform->Scale = glm::vec3(particleTemplate->Radius * 2.f / speedMultiplier, particleTemplate->Radius * 2.f / speedMultiplier, 1);
|
||||||
|
particleTransform->Velocity = glm::vec3(vel.x, vel.y, 0);
|
||||||
|
|
||||||
|
|
||||||
auto b2Particle = ps->CreateParticle(particleDef);
|
auto b2ParticleIndex = ps->CreateParticle(particleDef);
|
||||||
|
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2ParticleIndex);
|
||||||
|
|
||||||
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
|
|
||||||
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
|
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
|
||||||
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -554,7 +588,7 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
// std::cout << "Entities and handles: " << entHandles << std::endl;
|
// std::cout << "Entities and handles: " << entHandles << std::endl;
|
||||||
// LOG_INFO("Particles living: %i", pSizeTest);
|
// LOG_INFO("Particles living: %i", pSizeTest);
|
||||||
// LOG_INFO("Particle systems: %i", psListSize);
|
// LOG_INFO("Particle systems: %i", psListSize);
|
||||||
// int entHandles = 0;
|
// //int entHandles = 0;
|
||||||
// for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++)
|
// for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++)
|
||||||
// entHandles += m_EntitiesToParticleHandle[i].size();
|
// entHandles += m_EntitiesToParticleHandle[i].size();
|
||||||
// LOG_INFO("Entities and handles: %i", entHandles);
|
// LOG_INFO("Entities and handles: %i", entHandles);
|
||||||
@@ -570,7 +604,7 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_ParticleEmitters.ParticleSystem[key]->GetParticleCount() == 0 && key <= m_ParticleEmitters.ParticleSystem.size()) {
|
if (m_ParticleEmitters.ParticleSystem[key]->GetParticleCount() == 0 && key <= m_ParticleEmitters.ParticleSystem.size() - 1) {
|
||||||
m_World->RemoveEntity(ent);
|
m_World->RemoveEntity(ent);
|
||||||
m_PhysicsWorld->DestroyParticleSystem(m_ParticleEmitters.ParticleSystem[key]);
|
m_PhysicsWorld->DestroyParticleSystem(m_ParticleEmitters.ParticleSystem[key]);
|
||||||
m_ParticleEmitters.ParticleSystem.erase(m_ParticleEmitters.ParticleSystem.begin() + key);
|
m_ParticleEmitters.ParticleSystem.erase(m_ParticleEmitters.ParticleSystem.begin() + key);
|
||||||
@@ -578,16 +612,9 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
m_ParticleEmitters.ParticleTemplate.erase(m_ParticleEmitters.ParticleTemplate.begin() + key);
|
m_ParticleEmitters.ParticleTemplate.erase(m_ParticleEmitters.ParticleTemplate.begin() + key);
|
||||||
m_EntitiesToParticleHandle.erase(m_EntitiesToParticleHandle.begin() + key);
|
m_EntitiesToParticleHandle.erase(m_EntitiesToParticleHandle.begin() + key);
|
||||||
m_ParticleHandleToEntities.erase(m_ParticleHandleToEntities.begin() + key);
|
m_ParticleHandleToEntities.erase(m_ParticleHandleToEntities.begin() + key);
|
||||||
|
emittersToDelete.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int stp = 0;
|
|
||||||
for (auto ts : m_EntitiesToParticleHandle)
|
|
||||||
{
|
|
||||||
stp += ts.size();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreateParticleSequence &event)
|
bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreateParticleSequence &event)
|
||||||
@@ -611,21 +638,22 @@ bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreatePart
|
|||||||
particleEmitter->Spread = event.Spread;
|
particleEmitter->Spread = event.Spread;
|
||||||
particleEmitter->EmittingAngle = event.EmittingAngle;
|
particleEmitter->EmittingAngle = event.EmittingAngle;
|
||||||
particleEmitter->LifeTime = event.EmitterLifeTime;
|
particleEmitter->LifeTime = event.EmitterLifeTime;
|
||||||
|
particleEmitter->AlphaValues = event.AlphaValues;
|
||||||
{
|
particleEmitter->RadiusValues = event.RadiusValues;
|
||||||
//Creating Particle Template
|
{
|
||||||
auto particle = m_World->CreateEntity(emitter);
|
//Creating Particle Template
|
||||||
auto particleTransform = m_World->AddComponent<Components::Transform>(particle);
|
auto particle = m_World->CreateEntity(emitter);
|
||||||
auto sprite = m_World->AddComponent<Components::Sprite>(particle);
|
auto particleTransform = m_World->AddComponent<Components::Transform>(particle);
|
||||||
auto particleComponent = m_World->AddComponent<Components::Particle>(particle);
|
auto sprite = m_World->AddComponent<Components::Sprite>(particle);
|
||||||
m_World->AddComponent<Components::Template>(particle);
|
auto particleComponent = m_World->AddComponent<Components::Particle>(particle);
|
||||||
|
m_World->AddComponent<Components::Template>(particle);
|
||||||
particleTransform->Position = emitterTransform->Position;
|
particleTransform->Position = emitterTransform->Position;
|
||||||
sprite->SpriteFile = event.SpriteFile;
|
sprite->SpriteFile = event.SpriteFile;
|
||||||
sprite->Color = event.Color;
|
sprite->Color = event.Color;
|
||||||
particleComponent->LifeTime = event.ParticleLifeTime;
|
particleComponent->LifeTime = event.ParticleLifeTime;
|
||||||
particleComponent->Flags = event.Flags;
|
particleComponent->Flags = event.Flags;
|
||||||
particleComponent->Radius = event.Radius;
|
particleComponent->Radius = event.RadiusValues[0];
|
||||||
|
particleComponent->ParticleSystem = emitter;
|
||||||
}
|
}
|
||||||
m_World->CommitEntity(emitter);
|
m_World->CommitEntity(emitter);
|
||||||
return true;
|
return true;
|
||||||
@@ -679,17 +707,17 @@ b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius,
|
|||||||
m_ParticleSystemDef.maxCount = maxCount;
|
m_ParticleSystemDef.maxCount = maxCount;
|
||||||
m_ParticleSystemDef.radius = radius;
|
m_ParticleSystemDef.radius = radius;
|
||||||
m_ParticleSystemDef.gravityScale = gravityScale;
|
m_ParticleSystemDef.gravityScale = gravityScale;
|
||||||
m_ParticleSystemDef.destroyByAge = true;
|
m_ParticleSystemDef.destroyByAge = false;
|
||||||
|
|
||||||
return m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
return m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
||||||
{
|
{
|
||||||
//Check if it is a brick colliding
|
//Check if it is a brick colliding with ball
|
||||||
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
|
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
|
||||||
Components::Model* model;
|
Components::Model* model;
|
||||||
|
auto ball = m_World->GetComponent<Components::Ball>(event.Entity2);
|
||||||
if (!brick) {
|
if (!brick) {
|
||||||
brick = m_World->GetComponent<Components::Brick>(event.Entity2);
|
brick = m_World->GetComponent<Components::Brick>(event.Entity2);
|
||||||
if (!brick) {
|
if (!brick) {
|
||||||
@@ -699,7 +727,14 @@ bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
model = m_World->GetComponent<Components::Model>(event.Entity2);
|
model = m_World->GetComponent<Components::Model>(event.Entity2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!ball) {
|
||||||
|
ball = m_World->GetComponent<Components::Ball>(event.Entity1);
|
||||||
|
if (!ball) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
model = m_World->GetComponent<Components::Model>(event.Entity1);
|
model = m_World->GetComponent<Components::Model>(event.Entity1);
|
||||||
}
|
}
|
||||||
Events::CreateParticleSequence e;
|
Events::CreateParticleSequence e;
|
||||||
@@ -711,9 +746,12 @@ bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
e.ParticleLifeTime = 1.f;
|
e.ParticleLifeTime = 1.f;
|
||||||
e.ParticlesPerTick = 15;
|
e.ParticlesPerTick = 15;
|
||||||
e.Position = glm::vec3(event.IntersectionPoint.x, event.IntersectionPoint.y, -10);
|
e.Position = glm::vec3(event.IntersectionPoint.x, event.IntersectionPoint.y, -10);
|
||||||
e.Radius = 0.2f;
|
e.RadiusValues.push_back(0.2);
|
||||||
|
e.RadiusValues.push_back(1);
|
||||||
e.SpriteFile = "Textures/Particles/Cloud_Particle.png";
|
e.SpriteFile = "Textures/Particles/Cloud_Particle.png";
|
||||||
e.Color = model->Color + glm::vec4(0.5f);
|
e.Color = model->Color + glm::vec4(0.5f);
|
||||||
|
e.AlphaValues.push_back(1.f);
|
||||||
|
e.AlphaValues.push_back(0.f);
|
||||||
e.Speed = 100;
|
e.Speed = 100;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user