Operations on the Octree

Because our Octree serves as an acceleration structure to the Scene class, we want to implement the same operations Scene supports in Octree. This means we need to implement the same Raycast and Query functions that the Scene class already supports.

Getting ready

In this section, we are going to implement Raycast and Query functions for our new Octree. In order to implement the Raycast function, we will create a FindClosest helper function. The FindClosest function takes a set of models and a ray, and then returns the closest object to the origin of the ray.

How to do it…

Follow these steps to add Raycast and query functionality to the octree:

  1. Declare the FindClosest, Raycast, and Query functions in Scene.h:
    Model* FindClosest(conststd::vector<Model*>& ...

Get Game Physics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.