Base water set up
This commit is contained in:
+11
-9
@@ -44,8 +44,9 @@
|
|||||||
|
|
||||||
#include "Physics/PhysicsSystem.h"
|
#include "Physics/PhysicsSystem.h"
|
||||||
#include "Physics/CPhysics.h"
|
#include "Physics/CPhysics.h"
|
||||||
#include "Physics/CBoxShape.h"
|
#include "Physics/CRectangleShape.h"
|
||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
|
#include "Physics/CWaterVolume.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
@@ -91,6 +92,7 @@ public:
|
|||||||
m_World->ComponentFactory.Register<Components::Model>();
|
m_World->ComponentFactory.Register<Components::Model>();
|
||||||
m_World->ComponentFactory.Register<Components::Template>();
|
m_World->ComponentFactory.Register<Components::Template>();
|
||||||
m_World->ComponentFactory.Register<Components::PointLight>();
|
m_World->ComponentFactory.Register<Components::PointLight>();
|
||||||
|
m_World->ComponentFactory.Register<Components::WaterVolume>();
|
||||||
m_World->Initialize();
|
m_World->Initialize();
|
||||||
|
|
||||||
|
|
||||||
@@ -145,15 +147,15 @@ public:
|
|||||||
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Brick test model
|
//Water test
|
||||||
{
|
{
|
||||||
auto t_Brick = m_World->CreateEntity();
|
auto t_waterBody = m_World->CreateEntity();
|
||||||
auto transform = m_World->AddComponent<Components::Transform>(t_Brick);
|
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
|
||||||
transform->Position = glm::vec3(0.f, 0.f, -12.f);
|
transform->Position = glm::vec3(0.f, 0.f, -10.f);
|
||||||
transform->Orientation = glm::rotate(glm::quat(), 0.5f, glm::vec3(0,-1,-1));
|
auto water = m_World->AddComponent<Components::WaterVolume>(t_waterBody);
|
||||||
auto model = m_World->AddComponent<Components::Model>(t_Brick);
|
auto sprite = m_World->AddComponent<Components::Sprite>(t_waterBody);
|
||||||
model->ModelFile = "Models/Test/Brick/Brick.obj";
|
sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png";
|
||||||
|
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include "Game/ELifeLost.h"
|
#include "Game/ELifeLost.h"
|
||||||
#include "Game/EResetBall.h"
|
#include "Game/EResetBall.h"
|
||||||
#include "Game/EScoreEvent.h"
|
#include "Game/EScoreEvent.h"
|
||||||
#include "Physics/CBoxShape.h"
|
#include "Physics/CRectangleShape.h"
|
||||||
#include "Physics/CPhysics.h"
|
#include "Physics/CPhysics.h"
|
||||||
#include "Physics/CCircleShape.h"
|
#include "Physics/CCircleShape.h"
|
||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include "Core/EKeyUp.h"
|
#include "Core/EKeyUp.h"
|
||||||
#include "Input/EBindKey.h"
|
#include "Input/EBindKey.h"
|
||||||
#include "Physics/EContact.h"
|
#include "Physics/EContact.h"
|
||||||
#include "Physics/CBoxShape.h"
|
#include "Physics/CRectangleShape.h"
|
||||||
#include "Physics/CPhysics.h"
|
#include "Physics/CPhysics.h"
|
||||||
#include "Physics/CCircleShape.h"
|
#include "Physics/CCircleShape.h"
|
||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
|
|||||||
Executable
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef CWATERVOLUME_H
|
||||||
|
#define CWATERVOLUME_H
|
||||||
|
#include "Core/Component.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct WaterVolume : public Component
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Regular → Executable
+11
-1
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
#include "Physics/CBoxShape.h"
|
#include "CRectangleShape.h"
|
||||||
#include "Physics/CPhysics.h"
|
#include "Physics/CPhysics.h"
|
||||||
#include <Box2D/Box2D.h>
|
#include <Box2D/Box2D.h>
|
||||||
#include "Core/CTransform.h"
|
#include "Core/CTransform.h"
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
#include "Physics/CCircleShape.h"
|
#include "Physics/CCircleShape.h"
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Physics/CWaterVolume.h"
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
@@ -64,6 +65,15 @@ private:
|
|||||||
|
|
||||||
void CreateBody(EntityID entity);
|
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
|
class ContactListener : public b2ContactListener
|
||||||
{
|
{
|
||||||
|
|||||||
Regular → Executable
+30
-14
@@ -25,6 +25,11 @@ void dd::Systems::PhysicsSystem::Initialize()
|
|||||||
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, PhysicsSystem::SetImpulse);
|
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)
|
bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
||||||
{
|
{
|
||||||
b2Body* body = m_EntitiesToBodies[event.Entity];
|
b2Body* body = m_EntitiesToBodies[event.Entity];
|
||||||
@@ -57,7 +62,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (m_World->GetEntityParent(entity) == 0) {
|
if (m_World->GetEntityParent(entity) == 0) {
|
||||||
b2Vec2 position;
|
b2Vec2 position;
|
||||||
position.x = transformComponent->Position.x;
|
position.x = transformComponent->Position.x;
|
||||||
@@ -69,9 +73,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m_Accumulator += dt;
|
m_Accumulator += dt;
|
||||||
while(m_Accumulator >= m_TimeStep)
|
while(m_Accumulator >= m_TimeStep)
|
||||||
{
|
{
|
||||||
@@ -79,14 +80,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
m_Accumulator -= dt;
|
m_Accumulator -= dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (auto i : m_EntitiesToBodies) {
|
for (auto i : m_EntitiesToBodies) {
|
||||||
EntityID entity = i.first;
|
EntityID entity = i.first;
|
||||||
b2Body* body = i.second;
|
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)
|
void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
|
||||||
{
|
{
|
||||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||||
if(physicsComponent) {
|
auto waterComponent = m_World->GetComponent<Components::WaterVolume>(entity);
|
||||||
|
|
||||||
|
if (physicsComponent) {
|
||||||
CreateBody(entity);
|
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));
|
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<Components::Transform>(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()
|
dd::Systems::PhysicsSystem::~PhysicsSystem()
|
||||||
{
|
{
|
||||||
if (m_ContactListener != nullptr) {
|
if (m_ContactListener != nullptr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user