Merging octTreeTests a bit
This commit is contained in:
@@ -32,33 +32,17 @@ BOOST_AUTO_TEST_CASE(octTreeTest)
|
||||
//simple OctTree constructor check
|
||||
OctTree someOctTree(someAABB, 5);
|
||||
BOOST_CHECK(someOctTree.m_Children[0] != nullptr);
|
||||
//TODO: a check so it split the tree properly
|
||||
|
||||
|
||||
|
||||
|
||||
//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.AddDynamicObject(someAABB2);
|
||||
//clear the boxcontainer
|
||||
//need to check so it added the box properly
|
||||
|
||||
someOctTree.ClearDynamicObjects();
|
||||
//add a boxcontainer
|
||||
someOctTree.AddDynamicObject(someAABB2);
|
||||
|
||||
|
||||
//simple destructor check in the end, just look for memleaks, then it didnt clear the AABB structure
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octTreeTest2)
|
||||
{
|
||||
//octtree ritningen osv
|
||||
Game game(0, nullptr);
|
||||
while (game.Running()) {
|
||||
game.Tick();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "OctTreeTestGameClass.h"
|
||||
|
||||
Game::Game(int argc, char* argv[])
|
||||
Game::Game(int argc, char* argv[]) : someOctTree(AABB(-0.5f*worldSize, 0.5f*worldSize), 2)
|
||||
{
|
||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||
ResourceManager::RegisterType<Model>("Model");
|
||||
@@ -57,31 +57,100 @@ void Game::Tick()
|
||||
m_Renderer->Update(dt);
|
||||
m_EventBroker->Swap();
|
||||
|
||||
//movement
|
||||
minPos.x += 0.001f;
|
||||
//frameCounter++;
|
||||
//if (frameCounter > 50) {
|
||||
// m_World->createTestEntities(AABB(minPos, glm::vec3(0.1f, 0.4f, 0.6f)));
|
||||
// frameCounter = 0;
|
||||
//}
|
||||
//auto transf = m_World->GetComponent(m_World->OctTreeEntityIdSaved, "Transform");
|
||||
//((glm::vec3&)transf["Position"]).x += 0.001f;
|
||||
#define TEST2
|
||||
#ifdef TEST1
|
||||
//add/move the trigger box
|
||||
auto pos = m_Renderer->Camera()->Forward() + m_Renderer->Camera()->Position();
|
||||
AABB boxi;
|
||||
boxi.CreateFromCenter(pos, maxPos - minPos);
|
||||
frameCounter++;
|
||||
if (frameCounter > 50) {
|
||||
m_World->someOctTree.ClearDynamicObjects();
|
||||
m_World->someOctTree.AddDynamicObject(boxi);
|
||||
frameCounter = 0;
|
||||
}
|
||||
ComponentWrapper transform = m_World->GetComponent(m_World->anotherBoxTransformId, "Transform");
|
||||
transform["Position"] = boxi.Center();
|
||||
|
||||
//for (auto oneModel : m_World->allModels)
|
||||
//{
|
||||
//check all children again in the tree if they have a box in them or not, and colormark them if they do
|
||||
//contentboxarna får man ut - inte childboxarna!
|
||||
std::vector<int> boxIndex;
|
||||
boxIndex = m_World->someOctTree.childIndicesContainingBox(boxi);
|
||||
|
||||
//}
|
||||
for (auto& oneLinkedObject : m_World->linkOM)
|
||||
{
|
||||
ComponentWrapper model = m_World->GetComponent(oneLinkedObject.entId, "Model");
|
||||
model["Color"] = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
if (oneLinkedObject.child->m_DynamicObjects.size() != 0) {
|
||||
model["Color"] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
//next check if the childIndicesContainingBox method returns the correct boxes
|
||||
//REQUIRED: childIndicesContainingBox must be public to test this!
|
||||
for each (auto someBoxIndex in boxIndex)
|
||||
{
|
||||
glm::vec3 pos = m_World->someOctTree.m_Children[someBoxIndex]->m_Box.Center();
|
||||
if (abs(pos.x - oneLinkedObject.posxyz.x) < 0.005f &&
|
||||
abs(pos.y - oneLinkedObject.posxyz.y) < 0.005f &&
|
||||
abs(pos.z - oneLinkedObject.posxyz.z) < 0.005f) {
|
||||
model["Color"] = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
m_RenderQueueFactory->Update(m_World);
|
||||
|
||||
//wireframe
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
#endif
|
||||
#ifdef TEST2
|
||||
|
||||
//only add 1 for now...
|
||||
//grey box
|
||||
AABB aabb;
|
||||
aabb.CreateFromCenter(glm::vec3(0.f, 2.f, 0.f), glm::vec3(1.f, 1.f, 1.f));
|
||||
|
||||
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::vec3 boxSize = 0.1f*glm::vec3(1.0f, 1.0f, 1.0f);
|
||||
|
||||
if (!m_UpdatedOnce) {
|
||||
someOctTree.AddStaticObject(aabb);
|
||||
m_BoxID = m_World->CreateEntity();
|
||||
ComponentWrapper transform = m_World->AttachComponent(m_BoxID, "Transform");
|
||||
transform["Scale"] = boxSize;
|
||||
ComponentWrapper model = m_World->AttachComponent(m_BoxID, "Model");
|
||||
model["Resource"] = "Models/Core/UnitBox.obj";
|
||||
m_UpdatedOnce = true;
|
||||
m_World->createTestEntitiesTest2();
|
||||
}
|
||||
|
||||
//red box
|
||||
AABB redBox;
|
||||
auto boxPos = m_Renderer->Camera()->Position() + 1.2f*m_Renderer->Camera()->Forward();
|
||||
redBox.CreateFromCenter(boxPos, boxSize);
|
||||
ComponentWrapper transform = m_World->GetComponent(m_BoxID, "Transform");
|
||||
transform["Position"] = boxPos;
|
||||
ComponentWrapper model = m_World->GetComponent(m_BoxID, "Model");
|
||||
if (someOctTree.BoxCollides(redBox, AABB())) {
|
||||
//if (Collision::AABBVsAABB(redBox, aabb)) {
|
||||
m_Renderer->Camera()->SetPosition(m_PrevPos);
|
||||
m_Renderer->Camera()->SetOrientation(m_PrevOri);
|
||||
model["Color"] = greenCol;
|
||||
}
|
||||
else {
|
||||
model["Color"] = redCol;
|
||||
}
|
||||
|
||||
m_PrevPos = m_Renderer->Camera()->Position();
|
||||
m_PrevOri = m_Renderer->Camera()->Orientation();
|
||||
someOctTree.ClearObjects();
|
||||
|
||||
m_RenderQueueFactory->Update(m_World);
|
||||
#endif
|
||||
|
||||
m_Renderer->Draw(m_RenderQueueFactory->RenderQueues());
|
||||
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
|
||||
m_EventBroker->Swap();
|
||||
m_EventBroker->Clear();
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "Rendering/RenderQueueFactory.h"
|
||||
|
||||
#include "OctTreeTestHardCodedTestWorld.h"
|
||||
#include "Core\Collision.h"
|
||||
|
||||
class Game
|
||||
{
|
||||
@@ -31,8 +32,20 @@ private:
|
||||
HardcodedTestWorld* m_World;
|
||||
RenderQueueFactory* m_RenderQueueFactory;
|
||||
|
||||
//Test1
|
||||
int frameCounter = 0;
|
||||
glm::vec3 minPos = glm::vec3(-0.2f, 0.2f, 0.3f);
|
||||
glm::vec3 minPos = glm::vec3(0.1f, 0.1f, 0.1f);
|
||||
glm::vec3 maxPos = glm::vec3(0.2f, 0.2f, 0.2f);
|
||||
|
||||
//Test2
|
||||
bool m_UpdatedOnce = false;
|
||||
unsigned int m_BoxID;
|
||||
glm::vec3 m_PrevPos;
|
||||
glm::quat m_PrevOri;
|
||||
|
||||
glm::vec3 worldSize = glm::vec3(50, 50, 50);
|
||||
OctTree someOctTree;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
#include "Core/World.h"
|
||||
#include "Core/Util/Any.h"
|
||||
|
||||
//octTree
|
||||
//#include <windows.h>
|
||||
|
||||
#include <vector>
|
||||
//last!
|
||||
#define private public
|
||||
@@ -18,18 +15,26 @@ class HardcodedTestWorld : public World
|
||||
public:
|
||||
struct LinkOctTreeAndModel {
|
||||
EntityID entId;
|
||||
OctTree* child;
|
||||
glm::vec3 posxyz;
|
||||
LinkOctTreeAndModel(EntityID eId, OctTree* ch, glm::vec3 pos)
|
||||
{
|
||||
entId = eId;
|
||||
child = ch;
|
||||
posxyz = pos;
|
||||
}
|
||||
};
|
||||
EntityID OctTreeEntityIdSaved;
|
||||
//std::vector<ComponentWrapper> allModels;
|
||||
//ComponentWrapper moveModel;
|
||||
//OctTree* someOctTreePointer;
|
||||
EntityID anotherBoxTransformId;
|
||||
std::vector<LinkOctTreeAndModel> linkOM;
|
||||
OctTree someOctTree;
|
||||
|
||||
//constructor
|
||||
HardcodedTestWorld()
|
||||
: World()
|
||||
, someOctTree(AABB(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f)), 2)
|
||||
{
|
||||
registerTestComponents();
|
||||
createTestEntities(AABB(glm::vec3(-0.2f, 0.2f, 0.3f), glm::vec3(0.1f, 0.4f, 0.6f)));
|
||||
//createTestEntities();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -61,58 +66,69 @@ private:
|
||||
RegisterComponent(f);
|
||||
}
|
||||
|
||||
void createTestEntities(AABB anotherBox)
|
||||
void createTestEntities()
|
||||
{
|
||||
World& world = *this;
|
||||
|
||||
EntityID tempId;
|
||||
//add octTree
|
||||
{
|
||||
//copy of mainbox
|
||||
auto someAABB = AABB(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
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));
|
||||
|
||||
//draw main box first
|
||||
AddBoxModel(someAABB.Center(), someAABB.HalfSize().x, &someOctTree, tempId);
|
||||
|
||||
//add anotherbox in octTree
|
||||
auto anotherBox = AABB(glm::vec3(0.1f, 0.1f, 0.1f), glm::vec3(0.2f, 0.2f, 0.2f));
|
||||
//note: have to delete the box in the tree first, since were trying to move the box
|
||||
someOctTree.ClearDynamicObjects();
|
||||
someOctTree.AddDynamicObject(anotherBox);
|
||||
|
||||
//the main box first
|
||||
AddBoxModel(someAABB.Center(), someAABB.HalfSize().x, someOctTree.m_DynamicObjects.size());
|
||||
|
||||
//draw anotherbox
|
||||
AddBoxModel(anotherBox.Center(), anotherBox.HalfSize().x, 0);
|
||||
//draw anotherbox and save it in anotherBoxTransformId
|
||||
AddBoxModel(anotherBox.Center(), anotherBox.HalfSize().x, &someOctTree, anotherBoxTransformId);
|
||||
|
||||
//draw the octTree
|
||||
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_DynamicObjects.size());
|
||||
someOctTree.m_Children[j]->m_Box.HalfSize().x, someOctTree.m_Children[j], tempId);
|
||||
|
||||
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_DynamicObjects.size());
|
||||
someChild->m_Children[i]->m_Box.HalfSize().x, someChild->m_Children[i], tempId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end CreateEnt
|
||||
|
||||
void AddBoxModel(const glm::vec3 ¢er, const float &halfSize, const int &contBoxes) {
|
||||
void AddBoxModel(const glm::vec3 ¢er, const float &halfSize, OctTree* child, EntityID &outEntityId) {
|
||||
World& world = *this;
|
||||
|
||||
EntityID entityDummyScene = world.CreateEntity();
|
||||
|
||||
outEntityId = entityDummyScene;
|
||||
ComponentWrapper transform = world.AttachComponent(entityDummyScene, "Transform");
|
||||
transform["Position"] = center;
|
||||
transform["Scale"] = glm::vec3(1.0f, 1.0f, 1.0f)*halfSize*2.0f;
|
||||
transform["Scale"] = glm::vec3(1.0f, 1.0f, 1.0f)*halfSize*2.0f*0.97f;
|
||||
ComponentWrapper model = world.AttachComponent(entityDummyScene, "Model");
|
||||
model["Resource"] = "Models/Core/UnitBox2.obj";
|
||||
model["Resource"] = "Models/Core/UnitBox.obj";
|
||||
model["Color"] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
if (contBoxes != 0)
|
||||
if (child->m_DynamicObjects.size() != 0)
|
||||
model["Color"] = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
linkOM.emplace_back(entityDummyScene, child, center);
|
||||
//extra
|
||||
//allModels.push_back(model);
|
||||
}
|
||||
void createTestEntitiesTest2()
|
||||
{
|
||||
World& world = *this;
|
||||
|
||||
EntityID entityCollisionBox = world.CreateEntity();
|
||||
ComponentWrapper transform = world.AttachComponent(entityCollisionBox, "Transform");
|
||||
transform["Position"] = glm::vec3(0.f, 2.f, 0.f);
|
||||
ComponentWrapper model = world.AttachComponent(entityCollisionBox, "Model");
|
||||
model["Resource"] = "Models/Core/UnitBox.obj";
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user