diff --git a/include/Engine/Core/OctTree.h b/include/Engine/Core/OctTree.h index a3715480..c09ab63e 100644 --- a/include/Engine/Core/OctTree.h +++ b/include/Engine/Core/OctTree.h @@ -4,8 +4,6 @@ #include "Core/AABB.h" struct Ray; -class World; -class Camera; class OctTree { @@ -20,8 +18,8 @@ public: //For the root OctTree, [octTreeBounds] should be a box containing the entire level. OctTree(const AABB& octTreeBounds, int subDivisions); - //We should only ever need one OctTree in the game, and it should not need to be copied. - //Define these if the OctTree suddenly needs to be copied, think of the children OctTree* ptrs. + //We cannot copy the OctTree as of now, because of the recursive dynamic allocation. + //Define these if the OctTree suddenly needs to be copied, think of the children OctChild* ptrs. OctTree(const OctTree& other) = delete; OctTree(const OctTree&& other) = delete; OctTree& operator= (const OctTree& other) = delete; @@ -36,8 +34,6 @@ public: //Empty the tree of all dynamic objects. Static objects remain in the tree. void ClearDynamicObjects(); - //Collision test function. WTODO: Probably remove or relocate elsewhere, Collision system? - void Update(float dt, World* world, Camera* cam); //Returns true if the ray collides with something in the tree. Result is written to [data]. bool RayCollides(const Ray& ray, Output& data); //Returns true if the box collides with something in the tree. diff --git a/src/Engine/Core/OctTree.cpp b/src/Engine/Core/OctTree.cpp index 8c262faf..31b32cec 100644 --- a/src/Engine/Core/OctTree.cpp +++ b/src/Engine/Core/OctTree.cpp @@ -4,8 +4,6 @@ #include "Core/OctTree.h" #include "Collision/Collision.h" -#include "Core/World.h" -#include "Rendering/Camera.h" namespace { @@ -151,52 +149,6 @@ OctTree::OctChild::~OctChild() } } -void OctTree::Update(float dt, World* world, Camera* cam) -{ - for (ComponentWrapper& c : *world->GetComponents("Collision")) { - AABB aabb; - aabb.CreateFromCenter(c["BoxCenter"], c["BoxSize"]); - AddDynamicObject(aabb); - } - const glm::vec4 redCol = glm::vec4(1, 0.2f, 0, 1); - const glm::vec4 greenCol = glm::vec4(0.1f, 1.0f, 0.25f, 1); - const glm::vec4 blueCol = glm::vec4(0.1f, 0.05f, 0.95f, 1); - const glm::vec4 cyanCol = glm::vec4(0.1f, 0.9f, 0.85f, 1); - const glm::vec3 boxSize = 0.05f*glm::vec3(1.0f, 1.0f, 1.0f); - - if (!m_UpdatedOnce) { - m_BoxID = world->CreateEntity(); - ComponentWrapper transform = world->AttachComponent(m_BoxID, "Transform"); - transform["Scale"] = boxSize; - - ComponentWrapper model = world->AttachComponent(m_BoxID, "Model"); - model["Resource"] = "Models/Core/UnitBox.obj"; - m_UpdatedOnce = true; - } - - AABB box; - auto boxPos = cam->Position() + 1.2f*cam->Forward(); - box.CreateFromCenter(boxPos, boxSize); - ComponentWrapper transform = world->GetComponent(m_BoxID, "Transform"); - transform["Position"] = boxPos; - ComponentWrapper model = world->GetComponent(m_BoxID, "Model"); - bool collBox = BoxCollides(box, AABB()); - if (collBox) { - cam->SetPosition(m_PrevPos); - cam->SetOrientation(m_PrevOri); - bool collRay = RayCollides({ cam->Position(), cam->Forward() }, Output()); - model["Color"] = collRay ? cyanCol : greenCol; - } else if (RayCollides({ cam->Position(), cam->Forward() }, Output())) { - model["Color"] = blueCol; - } else { - model["Color"] = redCol; - } - - m_PrevPos = cam->Position(); - m_PrevOri = cam->Orientation(); - ClearDynamicObjects(); -} - bool OctTree::OctChild::BoxCollides(const AABB& boxToTest, AABB& outBoxIntersected) const { if (hasChildren()) {