"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
|
||||
{
|
||||
EntityID ParticleSystem;
|
||||
float Radius = 0.5f;
|
||||
float LifeTime = 5.0f;
|
||||
double TimeLived = 0;
|
||||
double LifeTime = 5;
|
||||
|
||||
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(
|
||||
ParticleFlags::Water
|
||||
|
||||
@@ -22,6 +22,10 @@ struct ParticleEmitter : public Component
|
||||
float Speed = 2.f;
|
||||
double LifeTime = 100;
|
||||
|
||||
//values to interpolate between.
|
||||
std::vector<float> RadiusValues;
|
||||
std::vector<float> AlphaValues;
|
||||
|
||||
//System variables
|
||||
float GravityScale = 1.0f;
|
||||
};
|
||||
|
||||
@@ -24,12 +24,15 @@ struct CreateParticleSequence : public Event
|
||||
float MaxCount = 0;
|
||||
glm::vec4 Color = glm::vec4(0);
|
||||
EntityID parent = 0;
|
||||
// values to interpolate between.
|
||||
std::vector<float> RadiusValues;
|
||||
std::vector<float> AlphaValues;
|
||||
|
||||
//Particle
|
||||
std::string SpriteFile = "";
|
||||
double ParticleLifeTime = 3.f;
|
||||
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
|
||||
{
|
||||
friend class ContractListener;
|
||||
friend class DestructionListener;
|
||||
//friend class DestructionListener;
|
||||
|
||||
public:
|
||||
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
@@ -107,6 +107,7 @@ namespace dd
|
||||
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale, int maxCount);
|
||||
void CreateParticleEmitter(EntityID entity);
|
||||
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;
|
||||
bool SetImpulse(const Events::SetImpulse &event);
|
||||
@@ -131,36 +132,36 @@ namespace dd
|
||||
std::list<Impulse> m_Impulses;
|
||||
|
||||
|
||||
class DestructionListener : public b2DestructionListener
|
||||
{
|
||||
public:
|
||||
DestructionListener(PhysicsSystem* physicsSystem)
|
||||
: m_PhysicsSystem(physicsSystem) { }
|
||||
|
||||
void SayGoodbye(b2Joint*) {LOG_INFO("joint körs");};
|
||||
void SayGoodbye(b2Fixture*) {/*LOG_INFO("Fixture körs");*/};
|
||||
|
||||
void SayGoodbye(b2ParticleSystem* particleSystem, int32 index) override
|
||||
{
|
||||
LOG_INFO("Particle ded");
|
||||
|
||||
|
||||
const b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index);
|
||||
for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) {
|
||||
if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) {
|
||||
std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle);
|
||||
if(it != m_PhysicsSystem->m_ParticleHandleToEntities[i].end()) {
|
||||
EntityID id = it->second;
|
||||
m_PhysicsSystem->m_World->RemoveEntity(id);
|
||||
m_PhysicsSystem->m_ParticleHandleToEntities[i].erase(it);
|
||||
LOG_INFO("Removing from list");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
// class DestructionListener : public b2DestructionListener
|
||||
// {
|
||||
// public:
|
||||
// DestructionListener(PhysicsSystem* physicsSystem)
|
||||
// : m_PhysicsSystem(physicsSystem) { }
|
||||
//
|
||||
// void SayGoodbye(b2Joint*) {LOG_INFO("joint körs");};
|
||||
// void SayGoodbye(b2Fixture*) {/*LOG_INFO("Fixture körs");*/};
|
||||
//
|
||||
// void SayGoodbye(b2ParticleSystem* particleSystem, int32 index) override
|
||||
// {
|
||||
// // LOG_INFO("Particle ded");
|
||||
// //
|
||||
// //
|
||||
// // const b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index);
|
||||
// // for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) {
|
||||
// // if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) {
|
||||
// // std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle);
|
||||
// // if(it != m_PhysicsSystem->m_ParticleHandleToEntities[i].end()) {
|
||||
// // EntityID id = it->second;
|
||||
// // m_PhysicsSystem->m_World->RemoveEntity(id);
|
||||
// // m_PhysicsSystem->m_ParticleHandleToEntities[i].erase(it);
|
||||
// // LOG_INFO("Removing from list");
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// }
|
||||
// private:
|
||||
// PhysicsSystem* m_PhysicsSystem;
|
||||
// };
|
||||
|
||||
class ParticleContactDisabler : public b2ContactFilter
|
||||
{
|
||||
@@ -198,7 +199,7 @@ namespace dd
|
||||
PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
|
||||
DestructionListener* m_DestructionListener;
|
||||
//DestructionListener* m_DestructionListener;
|
||||
ParticleContactDisabler* m_ParticleContactDisabler;
|
||||
ContactListener* m_ContactListener;
|
||||
};
|
||||
|
||||
@@ -314,9 +314,12 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
ep.EmittingAngle = glm::half_pi<float>();
|
||||
ep.Spread = 1.5f;
|
||||
ep.Position = transformComponentBrick->Position;
|
||||
ep.Radius = 0.05;
|
||||
//ep.Radius = 0.05;
|
||||
ep.SpriteFile = "Textures/Particles/FadeBall.png";
|
||||
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;
|
||||
EventBroker->Publish(ep);
|
||||
|
||||
@@ -369,9 +372,12 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
ep.EmittingAngle = glm::half_pi<float>();
|
||||
ep.Spread = 1.5f;
|
||||
ep.Position = transformComponentBrick->Position;
|
||||
ep.Radius = 0.05;
|
||||
//ep.Radius = 0.05;
|
||||
ep.SpriteFile = "Textures/Particles/FadeBall.png";
|
||||
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;
|
||||
EventBroker->Publish(ep);
|
||||
|
||||
|
||||
+783
-745
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user