Added overloads for visitor and sample functions

They now have an overload for accepting ICollideable
This commit is contained in:
Robin Engman 2013-11-29 09:03:37 +01:00
parent 14b1f20b87
commit 255a0b0070
2 changed files with 31 additions and 7 deletions

View File

@ -72,15 +72,13 @@ void Octree::DestroyObject(UniquePointer< ICustomBody > customBodyRef)
this->leafData.erase(this->leafData.begin() + this->leafData[this->mapReferences[customBodyRef]].queueRef); this->leafData.erase(this->leafData.begin() + this->leafData[this->mapReferences[customBodyRef]].queueRef);
} }
std::vector<ICustomBody*> Octree::Sample(ICustomBody* customBodyRef) std::vector<ICustomBody*>& Octree::Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList)
{ {
std::vector<ICustomBody*> list;
auto object = this->mapReferences.find(customBodyRef); auto object = this->mapReferences.find(customBodyRef);
if(object == this->mapReferences.end()) if(object == this->mapReferences.end())
{ {
return list; return updateList;
} }
unsigned int tempRef = object->second; unsigned int tempRef = object->second;
@ -89,11 +87,24 @@ std::vector<ICustomBody*> Octree::Sample(ICustomBody* customBodyRef)
{ {
if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container)) if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container))
{ {
list.push_back(this->leafData[i].customBodyRef); updateList.push_back(this->leafData[i].customBodyRef);
} }
} }
return list; return updateList;
}
std::vector<ICustomBody*>& Octree::Sample(::Collision3D::ICollideable* collideable, std::vector<ICustomBody*>& updateList)
{
for(unsigned int i = 0; i<this->leafData.size(); i++)
{
if(this->leafData[i].container.Intersects(*collideable))
{
updateList.push_back(this->leafData[i].customBodyRef);
}
}
return updateList;
} }
void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction )
@ -116,6 +127,17 @@ void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction )
} }
} }
void Octree::Visit(::Collision3D::ICollideable* collideable, VistorAction hitAction)
{
for(unsigned int i = 0; i<this->leafData.size(); i++)
{
if(this->leafData[i].container.Intersects(*collideable))
{
//hitAction(*this, tempRef, i); // @todo TODO: Add typedef to handle function calls with ICollideable
}
}
}
ICustomBody* Octree::GetCustomBody(const unsigned int tempRef) ICustomBody* Octree::GetCustomBody(const unsigned int tempRef)
{ {
return this->leafData[tempRef].customBodyRef; return this->leafData[tempRef].customBodyRef;

View File

@ -49,8 +49,10 @@ namespace Oyster
void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
std::vector<ICustomBody*> Sample(ICustomBody* customBodyRef); std::vector<ICustomBody*>& Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList);
std::vector<ICustomBody*>& Sample(Oyster::Collision3D::ICollideable* collideable, std::vector<ICustomBody*>& updateList);
void Visit(ICustomBody* customBodyRef, VistorAction hitAction ); void Visit(ICustomBody* customBodyRef, VistorAction hitAction );
void Visit(Oyster::Collision3D::ICollideable* collideable, VistorAction hitAction );
ICustomBody* GetCustomBody(const unsigned int tempRef); ICustomBody* GetCustomBody(const unsigned int tempRef);