Renamed all OctTree to Octree (More OCD)
This commit is contained in:
+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