From b69413d9c9a78ae380126c6ba37e8d32399b579c Mon Sep 17 00:00:00 2001 From: tleety Date: Thu, 17 Sep 2015 17:35:17 +0200 Subject: [PATCH] Base water set up --- include/Core/Engine.h | 20 +++++---- include/Game/LevelSystem.h | 2 +- include/Game/PadSystem.h | 2 +- .../{CBoxShape.h => CRectangleShape.h} | 0 include/Physics/CWaterVolume.h | 19 ++++++++ include/Physics/PhysicsSystem.h | 12 ++++- src/game/Physics/PhysicsSystem.cpp | 44 +++++++++++++------ 7 files changed, 73 insertions(+), 26 deletions(-) rename include/Physics/{CBoxShape.h => CRectangleShape.h} (100%) create mode 100755 include/Physics/CWaterVolume.h mode change 100644 => 100755 include/Physics/PhysicsSystem.h mode change 100644 => 100755 src/game/Physics/PhysicsSystem.cpp diff --git a/include/Core/Engine.h b/include/Core/Engine.h index 06adf81..fc644e9 100755 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -44,8 +44,9 @@ #include "Physics/PhysicsSystem.h" #include "Physics/CPhysics.h" -#include "Physics/CBoxShape.h" +#include "Physics/CRectangleShape.h" #include "Physics/ESetImpulse.h" +#include "Physics/CWaterVolume.h" namespace dd { @@ -91,6 +92,7 @@ public: m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); m_World->Initialize(); @@ -145,15 +147,15 @@ public: model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj"; } - //Brick test model + //Water test { - auto t_Brick = m_World->CreateEntity(); - auto transform = m_World->AddComponent(t_Brick); - transform->Position = glm::vec3(0.f, 0.f, -12.f); - transform->Orientation = glm::rotate(glm::quat(), 0.5f, glm::vec3(0,-1,-1)); - auto model = m_World->AddComponent(t_Brick); - model->ModelFile = "Models/Test/Brick/Brick.obj"; - + auto t_waterBody = m_World->CreateEntity(); + auto transform = m_World->AddComponent(t_waterBody); + transform->Position = glm::vec3(0.f, 0.f, -10.f); + auto water = m_World->AddComponent(t_waterBody); + auto sprite = m_World->AddComponent(t_waterBody); + sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png"; + auto body = m_World->AddComponent(t_waterBody); } { diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h index 786355f..7d02de0 100755 --- a/include/Game/LevelSystem.h +++ b/include/Game/LevelSystem.h @@ -18,7 +18,7 @@ #include "Game/ELifeLost.h" #include "Game/EResetBall.h" #include "Game/EScoreEvent.h" -#include "Physics/CBoxShape.h" +#include "Physics/CRectangleShape.h" #include "Physics/CPhysics.h" #include "Physics/CCircleShape.h" #include "Physics/ESetImpulse.h" diff --git a/include/Game/PadSystem.h b/include/Game/PadSystem.h index 4a21df7..cee9568 100755 --- a/include/Game/PadSystem.h +++ b/include/Game/PadSystem.h @@ -14,7 +14,7 @@ #include "Core/EKeyUp.h" #include "Input/EBindKey.h" #include "Physics/EContact.h" -#include "Physics/CBoxShape.h" +#include "Physics/CRectangleShape.h" #include "Physics/CPhysics.h" #include "Physics/CCircleShape.h" #include "Physics/ESetImpulse.h" diff --git a/include/Physics/CBoxShape.h b/include/Physics/CRectangleShape.h similarity index 100% rename from include/Physics/CBoxShape.h rename to include/Physics/CRectangleShape.h diff --git a/include/Physics/CWaterVolume.h b/include/Physics/CWaterVolume.h new file mode 100755 index 0000000..33adcae --- /dev/null +++ b/include/Physics/CWaterVolume.h @@ -0,0 +1,19 @@ +#ifndef CWATERVOLUME_H +#define CWATERVOLUME_H +#include "Core/Component.h" + +namespace dd +{ +namespace Components +{ + +struct WaterVolume : public Component +{ + +}; + +} + +} + +#endif \ No newline at end of file diff --git a/include/Physics/PhysicsSystem.h b/include/Physics/PhysicsSystem.h old mode 100644 new mode 100755 index 4b19098..4217d10 --- a/include/Physics/PhysicsSystem.h +++ b/include/Physics/PhysicsSystem.h @@ -5,7 +5,7 @@ #include "Core/System.h" #include "Core/World.h" -#include "Physics/CBoxShape.h" +#include "CRectangleShape.h" #include "Physics/CPhysics.h" #include #include "Core/CTransform.h" @@ -14,6 +14,7 @@ #include "Physics/ESetImpulse.h" #include "Physics/CCircleShape.h" #include "Core/EventBroker.h" +#include "Physics/CWaterVolume.h" namespace dd @@ -64,6 +65,15 @@ private: void CreateBody(EntityID entity); + const b2ParticleSystemDef m_ParticleSystemDef; + b2ParticleSystem *m_ParticleSystem; + + + void InitializeWater(); + void SyncWater(); //TODO: Probably remove this + void CreateParticleGroup(EntityID entity); + + class ContactListener : public b2ContactListener { diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp old mode 100644 new mode 100755 index 41d1166..5be8beb --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -25,6 +25,11 @@ void dd::Systems::PhysicsSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, PhysicsSystem::SetImpulse); } +void dd::Systems::PhysicsSystem::InitializeWater() +{ + m_ParticleSystem = m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef); +} + bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event) { b2Body* body = m_EntitiesToBodies[event.Entity]; @@ -57,7 +62,6 @@ void dd::Systems::PhysicsSystem::Update(double dt) continue; } - if (m_World->GetEntityParent(entity) == 0) { b2Vec2 position; position.x = transformComponent->Position.x; @@ -69,9 +73,6 @@ void dd::Systems::PhysicsSystem::Update(double dt) } } - - - m_Accumulator += dt; while(m_Accumulator >= m_TimeStep) { @@ -79,14 +80,6 @@ void dd::Systems::PhysicsSystem::Update(double dt) m_Accumulator -= dt; } - - - - - - - - for (auto i : m_EntitiesToBodies) { EntityID entity = i.first; b2Body* body = i.second; @@ -118,13 +111,17 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity } - void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity) { auto physicsComponent = m_World->GetComponent(entity); - if(physicsComponent) { + auto waterComponent = m_World->GetComponent(entity); + + if (physicsComponent) { CreateBody(entity); } + if (waterComponent) { + CreateParticleGroup(entity); + } } @@ -216,6 +213,25 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity) m_BodiesToEntities.insert(std::make_pair(body, entity)); } +void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e) +{ + //TODO: Lägg alla pd i en lista + auto transform = m_World->GetComponent(e); + if (!transform) { + LOG_ERROR("No Transform component in CreateParticleGroup"); + return; + } + LOG_INFO("------ CREATING PARTICLE GROUP"); + + b2ParticleGroupDef pd; + b2PolygonShape shape; + shape.SetAsBox(transform->Scale.x, transform->Scale.y); + pd.shape = &shape; + pd.flags = b2_elasticParticle; + pd.angle = -0.5f; + pd.angularVelocity = 2.0f; +} + dd::Systems::PhysicsSystem::~PhysicsSystem() { if (m_ContactListener != nullptr) {