From ad082e89d8b002a699545ae38802ae8ea43db298 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 13 Mar 2014 03:29:21 +0100 Subject: [PATCH] Debug: red bounding boxes when colliding --- Escape-the-Dawn/Systems/CollisionSystem.cpp | 12 +++++++++--- Escape-the-Dawn/Systems/PlayerSystem.cpp | 5 +++-- Escape-the-Dawn/Systems/RenderSystem.cpp | 3 ++- Escape-the-Dawn/Systems/RenderSystem.h | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Escape-the-Dawn/Systems/CollisionSystem.cpp b/Escape-the-Dawn/Systems/CollisionSystem.cpp index 8cd9c53..097f05f 100644 --- a/Escape-the-Dawn/Systems/CollisionSystem.cpp +++ b/Escape-the-Dawn/Systems/CollisionSystem.cpp @@ -3,7 +3,7 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { - if (parent != 0) + /*if (parent != 0) { auto transform = m_World->GetComponent(entity, "Transform"); auto parentTransform = m_World->GetComponent(parent, "Transform"); @@ -11,8 +11,14 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID transform->Position[0] += parentTransform->Position[0]; transform->Position[1] += parentTransform->Position[1]; transform->Position[2] += parentTransform->Position[2]; - } - LOG_INFO("Updating entity %i with parent %i", entity, parent); + }*/ + + auto collisionComponent = m_World->GetComponent(entity, "Collision"); + if (!collisionComponent) + return; + + // Clear old collisions + collisionComponent->CollidingEntities.clear(); auto entities = m_World->GetEntities(); diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 91e0731..dc237df 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -61,8 +61,9 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa } auto collision = m_World->GetComponent(entity, "Collision"); - if(collision->CollidingEntities.size() != 0) - int c = 1; // lol + if(collision->CollidingEntities.size() > 0) { + // DO STUFF + } } diff --git a/Escape-the-Dawn/Systems/RenderSystem.cpp b/Escape-the-Dawn/Systems/RenderSystem.cpp index 899b3dd..3165a0f 100644 --- a/Escape-the-Dawn/Systems/RenderSystem.cpp +++ b/Escape-the-Dawn/Systems/RenderSystem.cpp @@ -30,11 +30,12 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p // Debug draw bounds #ifdef DEBUG + auto collision = m_World->GetComponent(entity, "Collision"); auto bounds = m_World->GetComponent(entity, "Bounds"); if (bounds != nullptr) { glm::vec3 origin = transformComponent->Position + (transformComponent->Scale * bounds->Origin); glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector; - m_Renderer->AddAABBToDraw(origin, volumeVector, true); + m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0)); } #endif diff --git a/Escape-the-Dawn/Systems/RenderSystem.h b/Escape-the-Dawn/Systems/RenderSystem.h index 85ac40e..d2a182f 100644 --- a/Escape-the-Dawn/Systems/RenderSystem.h +++ b/Escape-the-Dawn/Systems/RenderSystem.h @@ -10,6 +10,7 @@ #include "Components/Transform.h" #include "Components/Camera.h" #include "Components/Bounds.h" +#include "Components/Collision.h" #include "Renderer.h" namespace Systems