2013-11-26 10:21:20 +01:00
|
|
|
#ifndef OCTREE_H
|
|
|
|
#define OCTREE_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include "Sphere.h"
|
|
|
|
#include "BoxAxisAligned.h"
|
|
|
|
#include "Utilities.h"
|
|
|
|
#include "../PhysicsAPI.h"
|
|
|
|
|
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Physics
|
|
|
|
{
|
|
|
|
class Octree
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Data
|
|
|
|
{
|
|
|
|
Data* prev;
|
|
|
|
Data* next;
|
|
|
|
|
|
|
|
Collision3D::Sphere container;
|
|
|
|
|
|
|
|
Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef;
|
|
|
|
|
|
|
|
unsigned int queueRef;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OctreeNode
|
|
|
|
{
|
2013-11-28 11:14:24 +01:00
|
|
|
OctreeNode* children[8];
|
|
|
|
Data* dataPtr;
|
|
|
|
Collision3D::BoxAxisAligned container;
|
2013-11-26 10:21:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Octree(unsigned int bufferSize, unsigned char numLayers, Math::Float3 worldSize);
|
|
|
|
virtual ~Octree();
|
|
|
|
|
|
|
|
void AddObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
|
|
|
|
|
|
|
void MoveToUpdateQueue(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
|
|
|
|
|
|
|
void DestroyObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
|
|
|
|
2013-11-28 11:14:24 +01:00
|
|
|
std::vector<ICustomBody*> Sample(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
2013-11-26 10:21:20 +01:00
|
|
|
private:
|
|
|
|
std::vector < Data > leafData;
|
2013-11-28 11:14:24 +01:00
|
|
|
std::vector < Data* > updateQueue;
|
2013-11-26 10:21:20 +01:00
|
|
|
|
|
|
|
std::map< ICustomBody*, unsigned int > mapReferences;
|
|
|
|
|
2013-11-28 11:14:24 +01:00
|
|
|
OctreeNode worldNode;
|
2013-11-26 10:21:20 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|