Added basic functionality for container.
This commit is contained in:
parent
2890c2a9ea
commit
ecbb606544
|
@ -155,6 +155,7 @@
|
|||
<ClInclude Include="PhysicsAPI.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Implementation\Octree.cpp" />
|
||||
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp" />
|
||||
<ClCompile Include="Implementation\SimpleRigidBody.cpp" />
|
||||
<ClCompile Include="DLLMain.cpp" />
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
<ClInclude Include="Implementation\SimpleRigidBody.h">
|
||||
<Filter>Header Files\Implementation</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Implementation\Octree.h">
|
||||
<Filter>Header Files\Implementation</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp">
|
||||
|
@ -41,5 +44,8 @@
|
|||
<ClCompile Include="DLLMain.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Implementation\Octree.cpp">
|
||||
<Filter>Header Files\Implementation</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -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 <ICustomBody*, unsigned int> (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<ICustomBody*, unsigned int>::iterator it = this->mapReferences.find(customBodyRef);
|
||||
|
||||
this->mapReferences.erase(it);
|
||||
|
||||
this->leafData.erase(this->leafData.begin() + this->leafData[this->mapReferences[customBodyRef]].queueRef);
|
||||
}
|
||||
|
||||
std::vector<ICustomBody*> Octree::Sample(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef)
|
||||
{
|
||||
std::vector<ICustomBody*> list;
|
||||
|
||||
for(unsigned int i = 0; i<this->leafData.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;
|
||||
}
|
|
@ -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<ICustomBody*> Sample(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
||||
private:
|
||||
std::vector < Data > leafData;
|
||||
std::vector < Data* > updateQueue;
|
||||
|
||||
std::map< ICustomBody*, unsigned int > mapReferences;
|
||||
|
||||
OctreeNode worldNode;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue