124template<
class TYPE>
void
127 #if NEBULA_BOUNDSCHECKS
134 int baseDimension = 1 << (this->
treeDepth - 1);
136 this->boundingBox.size().y,
137 this->boundingBox.size().z / baseDimension);
144 #if NEBULA_BOUNDSCHECKS
147 for (i = 0; i < num; i++)
158template<
class TYPE>
uchar
178template<
class TYPE>
SizeT
182 return 0x55555555 & ((1 << level * 2) - 1);
189template<
class TYPE>
SizeT
200template<
class TYPE>
IndexT
203 #if NEBULA_BOUNDSCHECKS
204 n_assert((col >= 0) && (col < (1 << level)));
205 n_assert((row >= 0) && (row < (1 << level)));
207 return this->
GetNumNodes(level) + (row << level) + col;
218 return this->
nodeArray[0].FindContainmentNode(checkBox);
231 for (i = 0; i < 4; i++)
250template<
class TYPE>
void
253 #if NEBULA_BOUNDSCHECKS
261 this->
level = _level;
266 float levelFactor = float(1 << (tree->
treeDepth - 1 - this->level));
274 center.
set(treeCenter.
x + (((this->col + 0.5f) * levelFactor * baseSize.
x) - (treeSize.
x * 0.5f)),
276 treeCenter.
z + (((this->row + 0.5f) * levelFactor * baseSize.
z) - (treeSize.
z * 0.5f)));
278 extent.
set(levelFactor * baseSize.
x * 0.5f,
280 levelFactor * baseSize.
z * 0.5f );
282 this->
box.set(center, extent);
289 for (i = 0; i < 4; i++)
291 ushort childCol = 2 * this->
col + (i & 1);
292 ushort childRow = 2 * this->
row + ((i & 2) >> 1);
295 this->
children[i]->Setup(tree, childLevel, childCol, childRow);
308 if (this->
box.contains(checkBox))
314 for (i = 0; i < 4; i++)
316 Node* containNode = this->
children[i]->FindContainmentNode(checkBox);
364template<
class TYPE>
char
373template<
class TYPE>
ushort
382template<
class TYPE>
ushort
391template<
class TYPE>
void
400template<
class TYPE>
const TYPE&
Nebula's bounding box class.
Definition bbox.h:24
vec3 size() const
get size of box
Definition bbox.h:164
vector extents() const
get extents of box
Definition bbox.h:155
point center() const
get center of box
Definition bbox.h:146
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
node in quad tree
Definition quadtree.h:51
friend class QuadTree
Definition quadtree.h:77
Node * children[4]
Definition quadtree.h:79
void SetElement(const TYPE &elm)
set data element associated with node
Definition quadtree.h:392
TYPE element
Definition quadtree.h:84
Node()
constructor
Definition quadtree.h:225
ushort Column() const
get the node's column
Definition quadtree.h:374
ushort row
Definition quadtree.h:82
const TYPE & GetElement() const
get data element
Definition quadtree.h:401
Math::bbox box
Definition quadtree.h:83
ushort col
Definition quadtree.h:81
ushort Row() const
get the node's row
Definition quadtree.h:383
char level
Definition quadtree.h:80
Node * GetChildAt(IndexT i)
get child at index
Definition quadtree.h:410
~Node()
destructor
Definition quadtree.h:241
Node * FindContainmentNode(const Math::bbox &box)
recursively find the smallest child node which contains the bounding box
Definition quadtree.h:306
const Math::bbox & GetBoundingBox() const
compute the node's bounding box
Definition quadtree.h:356
char Level() const
get the node's level
Definition quadtree.h:365
void Setup(QuadTree< TYPE > *tree, uchar _level, ushort _col, ushort _row)
recursively initialize the node
Definition quadtree.h:251
Math::bbox boundingBox
Definition quadtree.h:91
Util::FixedArray< Node > nodeArray
Definition quadtree.h:93
~QuadTree()
destructor
Definition quadtree.h:113
Node * FindContainmentNode(const Math::bbox &box)
recursively find the smallest child node which contains the bounding box
Definition quadtree.h:216
SizeT GetNumNodesInTree() const
get overall number of nodes in the tree
Definition quadtree.h:190
QuadTree()
constructor
Definition quadtree.h:101
SizeT GetNumNodes(uchar level) const
compute number of nodes in a level, including its children
Definition quadtree.h:179
uchar treeDepth
Definition quadtree.h:90
IndexT GetNodeIndex(uchar level, ushort col, ushort row) const
compute linear chunk index from level, col and row
Definition quadtree.h:201
uchar GetDepth() const
get the tree depth
Definition quadtree.h:159
Node & NodeByIndex(IndexT i)
read/write access to node
Definition quadtree.h:347
const Math::bbox & GetBoundingBox() const
get the top level bounding box
Definition quadtree.h:169
Math::vector baseNodeSize
Definition quadtree.h:92
void Setup(const Math::bbox &box, uchar depth)
initialize quad tree
Definition quadtree.h:125
const Node & GetNodeByIndex(IndexT i) const
get pointer to node by index
Definition quadtree.h:338
#define n_assert(exp)
Definition debug.h:50
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
A vector is a 3D direction in space.
Definition vector.h:22
float z
Definition vector.h:85
float x
Definition vector.h:85
float y
Definition vector.h:85
void set(scalar x, scalar y, scalar z)
set content
Definition vector.h:353
unsigned char uchar
Definition types.h:33
int SizeT
Definition types.h:49
unsigned short ushort
Definition types.h:32
int IndexT
Definition types.h:48