📄 quadtree.h
字号:
#ifndef _QUADTREE_H_
#define _QUADTREE_H_
#include <vector>
#include "../entity/entity.h"
#include "../math/aabb.h"
#include "../rendernode.h"
#include "../staticgeometry.h"
#include "../global.h"
#include "../frustum.h"
#define LEAF_TYPE 0
#define NODE_TYPE 1
class GcTerrain;
class GcQuadtreeNode;
class GcQuadtree;
//////////////////////////////////////////////////////////////////////
class GcQuadtreeNode : public GcRenderEntity, GcUpdateEntity
{
public:
static const int MAX_OBJECTS;
static int numDrawn;
GcQuadtreeNode();
GcQuadtreeNode( GcQuadtree * quadtree, int depth, GcQuadtreeNode * parent, GcAABB * aabb );
~GcQuadtreeNode();
bool AttachNode( GcRenderNode * node );
bool DetachNode( GcRenderNode * node );
//bool CreateBranches( int branchType );
void GrowTree( GcQuadtree * quadtree, int depth, GcQuadtreeNode * parent, GcAABB * aabb );
void Render();
void Update(float deltaTime);
GcAABB & AABB() { return *m_aabb; }
GcQuadtree * m_quadtree;
GcAABB * m_aabb; // AABB isn't the perfect volume to use for occlusion culling in quadtree
byte m_type;
GcQuadtreeNode * m_parent;
GcQuadtreeNode * m_nodes; //[4];
GcQuadtreeNode * m_neighbors;
float m_nodeHeight;
int m_nodeDepth;
std::vector<GcRenderNode *> m_objects;
std::vector<GcStaticGeometry *> m_staticGeometry;
};
//////////////////////////////////////////////////////////////////////
class GcQuadtree : public GcRenderEntity, GcUpdateEntity
{
public:
enum Node { Branch = 0, Leaf };
static const int MAX_DEPTH;
static float nodeHeight;
static int numObjectsDrawn;
static int numStaticGeometryDrawn;
GcQuadtree();
~GcQuadtree();
bool Create(uint depth, float leafSize);
bool AttachNode( GcRenderNode * node );
bool DetachNode( GcRenderNode * node );
void Render();
void Update( float deltaTime ) { m_rootNode->Update(deltaTime); }
void Destroy();
void ToggleDebugMode() { m_debugMode = !m_debugMode; }
bool DebugMode() { return m_debugMode; }
float GetLeafSide() { return m_leafSide; }
float GetTreeSide() { return m_treeSide; }
void SetNodeHeight( float f ) { m_nodeHeight = nodeHeight = f; }
float GetNodeHeight() { return m_nodeHeight; }
private:
GcQuadtreeNode *m_rootNode;
GcFrustum *m_frustum;
uint m_depth;
float m_leafSide;
float m_treeSide;
bool m_debugMode;
float m_nodeHeight;
void CreateNodes();
void BuildNode(uint bound[4], uint parentId, uint nodeId);
uint CoordX(uint index);
uint CoordZ(uint index);
};
//////////////////////////////////////////////////////////////////////
class GcCoordinate
{
public:
float x;
float z;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -