diff --git a/Bin/DLL/GamePhysics_x86D.exp b/Bin/DLL/GamePhysics_x86D.exp new file mode 100644 index 00000000..0cea5aa6 Binary files /dev/null and b/Bin/DLL/GamePhysics_x86D.exp differ diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index 64617426..6a6416b8 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -16,6 +16,16 @@ Octree::~Octree() } +Octree& Octree::operator=(const Octree& orig) +{ + this->leafData = orig.leafData; + this->updateQueue = orig.updateQueue; + this->worldNode = orig.worldNode; + this->mapReferences = orig.mapReferences; + + return *this; +} + void Octree::AddObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef) { Data data; @@ -50,7 +60,6 @@ void Octree::MoveToUpdateQueue(Utility::DynamicMemory::UniquePointer< ICustomBod 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); @@ -60,13 +69,22 @@ void Octree::DestroyObject(Utility::DynamicMemory::UniquePointer< ICustomBody > this->leafData.erase(this->leafData.begin() + this->leafData[this->mapReferences[customBodyRef]].queueRef); } -std::vector Octree::Sample(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef) +std::vector Octree::Sample(ICustomBody* customBodyRef) { std::vector list; + auto object = this->mapReferences.find(customBodyRef); + + if(object == this->mapReferences.end()) + { + return list; + } + + unsigned int tempRef = object->second; + for(unsigned int i = 0; ileafData.size(); i++) { - if(this->leafData[i].customBodyRef != customBodyRef) if(this->leafData[i].container.Intersects(customBodyRef->GetBoundingSphere())) + if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container)) { list.push_back(this->leafData[i].customBodyRef); } @@ -74,3 +92,28 @@ std::vector Octree::Sample(Utility::DynamicMemory::UniquePointer< return list; } + +void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) +{ + auto object = this->mapReferences.find(customBodyRef); + + if(object == this->mapReferences.end()) + { + return; + } + + unsigned int tempRef = object->second; + + for(unsigned int i = 0; ileafData.size(); i++) + { + if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container)) + { + hitAction(*this, tempRef, i); + } + } +} + +ICustomBody* Octree::GetCustomBody(const unsigned int tempRef) +{ + return this->leafData[tempRef].customBodyRef; +} \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 6034d129..8d111329 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -15,6 +15,8 @@ namespace Oyster class Octree { public: + typedef void(*VistorAction)(Octree&, unsigned int, unsigned int); + struct Data { Data* prev; @@ -22,7 +24,7 @@ namespace Oyster Collision3D::Sphere container; - Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef; + ::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef; unsigned int queueRef; }; @@ -34,16 +36,22 @@ namespace Oyster Collision3D::BoxAxisAligned container; }; - Octree(unsigned int bufferSize, unsigned char numLayers, Math::Float3 worldSize); + Octree(unsigned int bufferSize = 0, unsigned char numLayers = 0, Math::Float3 worldSize = Math::Float3::null); virtual ~Octree(); - void AddObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); + Octree& operator=(const Octree& orig); - void MoveToUpdateQueue(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); + void AddObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); - void DestroyObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); + void MoveToUpdateQueue(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); + + void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); + + std::vector Sample(ICustomBody* customBodyRef); + void Visit(ICustomBody* customBodyRef, VistorAction hitAction ); + + ICustomBody* GetCustomBody(const unsigned int tempRef); - std::vector Sample(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); private: std::vector < Data > leafData; std::vector < Data* > updateQueue;