Merging octTreeTests a bit
This commit is contained in:
@@ -32,33 +32,17 @@ BOOST_AUTO_TEST_CASE(octTreeTest)
|
|||||||
//simple OctTree constructor check
|
//simple OctTree constructor check
|
||||||
OctTree someOctTree(someAABB, 5);
|
OctTree someOctTree(someAABB, 5);
|
||||||
BOOST_CHECK(someOctTree.m_Children[0] != nullptr);
|
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
|
//simple destructor check in the end, just look for memleaks, then it didnt clear the AABB structure
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(octTreeTest2)
|
BOOST_AUTO_TEST_CASE(octTreeTest2)
|
||||||
{
|
{
|
||||||
|
//octtree ritningen osv
|
||||||
Game game(0, nullptr);
|
Game game(0, nullptr);
|
||||||
while (game.Running()) {
|
while (game.Running()) {
|
||||||
game.Tick();
|
game.Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "OctTreeTestGameClass.h"
|
#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<ConfigFile>("ConfigFile");
|
||||||
ResourceManager::RegisterType<Model>("Model");
|
ResourceManager::RegisterType<Model>("Model");
|
||||||
@@ -57,31 +57,100 @@ void Game::Tick()
|
|||||||
m_Renderer->Update(dt);
|
m_Renderer->Update(dt);
|
||||||
m_EventBroker->Swap();
|
m_EventBroker->Swap();
|
||||||
|
|
||||||
//movement
|
#define TEST2
|
||||||
minPos.x += 0.001f;
|
#ifdef TEST1
|
||||||
//frameCounter++;
|
//add/move the trigger box
|
||||||
//if (frameCounter > 50) {
|
auto pos = m_Renderer->Camera()->Forward() + m_Renderer->Camera()->Position();
|
||||||
// m_World->createTestEntities(AABB(minPos, glm::vec3(0.1f, 0.4f, 0.6f)));
|
AABB boxi;
|
||||||
// frameCounter = 0;
|
boxi.CreateFromCenter(pos, maxPos - minPos);
|
||||||
//}
|
frameCounter++;
|
||||||
//auto transf = m_World->GetComponent(m_World->OctTreeEntityIdSaved, "Transform");
|
if (frameCounter > 50) {
|
||||||
//((glm::vec3&)transf["Position"]).x += 0.001f;
|
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);
|
m_RenderQueueFactory->Update(m_World);
|
||||||
|
|
||||||
//wireframe
|
//wireframe
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
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());
|
m_Renderer->Draw(m_RenderQueueFactory->RenderQueues());
|
||||||
|
|
||||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
||||||
|
|
||||||
|
|
||||||
m_EventBroker->Swap();
|
m_EventBroker->Swap();
|
||||||
m_EventBroker->Clear();
|
m_EventBroker->Clear();
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "Rendering/RenderQueueFactory.h"
|
#include "Rendering/RenderQueueFactory.h"
|
||||||
|
|
||||||
#include "OctTreeTestHardCodedTestWorld.h"
|
#include "OctTreeTestHardCodedTestWorld.h"
|
||||||
|
#include "Core\Collision.h"
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
@@ -31,8 +32,20 @@ private:
|
|||||||
HardcodedTestWorld* m_World;
|
HardcodedTestWorld* m_World;
|
||||||
RenderQueueFactory* m_RenderQueueFactory;
|
RenderQueueFactory* m_RenderQueueFactory;
|
||||||
|
|
||||||
|
//Test1
|
||||||
int frameCounter = 0;
|
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
|
#endif
|
||||||
|
|||||||
@@ -5,9 +5,6 @@
|
|||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
#include "Core/Util/Any.h"
|
#include "Core/Util/Any.h"
|
||||||
|
|
||||||
//octTree
|
|
||||||
//#include <windows.h>
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
//last!
|
//last!
|
||||||
#define private public
|
#define private public
|
||||||
@@ -18,18 +15,26 @@ class HardcodedTestWorld : public World
|
|||||||
public:
|
public:
|
||||||
struct LinkOctTreeAndModel {
|
struct LinkOctTreeAndModel {
|
||||||
EntityID entId;
|
EntityID entId;
|
||||||
|
OctTree* child;
|
||||||
|
glm::vec3 posxyz;
|
||||||
|
LinkOctTreeAndModel(EntityID eId, OctTree* ch, glm::vec3 pos)
|
||||||
|
{
|
||||||
|
entId = eId;
|
||||||
|
child = ch;
|
||||||
|
posxyz = pos;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
EntityID OctTreeEntityIdSaved;
|
EntityID anotherBoxTransformId;
|
||||||
//std::vector<ComponentWrapper> allModels;
|
std::vector<LinkOctTreeAndModel> linkOM;
|
||||||
//ComponentWrapper moveModel;
|
OctTree someOctTree;
|
||||||
//OctTree* someOctTreePointer;
|
|
||||||
|
|
||||||
//constructor
|
//constructor
|
||||||
HardcodedTestWorld()
|
HardcodedTestWorld()
|
||||||
: World()
|
: World()
|
||||||
|
, someOctTree(AABB(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f)), 2)
|
||||||
{
|
{
|
||||||
registerTestComponents();
|
registerTestComponents();
|
||||||
createTestEntities(AABB(glm::vec3(-0.2f, 0.2f, 0.3f), glm::vec3(0.1f, 0.4f, 0.6f)));
|
//createTestEntities();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -61,58 +66,69 @@ private:
|
|||||||
RegisterComponent(f);
|
RegisterComponent(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void createTestEntities(AABB anotherBox)
|
void createTestEntities()
|
||||||
{
|
{
|
||||||
World& world = *this;
|
World& world = *this;
|
||||||
|
EntityID tempId;
|
||||||
//add octTree
|
//add octTree
|
||||||
{
|
{
|
||||||
|
//copy of mainbox
|
||||||
auto someAABB = AABB(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
|
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
|
//draw main box first
|
||||||
//auto anotherBox = AABB(glm::vec3(-0.2f, 0.2f, 0.3f), glm::vec3(0.1f, 0.4f, 0.6f));
|
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
|
//note: have to delete the box in the tree first, since were trying to move the box
|
||||||
someOctTree.ClearDynamicObjects();
|
|
||||||
someOctTree.AddDynamicObject(anotherBox);
|
someOctTree.AddDynamicObject(anotherBox);
|
||||||
|
|
||||||
//the main box first
|
//draw anotherbox and save it in anotherBoxTransformId
|
||||||
AddBoxModel(someAABB.Center(), someAABB.HalfSize().x, someOctTree.m_DynamicObjects.size());
|
AddBoxModel(anotherBox.Center(), anotherBox.HalfSize().x, &someOctTree, anotherBoxTransformId);
|
||||||
|
|
||||||
//draw anotherbox
|
|
||||||
AddBoxModel(anotherBox.Center(), anotherBox.HalfSize().x, 0);
|
|
||||||
|
|
||||||
//draw the octTree
|
//draw the octTree
|
||||||
for (size_t j = 0; j < 8; j++)
|
for (size_t j = 0; j < 8; j++)
|
||||||
{
|
{
|
||||||
AddBoxModel(someOctTree.m_Children[j]->m_Box.Center(),
|
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];
|
auto someChild = someOctTree.m_Children[j];
|
||||||
|
|
||||||
for (size_t i = 0; i < 8; i++)
|
for (size_t i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
AddBoxModel(someChild->m_Children[i]->m_Box.Center(),
|
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
|
}//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;
|
World& world = *this;
|
||||||
|
|
||||||
EntityID entityDummyScene = world.CreateEntity();
|
EntityID entityDummyScene = world.CreateEntity();
|
||||||
|
outEntityId = entityDummyScene;
|
||||||
ComponentWrapper transform = world.AttachComponent(entityDummyScene, "Transform");
|
ComponentWrapper transform = world.AttachComponent(entityDummyScene, "Transform");
|
||||||
transform["Position"] = center;
|
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");
|
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);
|
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);
|
model["Color"] = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
|
linkOM.emplace_back(entityDummyScene, child, center);
|
||||||
//extra
|
//extra
|
||||||
//allModels.push_back(model);
|
//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