Octree scene integration
In order to benefit from the Octree, we must integrate it with the scene as an acceleration structure. The OctreeNode
structure and its helper functions should not be used outside of the Scene
class.
Getting ready
First, we are going to modify the Scene
class to hold an Octree. This means dealing with some dynamic memory, so we also need to add a destructor. The copy constructor and assignment operator will be disabled. If an acceleration structure is present, we should forward operations such as raycasting to the accelerator. Of course, the original code needs to stay in place as the acceleration structure is optional.
How to do it…
Follow these steps to integrate the octree into the scene:
- Modify the
Scene
class declared inScene.h
. Add anOctreeNode
pointer to serve as the root node of the Octree. Set this pointer tonull
in the default constructor. The destructor should free this memory if it is allocated. Also, we need to declare theAccelerate
helper function...