Atoms Crowd  7.0.0
FrustumTest< T > Class Template Reference

#include <ImathFrustumTest.h>

Public Member Functions

Constructors
 FrustumTest () noexcept
 Initialize camera matrix to identity.
 
 FrustumTest (const Frustum< T > &frustum, const Matrix44< T > &cameraMat) noexcept
 Initialize to a given frustum and camera matrix.
 
Set Value
void setFrustum (const Frustum< T > &frustum, const Matrix44< T > &cameraMat) noexcept
 
Query
bool isVisible (const Sphere3< T > &sphere) const noexcept
 
bool isVisible (const Box< Vec3< T >> &box) const noexcept
 
bool isVisible (const Vec3< T > &vec) const noexcept
 Return true if the point is inside the frustum.
 
bool completelyContains (const Sphere3< T > &sphere) const noexcept
 
bool completelyContains (const Box< Vec3< T >> &box) const noexcept
 
ATOMSMATH_INTERNAL_NAMESPACE::Matrix44< T > cameraMat () const noexcept
 Return the camera matrix (primarily for debugging)
 
ATOMSMATH_INTERNAL_NAMESPACE::Frustum< T > currentFrustum () const noexcept
 Return the viewing frustum (primarily for debugging)
 

Detailed Description

template<class T>
class FrustumTest< T >

template class FrustumTest<T>

This is a helper class, designed to accelerate the case where many tests are made against the same frustum. That's a really common case.

The acceleration is achieved by pre-computing the planes of the frustum, along with the ablsolute values of the plane normals.

How to use this

Given that you already have: Imath::Frustum myFrustum Imath::Matrix44 myCameraWorldMatrix

First, make a frustum test object: FrustumTest myFrustumTest(myFrustum, myCameraWorldMatrix)

Whenever the camera or frustum changes, call: myFrustumTest.setFrustum(myFrustum, myCameraWorldMatrix)

For each object you want to test for visibility, call: myFrustumTest.isVisible(myBox) myFrustumTest.isVisible(mySphere) myFrustumTest.isVisible(myVec3) myFrustumTest.completelyContains(myBox) myFrustumTest.completelyContains(mySphere)

Explanation of how it works

We store six world-space Frustum planes (nx, ny, nz, offset)

Points: To test a Vec3 for visibility, test it against each plane using the normal (v dot n - offset) method. (the result is exact)

BBoxes: To test an axis-aligned bbox, test the center against each plane using the normal (v dot n - offset) method, but offset by the box extents dot the abs of the plane normal. (the result is NOT exact, but will not return false-negatives.)

Spheres: To test a sphere, test the center against each plane using the normal (v dot n - offset) method, but offset by the sphere's radius. (the result is NOT exact, but will not return false-negatives.)

SPECIAL NOTE: "Where are the dot products?" Actual dot products are currently slow for most SIMD architectures. In order to keep this code optimization-ready, the dot products are all performed using vector adds and multipies.

In order to do this, the plane equations are stored in "transpose" form, with the X components grouped into an X vector, etc.

Member Function Documentation

◆ completelyContains() [1/2]

template<typename T >
bool FrustumTest< T >::completelyContains ( const Box< Vec3< T >> &  box) const
noexcept

Return true if every part of the box is inside the frustum. The result MAY return close false-negatives, but not false-positives.

◆ completelyContains() [2/2]

template<typename T >
bool FrustumTest< T >::completelyContains ( const Sphere3< T > &  sphere) const
noexcept

Return true if every part of the sphere is inside the frustum. The result MAY return close false-negatives, but not false-positives.

◆ isVisible() [1/2]

template<typename T >
bool FrustumTest< T >::isVisible ( const Box< Vec3< T >> &  box) const
noexcept

Return true if any part of the box is inside the frustum. The result MAY return close false-positives, but not false-negatives.

◆ isVisible() [2/2]

template<typename T >
bool FrustumTest< T >::isVisible ( const Sphere3< T > &  sphere) const
noexcept

Return true if any part of the sphere is inside the frustum. The result MAY return close false-positives, but not false-negatives.

◆ setFrustum()

template<class T >
void FrustumTest< T >::setFrustum ( const Frustum< T > &  frustum,
const Matrix44< T > &  cameraMat 
)
noexcept

Update the frustum test with a new frustum and matrix. This should usually be called just once per frame, or however often the camera moves.


The documentation for this class was generated from the following file: