
12.4 Spatial Partitioning 281
12.4.2 Oct-Trees and Quad-Trees
Oct-trees and quad-trees are spatial tree data structures with many similarities to both
BSPs and BVHs. Quad-trees are used for two dimensions (or three dimension s where
most objects will be stuck on the ground), and oct-trees for three dimensions. In many
3D games, a quad-tree is as useful as an oct-tree and requires less memory, so I’ll focus
on that first.
A quad-tree is made up of a set of nodes, each with four descendants. Each node
splits space into four areas that intersect at a single point. A node can be represented
as a vector position and four children:
enum QuadTreeSector
{
BOTTOM_LEFT, ...