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:
- 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);
- Implement the point
Intersects
function inGeometry3D.cpp
:bool Intersects(const Frustum& f, const Point& p) { for (int i = 0; i <...