From ecbb606544f735a95daf37e88b7915baf7906dcf Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Thu, 28 Nov 2013 11:14:24 +0100 Subject: [PATCH] Added basic functionality for container. --- Code/GamePhysics/GamePhysics.vcxproj | 1 + Code/GamePhysics/GamePhysics.vcxproj.filters | 6 ++ Code/GamePhysics/Implementation/Octree.cpp | 76 ++++++++++++++++++++ Code/GamePhysics/Implementation/Octree.h | 10 +-- 4 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 Code/GamePhysics/Implementation/Octree.cpp diff --git a/Code/GamePhysics/GamePhysics.vcxproj b/Code/GamePhysics/GamePhysics.vcxproj index ddc37cf4..562fecb4 100644 --- a/Code/GamePhysics/GamePhysics.vcxproj +++ b/Code/GamePhysics/GamePhysics.vcxproj @@ -155,6 +155,7 @@ + diff --git a/Code/GamePhysics/GamePhysics.vcxproj.filters b/Code/GamePhysics/GamePhysics.vcxproj.filters index 256cd6b1..b971ed32 100644 --- a/Code/GamePhysics/GamePhysics.vcxproj.filters +++ b/Code/GamePhysics/GamePhysics.vcxproj.filters @@ -30,6 +30,9 @@ Header Files\Implementation + + Header Files\Implementation + @@ -41,5 +44,8 @@ Source Files + + Header Files\Implementation + \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp new file mode 100644 index 00000000..64617426 --- /dev/null +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -0,0 +1,76 @@ +#include "Octree.h" + +using namespace Oyster; +using namespace Physics; + +Octree::Octree(unsigned int bufferSize, unsigned char numLayers, Math::Float3 worldSize) +{ + this->worldNode.dataPtr = NULL; + + this->worldNode.container.maxVertex = worldSize*0.5f; + this->worldNode.container.minVertex = -worldSize*0.5f; +} + +Octree::~Octree() +{ + +} + +void Octree::AddObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef) +{ + Data data; + //Data* tempPtr = this->worldNode.dataPtr; + + data.container = customBodyRef->GetBoundingSphere(); + data.queueRef = -1; + data.next = NULL; + data.prev = NULL; + data.customBodyRef = customBodyRef; + this->mapReferences.insert(std::pair (customBodyRef, this->leafData.size())); + this->leafData.push_back(data); + + /*if(tempPtr != NULL) + { + tempPtr->prev->next = &this->leafData[this->leafData.size() - 1]; + this->leafData[this->leafData.size() - 1].prev = tempPtr->prev; + tempPtr->prev = &this->leafData[this->leafData.size() - 1]; + this->leafData[this->leafData.size() - 1].next = tempPtr; + } + else + { + this->worldNode.dataPtr = &this->leafData[this->leafData.size() - 1]; + this->worldNode.dataPtr->next = this->worldNode.dataPtr; + this->worldNode.dataPtr->prev = this->worldNode.dataPtr; + }*/ +} + +void Octree::MoveToUpdateQueue(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef) +{ + /*this->leafData[this->mapReferences[customBodyRef]].queueRef = this->updateQueue.size(); + this->updateQueue.push_back(&this->leafData[this->mapReferences[customBodyRef]]);*/ +} + + +void Octree::DestroyObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef) +{ + std::map::iterator it = this->mapReferences.find(customBodyRef); + + this->mapReferences.erase(it); + + this->leafData.erase(this->leafData.begin() + this->leafData[this->mapReferences[customBodyRef]].queueRef); +} + +std::vector Octree::Sample(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef) +{ + std::vector list; + + for(unsigned int i = 0; ileafData.size(); i++) + { + if(this->leafData[i].customBodyRef != customBodyRef) if(this->leafData[i].container.Intersects(customBodyRef->GetBoundingSphere())) + { + list.push_back(this->leafData[i].customBodyRef); + } + } + + return list; +} diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 22385dc6..6034d129 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -29,7 +29,9 @@ namespace Oyster struct OctreeNode { - + OctreeNode* children[8]; + Data* dataPtr; + Collision3D::BoxAxisAligned container; }; Octree(unsigned int bufferSize, unsigned char numLayers, Math::Float3 worldSize); @@ -39,16 +41,16 @@ namespace Oyster void MoveToUpdateQueue(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); - void Update(); - void DestroyObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); - void Sample(Collision3D::ICollideable& collideable); + std::vector Sample(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); private: std::vector < Data > leafData; + std::vector < Data* > updateQueue; std::map< ICustomBody*, unsigned int > mapReferences; + OctreeNode worldNode; }; }