Little more work with OctTreeTest

This commit is contained in:
verysecrethero
2015-12-09 13:56:59 +01:00
parent 519178dfba
commit 8949db5456
3 changed files with 11 additions and 95 deletions
+4 -5
View File
@@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(octTreeTest)
BOOST_CHECK(someAABB.Center() == 0.5f * (minCorner + maxCorner));
//simple OctTree constructor check
auto someOctTree = OctTree(someAABB, 5);
OctTree someOctTree(someAABB, 5);
BOOST_CHECK(someOctTree.m_Children[0] != nullptr);
//TODO: a check so it split the tree properly
@@ -40,14 +40,13 @@ BOOST_AUTO_TEST_CASE(octTreeTest)
//advanced AddBox check
//add a boxcontainer - which crosses the mid-split
auto someAABB2 = AABB(glm::vec3(0.45f, 0.45f, 0.45f), glm::vec3(0.55f, 0.55f, 0.55f));
someOctTree.AddBox(someAABB2);
someOctTree.AddDynamicObject(someAABB2);
//clear the boxcontainer
//need to check so it added the box properly
someOctTree.ClearBoxes();
someOctTree.ClearDynamicObjects();
//add a boxcontainer
someOctTree.AddBox(someAABB2);
someOctTree.AddDynamicObject(someAABB2);
//simple destructor check in the end, just look for memleaks, then it didnt clear the AABB structure
-83
View File
@@ -17,88 +17,5 @@ using boost::unit_test_framework::test_case;
//#define new DEBUG_CLIENTBLOCK
BOOST_AUTO_TEST_SUITE(cTest)
BOOST_AUTO_TEST_CASE(cTest)
{
//memleak
int* globalLeak = new int[5];
//fixed seed
srand(2);
Ray ray;
AABB someAABB;
glm::vec3 minPos;
glm::vec3 maxPos;
bool z;
int test = 0;
for (size_t i = 0; i < 10; i++)
{
ray.Origin.x = rand() % 100;
ray.Origin.y = rand() % 100;
ray.Origin.z = rand() % 100;
ray.Direction.x = rand() % 100;
ray.Direction.y = rand() % 100;
ray.Direction.z = rand() % 100;
minPos.x = rand() % 100;
minPos.y = rand() % 100;
minPos.z = rand() % 100;
maxPos.x = rand() % 100;
maxPos.y = rand() % 100;
maxPos.z = rand() % 100;
someAABB = AABB(minPos, maxPos);
z = Collision::RayVsAABB(ray, someAABB);
if (z) ++test;
}
BOOST_CHECK(test >= 0);
//_CrtDumpMemoryLeaks();
}
BOOST_AUTO_TEST_CASE(cTest2)
{
//fixed seed
srand(2);
Ray ray;
AABB someAABB;
glm::vec3 minPos;
glm::vec3 maxPos;
bool z;
int test = 0;
for (size_t i = 0; i < 1000000; i++)
{
ray.Origin.x = rand() % 100;
ray.Origin.y = rand() % 100;
ray.Origin.z = rand() % 100;
ray.Direction.x = rand() % 100;
ray.Direction.y = rand() % 100;
ray.Direction.z = rand() % 100;
minPos.x = rand() % 100;
minPos.y = rand() % 100;
minPos.z = rand() % 100;
maxPos.x = rand() % 100;
maxPos.y = rand() % 100;
maxPos.z = rand() % 100;
someAABB = AABB(minPos, maxPos);
z = Collision::RayAABBIntr(ray, someAABB);
if (z) ++test;
}
BOOST_CHECK(test >= 0);
}
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);
tree.AddBox(AABB(mini, -0.9f*maxi));
OctTree::Output data;
glm::vec3 origin = 3.0f * mini;
BOOST_CHECK(tree.RayCollides({origin , glm::normalize(mini - origin) }, data));
tree.ClearBoxes();
BOOST_CHECK(!tree.RayCollides({ origin , glm::normalize(mini - origin) }, data));
}
BOOST_AUTO_TEST_SUITE_END()
+7 -7
View File
@@ -29,7 +29,7 @@ public:
: World()
{
registerTestComponents();
//createTestEntities();
createTestEntities(AABB(glm::vec3(-0.2f, 0.2f, 0.3f), glm::vec3(0.1f, 0.4f, 0.6f)));
}
private:
@@ -68,15 +68,15 @@ private:
//add octTree
{
auto someAABB = AABB(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
OctTree someOctTree = OctTree(someAABB, 2);
OctTree someOctTree(someAABB, 2);
//add a box
//auto anotherBox = AABB(glm::vec3(-0.2f, 0.2f, 0.3f), glm::vec3(0.1f, 0.4f, 0.6f));
//note: have to delete the box in the tree first, since were trying to move the box
someOctTree.ClearBoxes();
someOctTree.AddBox(anotherBox);
someOctTree.ClearDynamicObjects();
someOctTree.AddDynamicObject(anotherBox);
//the main box first
AddBoxModel(someAABB.Center(), someAABB.HalfSize().x, someOctTree.m_ContainingBoxes.size());
AddBoxModel(someAABB.Center(), someAABB.HalfSize().x, someOctTree.m_DynamicObjects.size());
//draw anotherbox
AddBoxModel(anotherBox.Center(), anotherBox.HalfSize().x, 0);
@@ -85,14 +85,14 @@ private:
for (size_t j = 0; j < 8; j++)
{
AddBoxModel(someOctTree.m_Children[j]->m_Box.Center(),
someOctTree.m_Children[j]->m_Box.HalfSize().x, someOctTree.m_Children[j]->m_ContainingBoxes.size());
someOctTree.m_Children[j]->m_Box.HalfSize().x, someOctTree.m_Children[j]->m_DynamicObjects.size());
auto someChild = someOctTree.m_Children[j];
for (size_t i = 0; i < 8; i++)
{
AddBoxModel(someChild->m_Children[i]->m_Box.Center(),
someChild->m_Children[i]->m_Box.HalfSize().x, someChild->m_Children[i]->m_ContainingBoxes.size());
someChild->m_Children[i]->m_Box.HalfSize().x, someChild->m_Children[i]->m_DynamicObjects.size());
}
}
}