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

Sphere in frustum


Now that we can get the view frustum of a camera, we will explore how to check primitives for intersection against the frustum. We will start by checking if a point or sphere intersects the frustum. This intersection test will also handle containment:

Getting ready

In this section, we are going to implement two intersection functions. The first function will test if a point is inside of a frustum. The second function will check if a sphere intersects a frustum. Both functions handle containment as well as intersection.

How to do it…

Follow these steps to implement intersection tests for a point and a sphere against a Frustum:

  1. Declare the functions to test a point and a sphere against a frustum in Geometry3D.h:

    bool Intersects(const Frustum& f, const Point& p);
    bool Intersects(const Frustum& f, const Sphere& s);
  2. Implement the point Intersects function in Geometry3D.cpp:

    bool Intersects(const Frustum& f, const Point& p) {
       for (int i = 0; i < 6; ++i)...
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