Merge branch 'water'
This commit is contained in:
@@ -33,8 +33,10 @@ namespace Components
|
||||
|
||||
struct Particle : public Component
|
||||
{
|
||||
float Radius = 0.5f;
|
||||
float LifeTime = 5.0f;
|
||||
EntityID ParticleSystem;
|
||||
glm::vec3 Scale = glm::vec3(1.f);
|
||||
double TimeLived = 0;
|
||||
double LifeTime = 5;
|
||||
|
||||
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(
|
||||
ParticleFlags::Water
|
||||
|
||||
@@ -21,6 +21,11 @@ struct ParticleEmitter : public Component
|
||||
float Spread = 0.f;
|
||||
float Speed = 2.f;
|
||||
double LifeTime = 100;
|
||||
float RadiusDistribution = 0;
|
||||
|
||||
//values to interpolate between.
|
||||
std::vector<glm::vec3> ScaleValues;
|
||||
std::vector<float> AlphaValues;
|
||||
|
||||
//System variables
|
||||
float GravityScale = 1.0f;
|
||||
|
||||
@@ -22,14 +22,18 @@ struct CreateParticleSequence : public Event
|
||||
float Spread = 1.f;
|
||||
float EmittingAngle = 0.f;
|
||||
float MaxCount = 0;
|
||||
float RadiusDistribution = 0;
|
||||
glm::vec4 Color = glm::vec4(0);
|
||||
EntityID parent = 0;
|
||||
// values to interpolate between.
|
||||
std::vector<glm::vec3> ScaleValues;
|
||||
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)
|
||||
@@ -106,6 +106,9 @@ 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);
|
||||
glm::vec3 VectorInterpolation(float timeProgress, std::vector<glm::vec3> spectrum);
|
||||
|
||||
|
||||
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
|
||||
bool SetImpulse(const Events::SetImpulse &event);
|
||||
@@ -128,36 +131,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
|
||||
{
|
||||
@@ -195,7 +198,7 @@ namespace dd
|
||||
PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
|
||||
DestructionListener* m_DestructionListener;
|
||||
//DestructionListener* m_DestructionListener;
|
||||
ParticleContactDisabler* m_ParticleContactDisabler;
|
||||
ContactListener* m_ContactListener;
|
||||
};
|
||||
|
||||
@@ -307,7 +307,7 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||
} else if (ballTransform->Position.x <= -2.7f) {
|
||||
particleEvent.Position = glm::vec3(-2.7f, -3.f, -3.f);
|
||||
}
|
||||
particleEvent.Radius = 1.f;
|
||||
particleEvent.ScaleValues.push_back(glm::vec3(1.f));
|
||||
particleEvent.Color = glm::vec4(1.f);
|
||||
particleEvent.Speed = 0;
|
||||
|
||||
|
||||
@@ -286,6 +286,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
brick->Removed = true;
|
||||
m_World->RemoveEntity(entityShot);
|
||||
BrickHit(entityShot, entityBrick, 1);
|
||||
//ep.Radius = 0.05;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -393,6 +394,45 @@ void dd::Systems::LevelSystem::BrickHit(EntityID entityHitter, EntityID entityBr
|
||||
m_World->RemoveComponent<Components::Template>(b);
|
||||
m_World->SetEntityParent(b, 0);
|
||||
m_World->CommitEntity(b);
|
||||
|
||||
//Particle trail
|
||||
Events::CreateParticleSequence trail;
|
||||
trail.parent = b;
|
||||
trail.AlphaValues.push_back(1.f);
|
||||
trail.AlphaValues.push_back(0.f);
|
||||
trail.ScaleValues.push_back(glm::vec3(0.08f));
|
||||
trail.ScaleValues.push_back(glm::vec3(0.f));
|
||||
trail.RadiusDistribution = 1;
|
||||
trail.EmitterLifeTime = 2.f;
|
||||
trail.ParticleLifeTime = 1.f;
|
||||
trail.ParticlesPerTick = 1;
|
||||
trail.SpawnRate = 0.1f;
|
||||
trail.Speed = 10.f;
|
||||
trail.EmittingAngle = glm::half_pi<float>();
|
||||
trail.SpriteFile = "Textures/Particles/FadeBall.png";
|
||||
trail.Color = brickModel->Color;
|
||||
//p.Spread = ...
|
||||
EventBroker->Publish(trail);
|
||||
|
||||
//ParticlePoof
|
||||
Events::CreateParticleSequence poof;
|
||||
poof.EmitterLifeTime = 4;
|
||||
poof.EmittingAngle = glm::half_pi<float>();
|
||||
poof.Spread = 0.5f;
|
||||
poof.NumberOfTicks = 1;
|
||||
poof.ParticleLifeTime = 1.5f;
|
||||
poof.ParticlesPerTick = 1;
|
||||
poof.Position = cTransform->Position;
|
||||
poof.ScaleValues.clear();
|
||||
poof.ScaleValues.push_back(glm::vec3(0.5f));
|
||||
poof.ScaleValues.push_back(glm::vec3(2.f, 2.f, 0.2f));
|
||||
poof.SpriteFile = "Textures/Particles/Cloud_Particle.png";
|
||||
poof.Color = brickModel->Color;
|
||||
poof.AlphaValues.clear();
|
||||
poof.AlphaValues.push_back(1.f);
|
||||
poof.AlphaValues.push_back(0.f);
|
||||
poof.Speed = 10;
|
||||
EventBroker->Publish(poof);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ void dd::Systems::PhysicsSystem::Initialize()
|
||||
{
|
||||
std::random_device rd;
|
||||
gen = std::mt19937(rd());
|
||||
m_DestructionListener = new DestructionListener(this);
|
||||
// m_DestructionListener = new DestructionListener(this);
|
||||
m_ContactListener = new ContactListener(this);
|
||||
m_PhysicsWorld = new b2World(m_Gravity);
|
||||
m_ParticleContactDisabler = new ParticleContactDisabler();
|
||||
m_PhysicsWorld->SetContactListener(m_ContactListener);
|
||||
m_PhysicsWorld->SetContactFilter(m_ParticleContactDisabler);
|
||||
m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
|
||||
// m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
|
||||
|
||||
InitializeWater();
|
||||
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
|
||||
@@ -231,8 +231,10 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
parentTransform = tp->Position;
|
||||
}
|
||||
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->Scale = particle->Scale;//glm::vec3(particle->Radius * 2.f, particle->Radius * 2.f, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,8 +248,9 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
||||
auto pTemplate = m_World->GetComponent<Components::Template>(entity);
|
||||
|
||||
if (particle && !pTemplate) {
|
||||
particle->LifeTime -= dt;
|
||||
if (particle->LifeTime <= 0) {
|
||||
particle->TimeLived += dt;
|
||||
//Delete particles
|
||||
if (particle->TimeLived >= particle->LifeTime - 0.1) {
|
||||
for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) {
|
||||
const b2ParticleHandle* handle = m_EntitiesToParticleHandle[i][entity];
|
||||
std::unordered_map<EntityID, const b2ParticleHandle*>::iterator iter1;
|
||||
@@ -263,10 +266,21 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
||||
m_World->RemoveEntity(entity);
|
||||
}
|
||||
}
|
||||
//Update alpha
|
||||
auto sprite = m_World->GetComponent<Components::Sprite>(entity);
|
||||
sprite->Color.w = particle->LifeTime;
|
||||
float timeProgress = particle->TimeLived / (particle->LifeTime - 0.1);
|
||||
if (timeProgress > 1) {
|
||||
timeProgress = 1;
|
||||
}
|
||||
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(particle->ParticleSystem);
|
||||
if (emitter) {
|
||||
sprite->Color.w = ScalarInterpolation(timeProgress, emitter->AlphaValues);
|
||||
particle->Scale = VectorInterpolation(timeProgress, emitter->ScaleValues);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Particlesystem relative to parent
|
||||
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(entity);
|
||||
if (emitter) {
|
||||
EntityID emitterParent = emitter->Parent;
|
||||
@@ -280,6 +294,43 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
||||
}
|
||||
}
|
||||
|
||||
float dd::Systems::PhysicsSystem::ScalarInterpolation(float timeProgress, std::vector<float> spectrum)
|
||||
{
|
||||
int spectrumSize = spectrum.size();
|
||||
if (spectrumSize == 0) {
|
||||
return 1.f;
|
||||
}
|
||||
if (spectrumSize == 1) {
|
||||
return spectrum[0];
|
||||
}
|
||||
|
||||
float dValue = spectrum[1] - spectrum[0];
|
||||
float scalar = spectrum[0] + dValue * timeProgress;
|
||||
|
||||
return scalar;
|
||||
}
|
||||
|
||||
glm::vec3 dd::Systems::PhysicsSystem::VectorInterpolation(float timeProgress, std::vector<glm::vec3> spectrum)
|
||||
{
|
||||
int spectrumSize = spectrum.size();
|
||||
if (spectrumSize == 0) {
|
||||
LOG_ERROR("You need to supply your particlesystem with scales in ScaleValues.");
|
||||
return glm::vec3(1);
|
||||
}
|
||||
else if (spectrumSize == 1) {
|
||||
return spectrum[0];
|
||||
}
|
||||
|
||||
float dX = spectrum[1].x - spectrum[0].x;
|
||||
float x = spectrum[0].x + dX * timeProgress;
|
||||
float dY = spectrum[1].y - spectrum[0].y;
|
||||
float y = spectrum[0].y + dY * timeProgress;
|
||||
float dZ = spectrum[1].z - spectrum[0].z;
|
||||
float z = spectrum[0].z + dZ * timeProgress;
|
||||
|
||||
return glm::vec3(x, y, z);
|
||||
}
|
||||
|
||||
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
|
||||
{
|
||||
if (event.Type != "PhysicsSystem" && event.Type != "All") {
|
||||
@@ -332,7 +383,6 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
|
||||
m_BodiesToEntities.erase(it->second);
|
||||
m_EntitiesToBodies.erase(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -473,44 +523,70 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
if(emitter->TimeSinceLastSpawn < emitter->SpawnRate || emitter->NumberOfTicks < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
emitter->NumberOfTicks--;
|
||||
emitter->TimeSinceLastSpawn -= emitter->SpawnRate;
|
||||
auto templateTransform = m_World->GetComponent<Components::Transform>(pt);
|
||||
b2ParticleDef particleDef;
|
||||
|
||||
//Create new particle
|
||||
for ( int j = 0; j < emitter->ParticlesPerTick; j++) {
|
||||
b2ParticleDef particleDef;
|
||||
//position
|
||||
particleDef.position = b2Vec2(emitterTransform->Position.x, emitterTransform->Position.y);
|
||||
if (particleDef.position.x == 0.f && particleDef.position.y == 0.f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto particle = m_World->CloneEntity(pt, 0);
|
||||
m_World->RemoveComponent<Components::Template>(particle);
|
||||
auto particleTransform = m_World->GetComponent<Components::Transform>(particle);
|
||||
auto particleComponent = m_World->GetComponent<Components::Particle>(particle);
|
||||
|
||||
particleDef.flags = particleTemplate->Flags;
|
||||
//particleDef.color TODO: Implement this if we want color mixing and shit.
|
||||
particleDef.lifetime = particleTemplate->LifeTime;
|
||||
float eAngle = emitter->EmittingAngle;
|
||||
float halfSpread = emitter->Spread / 2;
|
||||
|
||||
//random angle
|
||||
float eAngle = emitter->EmittingAngle;
|
||||
float halfSpread = emitter->Spread / 2;
|
||||
std::uniform_real_distribution<float> dis(eAngle - halfSpread, eAngle + halfSpread);
|
||||
float pAngle = dis(gen);
|
||||
|
||||
//Using angle to determine velocity
|
||||
std::uniform_real_distribution<float> dis2(0.3, 1.5);
|
||||
float speedMultiplier = dis2(gen);
|
||||
glm::vec2 unitVec = glm::normalize(glm::vec2(glm::cos(pAngle), glm::sin(pAngle)));
|
||||
glm::vec2 vel = unitVec * emitter->Speed * (float)dt * speedMultiplier * 0.5f;
|
||||
glm::vec2 vel = unitVec * emitter->Speed * (float)dt * speedMultiplier;
|
||||
particleDef.velocity = b2Vec2(vel.x, vel.y);
|
||||
particleDef.position = b2Vec2(emitterTransform->Position.x, emitterTransform->Position.y);
|
||||
|
||||
//radius
|
||||
float radius = emitter->ScaleValues[0].x;
|
||||
float newRadius = 0;
|
||||
if (emitter->RadiusDistribution > 0) {
|
||||
float halfRadius = radius / 2;
|
||||
std::uniform_real_distribution<float> dis3(radius - halfRadius, radius + halfRadius);
|
||||
newRadius = dis3(gen);
|
||||
}
|
||||
else {
|
||||
newRadius = radius;
|
||||
}
|
||||
particleComponent->Scale = glm::vec3(newRadius);
|
||||
|
||||
|
||||
auto particle = m_World->CloneEntity(pt, 0);
|
||||
m_World->RemoveComponent<Components::Template>(particle);
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(particle);
|
||||
|
||||
//Random z-value
|
||||
std::uniform_real_distribution<float> dist(0, 1);
|
||||
float zDistribution = dist(gen);
|
||||
transform2->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->Position = glm::vec3(emitterTransform->Position.x, emitterTransform->Position.y, -9.5f + zDistribution);
|
||||
particleTransform->Scale = particleTemplate->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_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -523,7 +599,7 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
// std::cout << "Entities and handles: " << entHandles << std::endl;
|
||||
// LOG_INFO("Particles living: %i", pSizeTest);
|
||||
// LOG_INFO("Particle systems: %i", psListSize);
|
||||
// int entHandles = 0;
|
||||
// //int entHandles = 0;
|
||||
// for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++)
|
||||
// entHandles += m_EntitiesToParticleHandle[i].size();
|
||||
// LOG_INFO("Entities and handles: %i", entHandles);
|
||||
@@ -538,7 +614,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) {
|
||||
// DEBUG vvvvvv
|
||||
// int t_Entities = m_World->GetEntities()->size();
|
||||
// int t_Systems = m_ParticleEmitters.ParticleSystem.size();
|
||||
@@ -576,7 +652,7 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
m_ParticleEmitters.ParticleTemplate.erase(m_ParticleEmitters.ParticleTemplate.begin() + key);
|
||||
m_EntitiesToParticleHandle.erase(m_EntitiesToParticleHandle.begin() + key);
|
||||
m_ParticleHandleToEntities.erase(m_ParticleHandleToEntities.begin() + key);
|
||||
|
||||
emittersToDelete.clear();
|
||||
// DEBUG vvvvv
|
||||
// t_Entities = m_World->GetEntities()->size();
|
||||
// t_Systems = m_ParticleEmitters.ParticleSystem.size();
|
||||
@@ -609,14 +685,6 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int stp = 0;
|
||||
for (auto ts : m_EntitiesToParticleHandle)
|
||||
{
|
||||
stp += ts.size();
|
||||
}
|
||||
}
|
||||
|
||||
bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreateParticleSequence &event)
|
||||
@@ -640,21 +708,23 @@ bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreatePart
|
||||
particleEmitter->Spread = event.Spread;
|
||||
particleEmitter->EmittingAngle = event.EmittingAngle;
|
||||
particleEmitter->LifeTime = event.EmitterLifeTime;
|
||||
|
||||
{
|
||||
//Creating Particle Template
|
||||
auto particle = m_World->CreateEntity(emitter);
|
||||
auto particleTransform = m_World->AddComponent<Components::Transform>(particle);
|
||||
auto sprite = m_World->AddComponent<Components::Sprite>(particle);
|
||||
auto particleComponent = m_World->AddComponent<Components::Particle>(particle);
|
||||
m_World->AddComponent<Components::Template>(particle);
|
||||
|
||||
particleTransform->Position = emitterTransform->Position;
|
||||
sprite->SpriteFile = event.SpriteFile;
|
||||
particleEmitter->AlphaValues = event.AlphaValues;
|
||||
particleEmitter->ScaleValues = event.ScaleValues;
|
||||
particleEmitter->RadiusDistribution = event.RadiusDistribution;
|
||||
{
|
||||
//Creating Particle Template
|
||||
auto particle = m_World->CreateEntity(emitter);
|
||||
auto particleTransform = m_World->AddComponent<Components::Transform>(particle);
|
||||
auto sprite = m_World->AddComponent<Components::Sprite>(particle);
|
||||
auto particleComponent = m_World->AddComponent<Components::Particle>(particle);
|
||||
m_World->AddComponent<Components::Template>(particle);
|
||||
particleTransform->Position = emitterTransform->Position;
|
||||
sprite->SpriteFile = event.SpriteFile;
|
||||
sprite->Color = event.Color;
|
||||
particleComponent->LifeTime = event.ParticleLifeTime;
|
||||
particleComponent->Flags = event.Flags;
|
||||
particleComponent->Radius = event.Radius;
|
||||
particleComponent->LifeTime = event.ParticleLifeTime;
|
||||
particleComponent->Flags = event.Flags;
|
||||
particleComponent->Scale = event.ScaleValues[0];
|
||||
particleComponent->ParticleSystem = emitter;
|
||||
}
|
||||
m_World->CommitEntity(emitter);
|
||||
return true;
|
||||
@@ -691,7 +761,7 @@ void dd::Systems::PhysicsSystem::CreateParticleEmitter(EntityID entity)
|
||||
}
|
||||
//TODO: Skicka med fler flaggor till particlesystemet;
|
||||
|
||||
m_ParticleEmitters.ParticleSystem.push_back(CreateParticleSystem(particle->Radius, 0.f, 0));
|
||||
m_ParticleEmitters.ParticleSystem.push_back(CreateParticleSystem(particle->Scale.x, 0.f, 0));
|
||||
m_ParticleEmitters.ParticleEmitter.push_back(entity);
|
||||
m_ParticleEmitters.ParticleTemplate.push_back(childEntity);
|
||||
}
|
||||
@@ -708,18 +778,18 @@ b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius,
|
||||
m_ParticleSystemDef.maxCount = maxCount;
|
||||
m_ParticleSystemDef.radius = radius;
|
||||
m_ParticleSystemDef.gravityScale = gravityScale;
|
||||
m_ParticleSystemDef.destroyByAge = true;
|
||||
m_ParticleSystemDef.destroyByAge = false;
|
||||
|
||||
return m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
||||
}
|
||||
|
||||
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);
|
||||
EntityID entity = event.Entity1;
|
||||
Components::Model* model;
|
||||
|
||||
auto ball = m_World->GetComponent<Components::Ball>(event.Entity2);
|
||||
if (!brick) {
|
||||
brick = m_World->GetComponent<Components::Brick>(event.Entity2);
|
||||
EntityID entity = event.Entity2;
|
||||
@@ -730,14 +800,19 @@ bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
||||
model = m_World->GetComponent<Components::Model>(event.Entity2);
|
||||
}
|
||||
}
|
||||
else if (!ball) {
|
||||
ball = m_World->GetComponent<Components::Ball>(event.Entity1);
|
||||
if (!ball) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
model = m_World->GetComponent<Components::Model>(event.Entity1);
|
||||
}
|
||||
|
||||
//Spawn a particle when a brick collides with somthing
|
||||
Events::CreateParticleSequence e;
|
||||
|
||||
|
||||
e.EmitterLifeTime = 3;
|
||||
e.EmittingAngle = glm::half_pi<float>();
|
||||
e.Spread = 0.f;
|
||||
@@ -746,7 +821,9 @@ bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
||||
e.ParticlesPerTick = 1;
|
||||
e.Position = glm::vec3(event.IntersectionPoint.x, event.IntersectionPoint.y, -7);
|
||||
e.Color = glm::vec4(1.f);
|
||||
e.Radius = 1.f;
|
||||
e.AlphaValues.push_back(1.f);
|
||||
e.AlphaValues.push_back(0.f);
|
||||
e.ScaleValues.push_back(glm::vec3(1.f));
|
||||
e.Speed = 0;
|
||||
|
||||
auto PowerFriend = m_World->GetComponent<Components::MultiBallBrick>(entity);
|
||||
@@ -771,13 +848,18 @@ bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
||||
e.EmittingAngle = glm::half_pi<float>();
|
||||
e.Spread = 0.5f;
|
||||
e.NumberOfTicks = 1;
|
||||
e.ParticleLifeTime = 1.f;
|
||||
e.ParticlesPerTick = 15;
|
||||
e.ParticleLifeTime = 0.5f;
|
||||
e.ParticlesPerTick = 1;
|
||||
e.Position = glm::vec3(event.IntersectionPoint.x, event.IntersectionPoint.y, -10);
|
||||
e.Radius = 0.2f;
|
||||
e.ScaleValues.clear();
|
||||
e.ScaleValues.push_back(glm::vec3(0.5f));
|
||||
e.ScaleValues.push_back(glm::vec3(4.f, 4.f, 0.2f));
|
||||
e.SpriteFile = "Textures/Particles/Cloud_Particle.png";
|
||||
e.Color = model->Color + glm::vec4(0.5f);
|
||||
e.Speed = 100;
|
||||
e.Color = model->Color;
|
||||
e.AlphaValues.clear();
|
||||
e.AlphaValues.push_back(1.f);
|
||||
e.AlphaValues.push_back(0.f);
|
||||
//e.Speed = 0;
|
||||
}
|
||||
|
||||
EventBroker->Publish(e);
|
||||
|
||||
Reference in New Issue
Block a user