Further work in testing OctTree

This commit is contained in:
verysecrethero
2015-12-09 13:29:15 +01:00
parent 1d0810db10
commit ed5cd392ab
4 changed files with 60 additions and 123 deletions
+11
View File
@@ -58,9 +58,20 @@ void Game::Tick()
m_EventBroker->Swap(); m_EventBroker->Swap();
//movement //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"); //auto transf = m_World->GetComponent(m_World->OctTreeEntityIdSaved, "Transform");
//((glm::vec3&)transf["Position"]).x += 0.001f; //((glm::vec3&)transf["Position"]).x += 0.001f;
//for (auto oneModel : m_World->allModels)
//{
//}
m_RenderQueueFactory->Update(m_World); m_RenderQueueFactory->Update(m_World);
//wireframe //wireframe
+3
View File
@@ -30,6 +30,9 @@ private:
GUI::Frame* m_FrameStack; GUI::Frame* m_FrameStack;
HardcodedTestWorld* m_World; HardcodedTestWorld* m_World;
RenderQueueFactory* m_RenderQueueFactory; RenderQueueFactory* m_RenderQueueFactory;
int frameCounter = 0;
glm::vec3 minPos = glm::vec3(-0.2f, 0.2f, 0.3f);
}; };
#endif #endif
+3 -3
View File
@@ -16,9 +16,9 @@ using boost::unit_test_framework::test_case;
//#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) //#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
//#define new DEBUG_CLIENTBLOCK //#define new DEBUG_CLIENTBLOCK
BOOST_AUTO_TEST_SUITE(collisionTests) BOOST_AUTO_TEST_SUITE(cTest)
BOOST_AUTO_TEST_CASE(collisionTest) BOOST_AUTO_TEST_CASE(cTest)
{ {
//memleak //memleak
int* globalLeak = new int[5]; int* globalLeak = new int[5];
@@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(collisionTest)
//_CrtDumpMemoryLeaks(); //_CrtDumpMemoryLeaks();
} }
BOOST_AUTO_TEST_CASE(collisionTest2) BOOST_AUTO_TEST_CASE(cTest2)
{ {
//fixed seed //fixed seed
srand(2); srand(2);
+42 -119
View File
@@ -8,6 +8,7 @@
//octTree //octTree
//#include <windows.h> //#include <windows.h>
#include <vector>
//last! //last!
#define private public #define private public
#include <Engine\Core\OctTree.h> #include <Engine\Core\OctTree.h>
@@ -15,14 +16,20 @@
class HardcodedTestWorld : public World class HardcodedTestWorld : public World
{ {
public: public:
struct LinkOctTreeAndModel {
EntityID entId;
};
EntityID OctTreeEntityIdSaved; EntityID OctTreeEntityIdSaved;
//std::vector<ComponentWrapper> allModels;
//ComponentWrapper moveModel;
//OctTree* someOctTreePointer;
//constructor //constructor
HardcodedTestWorld() HardcodedTestWorld()
: World() : World()
{ {
registerTestComponents(); registerTestComponents();
createTestEntities(); //createTestEntities();
} }
private: private:
@@ -54,142 +61,58 @@ private:
RegisterComponent(f); RegisterComponent(f);
} }
void createTestEntities() void createTestEntities(AABB anotherBox)
{ {
World& world = *this; World& world = *this;
// Create an entity
EntityID e = world.CreateEntity();
// Attach a Debug component
ComponentWrapper debug = world.AttachComponent(e, "Debug");
// Set the Name field of the Debug component using subscript operator
debug["Name"] = "Carlito";
// Attach a Transform component
world.AttachComponent(e, "Transform");
// Fetch the component based on EntityID and component type
ComponentWrapper transform = world.GetComponent(e, "Transform");
// Set the fields of the Transform component
transform["Position"] = glm::vec3(0.f, 0.f, 0.f);
transform["Scale"] = glm::vec3(1.f, 1.f, 1.f);
// Move on the X axis by fetching field as reference
((glm::vec3&)transform["Position"]).x += 10.f;
// Shrink by a factor of 100
((glm::vec3&)transform["Scale"]) /= 100.f;
// Loop through all Transform components and print them
for (auto& transform : world.GetComponents("Transform")) {
glm::vec3 pos = transform["Position"];
std::cout << "Position: " << pos.x << " " << pos.y << " " << pos.z << std::endl;
glm::vec3 scale = transform["Scale"];
std::cout << "Scale: " << scale.x << " " << scale.y << " " << scale.z << std::endl;
// Fetch the Debug component also present in this entity
ComponentWrapper debug = world.GetComponent(transform.EntityID, "Debug");
std::cout << "Name: " << (std::string)debug["Name"] << std::endl;
}
//Create some test widgets
//{
// EntityID entityScaleWidget = world.CreateEntity();
// ComponentWrapper transform = world.AttachComponent(entityScaleWidget, "Transform");
// transform["Position"] = glm::vec3(-1.5f, 0.f, 0.f);
// ComponentWrapper model = world.AttachComponent(entityScaleWidget, "Model");
// model["Resource"] = "Models/ScaleWidget.obj";
//}
//{
// EntityID entityRotationWidget = world.CreateEntity();
// ComponentWrapper transform = world.AttachComponent(entityRotationWidget, "Transform");
// transform["Position"] = glm::vec3(1.5f, 0.f, 0.f);
// ComponentWrapper model = world.AttachComponent(entityRotationWidget, "Model");
// model["Resource"] = "Models/RotationWidget.obj";
//}
//{
// EntityID entityDummyScene = world.CreateEntity();
// ComponentWrapper transform = world.AttachComponent(entityDummyScene, "Transform");
// transform["Position"] = glm::vec3(0, 0.f, 0.f);
// ComponentWrapper model = world.AttachComponent(entityDummyScene, "Model");
// model["Resource"] = "Models/DummyScene.obj";
//}
//add octTree //add octTree
{ {
//ComponentWrapper debug = world.AttachComponent(e, "Debug"); auto someAABB = AABB(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
//// Set the Name field of the Debug component using subscript operator OctTree someOctTree = OctTree(someAABB, 2);
//debug["Name"] = "Blah"; //add a box
auto minCorner = glm::vec3(0.0f, 0.0f, 0.0f); //auto anotherBox = AABB(glm::vec3(-0.2f, 0.2f, 0.3f), glm::vec3(0.1f, 0.4f, 0.6f));
auto maxCorner = glm::vec3(1.0f, 1.0f, 1.0f); //note: have to delete the box in the tree first, since were trying to move the box
auto someAABB = AABB(minCorner, maxCorner); someOctTree.ClearBoxes();
someOctTree.AddBox(anotherBox);
auto someOctTree = OctTree(someAABB, 2); //the main box first
AddBoxModel(someAABB.Center(), someAABB.HalfSize().x, someOctTree.m_ContainingBoxes.size());
//auto min1 = someOctTree.m_Children[i]->m_Box.MinCorner(); //draw anotherbox
//auto max1 = someOctTree.m_Children[i]->m_Box.MaxCorner(); AddBoxModel(anotherBox.Center(), anotherBox.HalfSize().x, 0);
float boxDrawFactor = 1.00f; //draw the octTree
auto halfSizeFactor = 0.0f;
halfSizeFactor = someAABB.HalfSize().x;
//the first box first
EntityID entityDummyScene = world.CreateEntity();
ComponentWrapper transform = world.AttachComponent(entityDummyScene, "Transform");
transform["Position"] = someAABB.Center()*1.0f;
transform["Scale"] = glm::vec3(1.0f, 1.0f, 1.0f)*halfSizeFactor*boxDrawFactor*2.0f;
ComponentWrapper model = world.AttachComponent(entityDummyScene, "Model");
model["Resource"] = "Models/Core/UnitBox2.obj";
model["Color"] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
//just draw the first 8 children - looks nicer in code if i split it this way
for (size_t i = 0; i < 8; i++)
{
auto cen1 = someOctTree.m_Children[i]->m_Box.Center();
halfSizeFactor = someOctTree.m_Children[i]->m_Box.HalfSize().x;
EntityID entityDummyScene = world.CreateEntity();
ComponentWrapper transform = world.AttachComponent(entityDummyScene, "Transform");
transform["Position"] = cen1*1.0f;
transform["Scale"] = glm::vec3(1.0f, 1.0f, 1.0f)*halfSizeFactor*boxDrawFactor*2.0f;
ComponentWrapper model = world.AttachComponent(entityDummyScene, "Model");
model["Resource"] = "Models/Core/UnitBox2.obj";
model["Color"] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
//OutputDebugStringA((std::to_string(cen1.x) + std::to_string(cen1.y) + std::to_string(cen1.z)).c_str());
//OctTreeEntityIdSaved = entityDummyScene;
}
//then draw the childrens children
for (size_t j = 0; j < 8; j++) 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());
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++)
{ {
auto cen1 = someChild->m_Children[i]->m_Box.Center(); AddBoxModel(someChild->m_Children[i]->m_Box.Center(),
halfSizeFactor = someChild->m_Children[i]->m_Box.HalfSize().x; someChild->m_Children[i]->m_Box.HalfSize().x, someChild->m_Children[i]->m_ContainingBoxes.size());
EntityID entityDummyScene = world.CreateEntity();
ComponentWrapper transform = world.AttachComponent(entityDummyScene, "Transform");
transform["Position"] = cen1*1.0f;
transform["Scale"] = glm::vec3(1.0f, 1.0f, 1.0f)*halfSizeFactor*boxDrawFactor*2.0f;
ComponentWrapper model = world.AttachComponent(entityDummyScene, "Model");
model["Resource"] = "Models/Core/UnitBox2.obj";
model["Color"] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
//OctTreeEntityIdSaved = entityDummyScene;
} }
} }
} }
}//end CreateEnt
void AddBoxModel(const glm::vec3 &center, const float &halfSize, const int &contBoxes) {
World& world = *this;
EntityID entityDummyScene = world.CreateEntity();
ComponentWrapper transform = world.AttachComponent(entityDummyScene, "Transform");
transform["Position"] = center;
transform["Scale"] = glm::vec3(1.0f, 1.0f, 1.0f)*halfSize*2.0f;
ComponentWrapper model = world.AttachComponent(entityDummyScene, "Model");
model["Resource"] = "Models/Core/UnitBox2.obj";
model["Color"] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
if (contBoxes != 0)
model["Color"] = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
//extra
//allModels.push_back(model);
} }
}; };