Reader small image

You're reading from  Game Physics Cookbook

Product typeBook
Published inMar 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781787123663
Edition1st Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Gabor Szauer
Gabor Szauer
author image
Gabor Szauer

Gabor Szauer has been making games since 2010. He graduated from Full Sail University in 2010 with a bachelor's degree in game development. Gabor maintains an active Twitter presence, and maintains a programming-oriented game development blog. Gabor's previously published books are Game Physics Programming Cookbook and Lua Quick Start Guide, both published by Packt.
Read more about Gabor Szauer

Right arrow

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*>& set, 
        const Ray& ray);
    Model* Raycast(OctreeNode* node, const Ray& ray);
    std::vector<Model*> Query(OctreeNode* node, 
        const Sphere& sphere);
    std::vector<Model*> Query(OctreeNode...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Game Physics Cookbook
Published in: Mar 2017Publisher: PacktISBN-13: 9781787123663

Author (1)

author image
Gabor Szauer

Gabor Szauer has been making games since 2010. He graduated from Full Sail University in 2010 with a bachelor's degree in game development. Gabor maintains an active Twitter presence, and maintains a programming-oriented game development blog. Gabor's previously published books are Game Physics Programming Cookbook and Lua Quick Start Guide, both published by Packt.
Read more about Gabor Szauer