Octree contents
Once we have built an octree, we must manage models that might occupy the same space as the tree. There are three operations that will help us manage models within the tree. We want to know when a model is added to the tree or removed from the tree. We also want to know when a model moves, as it may occupy different leaf nodes at its new position.
Getting ready
In this section, we are going to implement three support functions for the octree. We are going to create an Insert
function for when something is added to the tree. We are going to create a Remove
function for when something is removed from the tree. And finally, an Update
function for when something within the tree moves. The update function will simply remove the model from the tree and reinsert it.
How to do it…
Follow these steps to add objects to the octree or to remove objects from the octree:
- Declare the
Insert
,Remove
, andUpdate
functions inScene.h
:void Insert(OctreeNode* node, Model* model); void Remove...