Partycles.
This commit is contained in:
+5
-16
@@ -227,9 +227,10 @@ public:
|
||||
|
||||
transform->Position = glm::vec3(0.f, 0.f, -10.f);
|
||||
particleEmitter->GravityScale = 0.0f;
|
||||
particleEmitter->SpawnRate = 0.1f;
|
||||
particleEmitter->SpawnRate = 1.1f;
|
||||
particleEmitter->NumberOfTicks = 1000;
|
||||
particleEmitter->Speed = 2.f;
|
||||
particleEmitter->ParticlesPerTick = 5;
|
||||
particleEmitter->Spread = glm::pi<float>()/2;
|
||||
particleEmitter->EmittingAngle = glm::pi<float>();
|
||||
|
||||
@@ -242,25 +243,13 @@ public:
|
||||
|
||||
//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::staticPressureParticle;
|
||||
PtSprite->SpriteFile = "Textures/Background.png";
|
||||
PtParticle->LifeTime = 1.f;
|
||||
PtParticle->Flags = ParticleFlags::Type::powderParticle | ParticleFlags::Type::particleContactFilterParticle | ParticleFlags::Type::fixtureContactFilterParticle;
|
||||
}
|
||||
m_World->CommitEntity(Pe);
|
||||
}
|
||||
|
||||
{
|
||||
auto Pt = m_World->CreateEntity();
|
||||
auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
|
||||
auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
|
||||
auto PtParticle = m_World->AddComponent<Components::Particle>(Pt);
|
||||
|
||||
PtTransform->Velocity = glm::vec3(1.0f, 0.f, 0.f);
|
||||
PtTransform->Position = glm::vec3(0.f, 0.f, -10.f);
|
||||
PtSprite->SpriteFile = "Textures/Ball.png";
|
||||
//PtModel->ModelFile = "Models/Brick/Brick.obj";
|
||||
}
|
||||
|
||||
//TODO: Why does the ball not collide with these bricks?
|
||||
//BottomBox
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ struct ParticleEmitter : public Component
|
||||
int NumberOfTicks = 10.f;
|
||||
float InitialSpeed = 1.f;
|
||||
double SpawnRate = 1;
|
||||
int ParticlesPerTick = 1;
|
||||
double TimeSinceLastSpawn = 0;
|
||||
int MaxCount = 0;
|
||||
float EmittingAngle = 0.f;
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace Systems
|
||||
class PhysicsSystem : public System
|
||||
{
|
||||
friend class ContractListener;
|
||||
friend class DestructionListener;
|
||||
|
||||
public:
|
||||
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
@@ -108,7 +109,36 @@ private:
|
||||
};
|
||||
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");
|
||||
|
||||
|
||||
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 ContactListener : public b2ContactListener
|
||||
{
|
||||
@@ -130,6 +160,7 @@ private:
|
||||
|
||||
m_PhysicsSystem->EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
void EndContact(b2Contact* contact)
|
||||
{
|
||||
|
||||
@@ -149,7 +180,6 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
|
||||
{
|
||||
@@ -160,6 +190,25 @@ private:
|
||||
PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
|
||||
class ParticleContactDisabler : public b2ContactFilter
|
||||
{
|
||||
public:
|
||||
ParticleContactDisabler() { };
|
||||
|
||||
//Particles to particles
|
||||
virtual bool ShouldCollide(b2ParticleSystem *particleSystem, int32 particleIndexA, int32 particleIndexB)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool ShouldCollide(b2Fixture* fixture, b2ParticleSystem* particleSystem, int32 particleIndex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
DestructionListener* m_DestructionListener;
|
||||
ParticleContactDisabler m_ParticleContactDisabler;
|
||||
ContactListener* m_ContactListener;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user