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:
|
2013-11-28 17:59:12 +01:00
|
|
|
static const unsigned int invalid_ref;
|
|
|
|
|
2014-01-21 14:10:31 +01:00
|
|
|
typedef void(*VisitorAction)(Octree&, unsigned int, unsigned int);
|
|
|
|
typedef void(*VisitorActionCollideable)(Octree&, unsigned int);
|
2013-11-28 14:18:44 +01:00
|
|
|
|
2013-11-26 10:21:20 +01:00
|
|
|
struct Data
|
|
|
|
{
|
|
|
|
Data* prev;
|
|
|
|
Data* next;
|
|
|
|
|
|
|
|
Collision3D::Sphere container;
|
|
|
|
|
2013-11-28 14:18:44 +01:00
|
|
|
::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef;
|
2013-11-26 10:21:20 +01:00
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2013-11-28 14:18:44 +01:00
|
|
|
Octree(unsigned int bufferSize = 0, unsigned char numLayers = 0, Math::Float3 worldSize = Math::Float3::null);
|
2013-11-26 10:21:20 +01:00
|
|
|
virtual ~Octree();
|
|
|
|
|
2013-11-28 14:18:44 +01:00
|
|
|
Octree& operator=(const Octree& orig);
|
|
|
|
|
|
|
|
void AddObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
|
|
|
|
|
|
|
void MoveToUpdateQueue(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
|
|
|
|
|
|
|
void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
2013-11-26 10:21:20 +01:00
|
|
|
|
2013-11-29 09:03:37 +01:00
|
|
|
std::vector<ICustomBody*>& Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList);
|
2013-11-29 09:07:52 +01:00
|
|
|
std::vector<ICustomBody*>& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector<ICustomBody*>& updateList);
|
2014-01-21 14:10:31 +01:00
|
|
|
void Visit(ICustomBody* customBodyRef, VisitorAction hitAction );
|
|
|
|
void Visit(const Oyster::Collision3D::ICollideable& collideable, VisitorActionCollideable hitAction );
|
2013-11-26 10:21:20 +01:00
|
|
|
|
2013-11-28 14:18:44 +01:00
|
|
|
ICustomBody* GetCustomBody(const unsigned int tempRef);
|
2013-11-26 10:21:20 +01:00
|
|
|
|
2013-11-28 17:59:12 +01:00
|
|
|
::Utility::DynamicMemory::UniquePointer<ICustomBody> Extract( const ICustomBody* objRef );
|
|
|
|
::Utility::DynamicMemory::UniquePointer<ICustomBody> Extract( unsigned int tempRef ); // Dan vill ha
|
|
|
|
unsigned int GetTemporaryReferenceOf( const ICustomBody* objRef ) const; // Dan vill ha
|
|
|
|
void SetAsAltered( unsigned int tempRef ); // Dan vill ha
|
|
|
|
void EvaluatePosition( unsigned int tempRef ); // Dan vill ha
|
|
|
|
|
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
|
|
|
|
2013-11-28 17:59:12 +01:00
|
|
|
std::map< const ICustomBody*, unsigned int > mapReferences;
|
2013-11-26 10:21:20 +01:00
|
|
|
|
2013-11-28 11:14:24 +01:00
|
|
|
OctreeNode worldNode;
|
2013-11-26 10:21:20 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|