"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);
|
||||||
|
|
||||||
|
|||||||
+783
-745
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user