Renamed all OctTree to Octree (More OCD)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#ifndef OctTree_h__
|
||||
#define OctTree_h__
|
||||
#ifndef Octree_h__
|
||||
#define Octree_h__
|
||||
|
||||
#include "Core/AABB.h"
|
||||
|
||||
class Ray;
|
||||
|
||||
class OctTree
|
||||
class Octree
|
||||
{
|
||||
public:
|
||||
struct Output
|
||||
@@ -13,16 +13,16 @@ public:
|
||||
float CollideDistance;
|
||||
};
|
||||
|
||||
OctTree();
|
||||
~OctTree();
|
||||
//For the root OctTree, [octTreeBounds] should be a box containing the entire level.
|
||||
OctTree(const AABB& octTreeBounds, int subDivisions);
|
||||
Octree();
|
||||
~Octree();
|
||||
//For the root Octree, [octreeBounds] should be a box containing the entire level.
|
||||
Octree(const AABB& octreeBounds, int subDivisions);
|
||||
|
||||
//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;
|
||||
//We cannot copy the Octree as of now, because of the recursive dynamic allocation.
|
||||
//Define these if the Octree suddenly needs to be copied, think of the children Child* ptrs.
|
||||
Octree(const Octree& other) = delete;
|
||||
Octree(const Octree&& other) = delete;
|
||||
Octree& operator= (const Octree& other) = delete;
|
||||
//Add a dynamic object (one that moves around) into the tree.
|
||||
void AddDynamicObject(const AABB& box);
|
||||
//Add a static object (that does not move) into the tree.
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
bool BoxCollides(const AABB& boxToTest, AABB& outBoxIntersected);
|
||||
|
||||
private:
|
||||
struct OctChild; //Fwd declaration;
|
||||
struct Child; //Fwd declaration;
|
||||
struct ContainedObject
|
||||
{
|
||||
ContainedObject()
|
||||
@@ -56,7 +56,7 @@ private:
|
||||
AABB Box;
|
||||
bool Checked;
|
||||
};
|
||||
OctChild* m_Root;
|
||||
Child* m_Root;
|
||||
std::vector<ContainedObject> m_StaticObjects;
|
||||
std::vector<ContainedObject> m_DynamicObjects;
|
||||
|
||||
@@ -67,16 +67,16 @@ private:
|
||||
|
||||
void falsifyObjectChecks();
|
||||
|
||||
struct OctChild
|
||||
struct Child
|
||||
{
|
||||
~OctChild();
|
||||
OctChild(const AABB& octTreeBounds,
|
||||
~Child();
|
||||
Child(const AABB& octTreeBounds,
|
||||
int subDivisions,
|
||||
std::vector<OctTree::ContainedObject>& staticObjects,
|
||||
std::vector<OctTree::ContainedObject>& dynamicObjects);
|
||||
OctChild(const OctChild& other) = delete;
|
||||
OctChild(const OctChild&& other) = delete;
|
||||
OctChild& operator= (const OctChild& other) = delete;
|
||||
std::vector<Octree::ContainedObject>& staticObjects,
|
||||
std::vector<Octree::ContainedObject>& dynamicObjects);
|
||||
Child(const Child& other) = delete;
|
||||
Child(const Child&& other) = delete;
|
||||
Child& operator= (const Child& other) = delete;
|
||||
void AddDynamicObject(const AABB& box);
|
||||
void AddStaticObject(const AABB& box);
|
||||
void BoxesInSameRegion(const AABB& box, std::vector<AABB>& outBoxes) const;
|
||||
@@ -85,14 +85,14 @@ private:
|
||||
bool RayCollides(const Ray& ray, Output& data) const;
|
||||
bool BoxCollides(const AABB& boxToTest, AABB& outBoxIntersected) const;
|
||||
|
||||
OctChild* m_Children[8];
|
||||
//Indices into the lists in OctTree.
|
||||
Child* m_Children[8];
|
||||
//Indices into the lists in Octree.
|
||||
std::vector<int> m_StaticObjIndices;
|
||||
std::vector<int> m_DynamicObjIndices;
|
||||
AABB m_Box;
|
||||
//Reference to the lists in OctTree.
|
||||
std::vector<OctTree::ContainedObject>& m_StaticObjectsRef;
|
||||
std::vector<OctTree::ContainedObject>& m_DynamicObjectsRef;
|
||||
//Reference to the lists in Octree.
|
||||
std::vector<Octree::ContainedObject>& m_StaticObjectsRef;
|
||||
std::vector<Octree::ContainedObject>& m_DynamicObjectsRef;
|
||||
|
||||
inline bool hasChildren() const;
|
||||
int childIndexContainingPoint(const glm::vec3& point) const;
|
||||
|
||||
+30
-30
@@ -21,65 +21,65 @@ bool isFirstLower(const ChildInfo& first, const ChildInfo& second)
|
||||
|
||||
}
|
||||
|
||||
OctTree::OctTree()
|
||||
: OctTree(AABB(), 0)
|
||||
Octree::Octree()
|
||||
: Octree(AABB(), 0)
|
||||
{}
|
||||
|
||||
OctTree::OctTree(const AABB& octTreeBounds, int subDivisions)
|
||||
: m_Root(new OctChild(octTreeBounds, subDivisions, m_StaticObjects, m_DynamicObjects))
|
||||
Octree::Octree(const AABB& octTreeBounds, int subDivisions)
|
||||
: m_Root(new Child(octTreeBounds, subDivisions, m_StaticObjects, m_DynamicObjects))
|
||||
, m_UpdatedOnce(false)
|
||||
{}
|
||||
|
||||
OctTree::~OctTree()
|
||||
Octree::~Octree()
|
||||
{
|
||||
delete m_Root;
|
||||
}
|
||||
|
||||
void OctTree::AddDynamicObject(const AABB& box)
|
||||
void Octree::AddDynamicObject(const AABB& box)
|
||||
{
|
||||
m_Root->AddDynamicObject(box);
|
||||
m_DynamicObjects.push_back(box);
|
||||
}
|
||||
|
||||
void OctTree::AddStaticObject(const AABB& box)
|
||||
void Octree::AddStaticObject(const AABB& box)
|
||||
{
|
||||
m_Root->AddStaticObject(box);
|
||||
m_StaticObjects.push_back(box);
|
||||
}
|
||||
|
||||
void OctTree::BoxesInSameRegion(const AABB& box, std::vector<AABB>& outBoxes)
|
||||
void Octree::BoxesInSameRegion(const AABB& box, std::vector<AABB>& outBoxes)
|
||||
{
|
||||
falsifyObjectChecks();
|
||||
m_Root->BoxesInSameRegion(box, outBoxes);
|
||||
}
|
||||
|
||||
void OctTree::ClearObjects()
|
||||
void Octree::ClearObjects()
|
||||
{
|
||||
m_StaticObjects.clear();
|
||||
m_DynamicObjects.clear();
|
||||
m_Root->ClearObjects();
|
||||
}
|
||||
|
||||
void OctTree::ClearDynamicObjects()
|
||||
void Octree::ClearDynamicObjects()
|
||||
{
|
||||
m_DynamicObjects.clear();
|
||||
m_Root->ClearDynamicObjects();
|
||||
}
|
||||
|
||||
bool OctTree::RayCollides(const Ray& ray, Output& data)
|
||||
bool Octree::RayCollides(const Ray& ray, Output& data)
|
||||
{
|
||||
falsifyObjectChecks();
|
||||
data.CollideDistance = -1;
|
||||
return m_Root->RayCollides(ray, data);
|
||||
}
|
||||
|
||||
bool OctTree::BoxCollides(const AABB& boxToTest, AABB& outBoxIntersected)
|
||||
bool Octree::BoxCollides(const AABB& boxToTest, AABB& outBoxIntersected)
|
||||
{
|
||||
falsifyObjectChecks();
|
||||
return m_Root->BoxCollides(boxToTest, outBoxIntersected);
|
||||
}
|
||||
|
||||
void OctTree::falsifyObjectChecks()
|
||||
void Octree::falsifyObjectChecks()
|
||||
{
|
||||
for (auto& obj : m_StaticObjects) {
|
||||
obj.Checked = false;
|
||||
@@ -89,7 +89,7 @@ void OctTree::falsifyObjectChecks()
|
||||
}
|
||||
}
|
||||
|
||||
OctTree::OctChild::OctChild(const AABB& octTreeBounds,
|
||||
Octree::Child::Child(const AABB& octTreeBounds,
|
||||
int subDivisions,
|
||||
std::vector<ContainedObject>& staticObjects,
|
||||
std::vector<ContainedObject>& dynamicObjects)
|
||||
@@ -98,7 +98,7 @@ OctTree::OctChild::OctChild(const AABB& octTreeBounds,
|
||||
, m_DynamicObjectsRef(dynamicObjects)
|
||||
{
|
||||
if (subDivisions == 0) {
|
||||
for (OctChild*& c : m_Children) {
|
||||
for (Child*& c : m_Children) {
|
||||
c = nullptr;
|
||||
}
|
||||
} else {
|
||||
@@ -134,14 +134,14 @@ OctTree::OctChild::OctChild(const AABB& octTreeBounds,
|
||||
minPos.z = parentMin.z;
|
||||
maxPos.z = parentCenter.z;
|
||||
}
|
||||
m_Children[i] = new OctChild(AABB(minPos, maxPos), subDivisions, m_StaticObjectsRef, m_DynamicObjectsRef);
|
||||
m_Children[i] = new Child(AABB(minPos, maxPos), subDivisions, m_StaticObjectsRef, m_DynamicObjectsRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OctTree::OctChild::~OctChild()
|
||||
Octree::Child::~Child()
|
||||
{
|
||||
for (OctChild*& c : m_Children) {
|
||||
for (Child*& c : m_Children) {
|
||||
if (c != nullptr) {
|
||||
delete c;
|
||||
c = nullptr;
|
||||
@@ -149,7 +149,7 @@ OctTree::OctChild::~OctChild()
|
||||
}
|
||||
}
|
||||
|
||||
bool OctTree::OctChild::BoxCollides(const AABB& boxToTest, AABB& outBoxIntersected) const
|
||||
bool Octree::Child::BoxCollides(const AABB& boxToTest, AABB& outBoxIntersected) const
|
||||
{
|
||||
if (hasChildren()) {
|
||||
for (int i : childIndicesContainingBox(boxToTest)) {
|
||||
@@ -182,7 +182,7 @@ bool OctTree::OctChild::BoxCollides(const AABB& boxToTest, AABB& outBoxIntersect
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OctTree::OctChild::RayCollides(const Ray& ray, Output& data) const
|
||||
bool Octree::Child::RayCollides(const Ray& ray, Output& data) const
|
||||
{
|
||||
//If the node AABB is missed, everything it contains is missed.
|
||||
if (Collision::RayAABBIntr(ray, m_Box)) {
|
||||
@@ -234,7 +234,7 @@ bool OctTree::OctChild::RayCollides(const Ray& ray, Output& data) const
|
||||
}
|
||||
|
||||
|
||||
void OctTree::OctChild::AddDynamicObject(const AABB& box)
|
||||
void Octree::Child::AddDynamicObject(const AABB& box)
|
||||
{
|
||||
if (hasChildren()) {
|
||||
for (auto i : childIndicesContainingBox(box)) {
|
||||
@@ -246,7 +246,7 @@ void OctTree::OctChild::AddDynamicObject(const AABB& box)
|
||||
}
|
||||
}
|
||||
|
||||
void OctTree::OctChild::AddStaticObject(const AABB& box)
|
||||
void Octree::Child::AddStaticObject(const AABB& box)
|
||||
{
|
||||
if (hasChildren()) {
|
||||
for (auto i : childIndicesContainingBox(box)) {
|
||||
@@ -258,7 +258,7 @@ void OctTree::OctChild::AddStaticObject(const AABB& box)
|
||||
}
|
||||
}
|
||||
|
||||
void OctTree::OctChild::BoxesInSameRegion(const AABB& box, std::vector<AABB>& outBoxes) const
|
||||
void Octree::Child::BoxesInSameRegion(const AABB& box, std::vector<AABB>& outBoxes) const
|
||||
{
|
||||
if (hasChildren()) {
|
||||
for (auto i : childIndicesContainingBox(box)) {
|
||||
@@ -292,10 +292,10 @@ void OctTree::OctChild::BoxesInSameRegion(const AABB& box, std::vector<AABB>& ou
|
||||
}
|
||||
}
|
||||
|
||||
void OctTree::OctChild::ClearObjects()
|
||||
void Octree::Child::ClearObjects()
|
||||
{
|
||||
if (hasChildren()) {
|
||||
for (OctChild*& c : m_Children) {
|
||||
for (Child*& c : m_Children) {
|
||||
c->ClearObjects();
|
||||
}
|
||||
} else {
|
||||
@@ -304,10 +304,10 @@ void OctTree::OctChild::ClearObjects()
|
||||
}
|
||||
}
|
||||
|
||||
void OctTree::OctChild::ClearDynamicObjects()
|
||||
void Octree::Child::ClearDynamicObjects()
|
||||
{
|
||||
if (hasChildren()) {
|
||||
for (OctChild*& c : m_Children) {
|
||||
for (Child*& c : m_Children) {
|
||||
c->ClearObjects();
|
||||
}
|
||||
} else {
|
||||
@@ -327,13 +327,13 @@ void OctTree::OctChild::ClearDynamicObjects()
|
||||
// x : - - - - + + + +
|
||||
// y : - - + + - - + +
|
||||
// z : - + - + - + - +
|
||||
int OctTree::OctChild::childIndexContainingPoint(const glm::vec3& point) const
|
||||
int Octree::Child::childIndexContainingPoint(const glm::vec3& point) const
|
||||
{
|
||||
const glm::vec3& c = m_Box.Center();
|
||||
return (1 << 2) * (point.x >= c.x) | (1 << 1) * (point.y >= c.y) | (point.z >= c.z);
|
||||
}
|
||||
|
||||
std::vector<int> OctTree::OctChild::childIndicesContainingBox(const AABB& box) const
|
||||
std::vector<int> Octree::Child::childIndicesContainingBox(const AABB& box) const
|
||||
{
|
||||
int minInd = childIndexContainingPoint(box.MinCorner());
|
||||
int maxInd = childIndexContainingPoint(box.MaxCorner());
|
||||
@@ -371,7 +371,7 @@ std::vector<int> OctTree::OctChild::childIndicesContainingBox(const AABB& box) c
|
||||
}
|
||||
}
|
||||
|
||||
inline bool OctTree::OctChild::hasChildren() const
|
||||
inline bool Octree::Child::hasChildren() const
|
||||
{
|
||||
return m_Children[0] != nullptr;
|
||||
}
|
||||
@@ -205,9 +205,9 @@ BOOST_AUTO_TEST_CASE(octTest)
|
||||
{
|
||||
glm::vec3 mini = glm::vec3(-1, -1, -1);
|
||||
glm::vec3 maxi = glm::vec3(1, 1, 1);
|
||||
OctTree tree(AABB(mini, maxi), 2);
|
||||
Octree tree(AABB(mini, maxi), 2);
|
||||
tree.AddDynamicObject(AABB(mini, -0.9f*maxi));
|
||||
OctTree::Output data;
|
||||
Octree::Output data;
|
||||
glm::vec3 origin = 3.0f * mini;
|
||||
bool rayIntersected = tree.RayCollides(Ray(origin , mini - origin), data);
|
||||
BOOST_CHECK(rayIntersected);
|
||||
|
||||
@@ -13,7 +13,7 @@ BOOST_AUTO_TEST_CASE(octSameRegionTest)
|
||||
{
|
||||
glm::vec3 mini = glm::vec3(-1, -1, -1);
|
||||
glm::vec3 maxi = glm::vec3(1, 1, 1);
|
||||
OctTree tree(AABB(mini, maxi), 2);
|
||||
Octree tree(AABB(mini, maxi), 2);
|
||||
AABB firstQuadrant(mini, 0.8f*mini);
|
||||
tree.AddStaticObject(firstQuadrant);
|
||||
AABB testBox(0.9f*mini, 0.8f*mini);
|
||||
@@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(octRegionPerfTestWithDuplicates)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octRegionPerfTestNoDuplicates)
|
||||
{
|
||||
TestLoop<OctTree>(RegionTest<OctTree>);
|
||||
TestLoop<Octree>(RegionTest<Octree>);
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(octBoxPerfTestWithDuplicates)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octBoxPerfTestNoDuplicates)
|
||||
{
|
||||
TestLoop<OctTree>(BoxTest<OctTree>);
|
||||
TestLoop<Octree>(BoxTest<Octree>);
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE(octRayPerfTestWithDuplicates)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octRayPerfTestNoDuplicates)
|
||||
{
|
||||
TestLoop<OctTree>(RayTest<OctTree>);
|
||||
TestLoop<Octree>(RayTest<Octree>);
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE(octNopPerfTestWithDuplicates)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octNopPerfTestNoDuplicates)
|
||||
{
|
||||
TestLoop<OctTree>(NopTest<OctTree>);
|
||||
TestLoop<Octree>(NopTest<Octree>);
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ private:
|
||||
glm::quat m_PrevOri;
|
||||
|
||||
glm::vec3 worldSize = glm::vec3(50, 50, 50);
|
||||
OctTree someOctTree;
|
||||
Octree someOctTree;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ class HardcodedTestWorld : public World
|
||||
public:
|
||||
struct LinkOctTreeAndModel {
|
||||
EntityID entId;
|
||||
OctTree::OctChild* child;
|
||||
Octree::Child* child;
|
||||
glm::vec3 posxyz;
|
||||
LinkOctTreeAndModel(EntityID eId, OctTree::OctChild* ch, glm::vec3 pos)
|
||||
LinkOctTreeAndModel(EntityID eId, Octree::Child* ch, glm::vec3 pos)
|
||||
{
|
||||
entId = eId;
|
||||
child = ch;
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
};
|
||||
EntityID anotherBoxTransformId;
|
||||
std::vector<LinkOctTreeAndModel> linkOM;
|
||||
OctTree someOctTree;
|
||||
Octree someOctTree;
|
||||
|
||||
//constructor
|
||||
HardcodedTestWorld()
|
||||
@@ -115,7 +115,7 @@ private:
|
||||
model["Resource"] = "Models/Core/UnitBox.obj";
|
||||
}
|
||||
|
||||
void AddBoxModel(const glm::vec3 ¢er, const float &halfSize, OctTree::OctChild* child, EntityID &outEntityId) {
|
||||
void AddBoxModel(const glm::vec3 ¢er, const float &halfSize, Octree::Child* child, EntityID &outEntityId) {
|
||||
World& world = *this;
|
||||
|
||||
EntityID entityDummyScene = world.CreateEntity();
|
||||
|
||||
Reference in New Issue
Block a user