HDK
|
#include <ImathFrustumTest.h>
Public Member Functions | |
Constructors | |
FrustumTest () IMATH_NOEXCEPT | |
Initialize camera matrix to identity. More... | |
FrustumTest (const Frustum< T > &frustum, const Matrix44< T > &cameraMat) IMATH_NOEXCEPT | |
Initialize to a given frustum and camera matrix. More... | |
Set Value | |
void | setFrustum (const Frustum< T > &frustum, const Matrix44< T > &cameraMat) IMATH_NOEXCEPT |
Query | |
bool | isVisible (const Sphere3< T > &sphere) const IMATH_NOEXCEPT |
bool | isVisible (const Box< Vec3< T >> &box) const IMATH_NOEXCEPT |
bool | isVisible (const Vec3< T > &vec) const IMATH_NOEXCEPT |
Return true if the point is inside the frustum. More... | |
bool | completelyContains (const Sphere3< T > &sphere) const IMATH_NOEXCEPT |
bool | completelyContains (const Box< Vec3< T >> &box) const IMATH_NOEXCEPT |
IMATH_INTERNAL_NAMESPACE::Matrix44 < T > | cameraMat () const IMATH_NOEXCEPT |
Return the camera matrix (primarily for debugging) More... | |
IMATH_INTERNAL_NAMESPACE::Frustum < T > | currentFrustum () const IMATH_NOEXCEPT |
Return the viewing frustum (primarily for debugging) More... | |
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.
Definition at line 85 of file ImathFrustumTest.h.
|
inline |
Initialize camera matrix to identity.
Definition at line 92 of file ImathFrustumTest.h.
|
inline |
Initialize to a given frustum and camera matrix.
Definition at line 101 of file ImathFrustumTest.h.
|
inline |
Return the camera matrix (primarily for debugging)
Definition at line 141 of file ImathFrustumTest.h.
bool FrustumTest< T >::completelyContains | ( | const Sphere3< T > & | sphere | ) | const |
Return true if every part of the sphere is inside the frustum. The result MAY return close false-negatives, but not false-positives.
Definition at line 239 of file ImathFrustumTest.h.
bool FrustumTest< T >::completelyContains | ( | const Box< Vec3< T >> & | box | ) | const |
Return true if every part of the box is inside the frustum. The result MAY return close false-negatives, but not false-positives.
Definition at line 290 of file ImathFrustumTest.h.
|
inline |
Return the viewing frustum (primarily for debugging)
Definition at line 144 of file ImathFrustumTest.h.
bool FrustumTest< T >::isVisible | ( | const Sphere3< T > & | sphere | ) | const |
Return true if any part of the sphere is inside the frustum. The result MAY return close false-positives, but not false-negatives.
Definition at line 216 of file ImathFrustumTest.h.
bool FrustumTest< T >::isVisible | ( | const Box< Vec3< T >> & | box | ) | const |
Return true if any part of the box is inside the frustum. The result MAY return close false-positives, but not false-negatives.
Definition at line 262 of file ImathFrustumTest.h.
bool FrustumTest< T >::isVisible | ( | const Vec3< T > & | vec | ) | const |
Return true if the point is inside the frustum.
Definition at line 318 of file ImathFrustumTest.h.
void FrustumTest< T >::setFrustum | ( | const Frustum< T > & | frustum, |
const Matrix44< T > & | cameraMat | ||
) |
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.
Definition at line 175 of file ImathFrustumTest.h.