FrustumIntersection

Efficiently performs frustum intersection tests by caching the frustum planes of an arbitrary transformation {@link Matrix4d matrix}. <p> This class is preferred over the frustum intersection methods in {@link Matrix4d} when many objects need to be culled by the same static frustum.

@author Kai Burjack

struct FrustumIntersection {}

Constructors

this
this(Matrix4d m)

Create a new {@link FrustumIntersection} from the given {@link Matrix4d matrix} by extracing the matrix's frustum planes. <p> In order to update the compute frustum planes later on, call {@link #set(Matrix4d)}.

this
this(Matrix4d m, bool allowTestSpheres)

Create a new {@link FrustumIntersection} from the given {@link Matrix4d matrix} by extracing the matrix's frustum planes. <p> In order to update the compute frustum planes later on, call {@link #set(Matrix4d)}.

Members

Functions

distanceToPlane
float distanceToPlane(float minX, float minY, float minZ, float maxX, float maxY, float maxZ, int plane)

Compute the signed distance from the given axis-aligned box to the <code>plane</code>.

intersectAab
int intersectAab(Vector3d min, Vector3d max)

Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it. The box is specified via its <code>min</code> and <code>max</code> corner coordinates. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns {@link #INTERSECT} for boxes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem.

intersectAab
int intersectAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)

Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it. The box is specified via its min and max corner coordinates. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns {@link #INTERSECT} for boxes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem. <p> Reference: <a href="http://old.cescg.org/CESCG-2002/DSykoraJJelinek/">Efficient View Frustum Culling</a>

intersectAab
int intersectAab(Vector3d min, Vector3d max, int mask)

Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it. The box is specified via its <code>min</code> and <code>max</code> corner coordinates. <p> This method differs from {@link #intersectAab(Vector3d, Vector3d)} in that it allows to mask-off planes that should not be calculated. For example, in order to only test a box against the left frustum plane, use a mask of {@link #PLANE_MASK_NX}. Or in order to test all planes <i>except</i> the left plane, use a mask of <code>(~0 ^ PLANE_MASK_NX)</code>. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns {@link #INTERSECT} for boxes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem.

intersectAab
int intersectAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ, int mask)

Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it. The box is specified via its min and max corner coordinates. <p> This method differs from {@link #intersectAab(float, float, float, float, float, float)} in that it allows to mask-off planes that should not be calculated. For example, in order to only test a box against the left frustum plane, use a mask of {@link #PLANE_MASK_NX}. Or in order to test all planes <i>except</i> the left plane, use a mask of <code>(~0 ^ PLANE_MASK_NX)</code>. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns {@link #INTERSECT} for boxes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem. <p> Reference: <a href="http://old.cescg.org/CESCG-2002/DSykoraJJelinek/">Efficient View Frustum Culling</a>

intersectAab
int intersectAab(Vector3d min, Vector3d max, int mask, int startPlane)

Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it. The box is specified via its <code>min</code> and <code>max</code> corner coordinates. <p> This method differs from {@link #intersectAab(Vector3d, Vector3d)} in that it allows to mask-off planes that should not be calculated. For example, in order to only test a box against the left frustum plane, use a mask of {@link #PLANE_MASK_NX}. Or in order to test all planes <i>except</i> the left plane, use a mask of <code>(~0 ^ PLANE_MASK_NX)</code>. <p> In addition, the <code>startPlane</code> denotes the first frustum plane to test the box against. To use this effectively means to store the plane that previously culled an axis-aligned box (as returned by <code>intersectAab()</code>) and in the next frame use the return value as the argument to the <code>startPlane</code> parameter of this method. The assumption is that the plane that culled the object previously will also cull it now (temporal coherency) and the culling computation is likely reduced in that case. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns {@link #INTERSECT} for boxes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem.

intersectAab
int intersectAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ, int mask, int startPlane)

Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it. The box is specified via its min and max corner coordinates. <p> This method differs from {@link #intersectAab(float, float, float, float, float, float)} in that it allows to mask-off planes that should not be calculated. For example, in order to only test a box against the left frustum plane, use a mask of {@link #PLANE_MASK_NX}. Or in order to test all planes <i>except</i> the left plane, use a mask of <code>(~0 ^ PLANE_MASK_NX)</code>. <p> In addition, the <code>startPlane</code> denotes the first frustum plane to test the box against. To use this effectively means to store the plane that previously culled an axis-aligned box (as returned by <code>intersectAab()</code>) and in the next frame use the return value as the argument to the <code>startPlane</code> parameter of this method. The assumption is that the plane that culled the object previously will also cull it now (temporal coherency) and the culling computation is likely reduced in that case. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns {@link #INTERSECT} for boxes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem. <p> Reference: <a href="http://old.cescg.org/CESCG-2002/DSykoraJJelinek/">Efficient View Frustum Culling</a>

intersectSphere
int intersectSphere(Vector3d center, float radius)

Determine whether the given sphere is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns {@link #INTERSECT} for spheres that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem.

intersectSphere
int intersectSphere(float x, float y, float z, float r)

Determine whether the given sphere is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns {@link #INTERSECT} for spheres that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem.

set
FrustumIntersection set(Matrix4d m)

Update the stored frustum planes of <code>this</code> {@link FrustumIntersection} with the given {@link Matrix4d matrix}. <p> Reference: <a href="http://gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf"> Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix</a>

set
FrustumIntersection set(Matrix4d m, bool allowTestSpheres)

Update the stored frustum planes of <code>this</code> {@link FrustumIntersection} with the given {@link Matrix4d matrix} and allow to optimize the frustum plane extraction in the case when no intersection test is needed for spheres. <p> Reference: <a href="http://gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf"> Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix</a>

testAab
bool testAab(Vector3d min, Vector3d max)

Test whether the given axis-aligned box is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler. The box is specified via its <code>min</code> and <code>max</code> corner coordinates. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns <code>true</code> for boxes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem.

testAab
bool testAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)

Test whether the given axis-aligned box is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler. The box is specified via its min and max corner coordinates. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns <code>true</code> for boxes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem. <p> Reference: <a href="http://old.cescg.org/CESCG-2002/DSykoraJJelinek/">Efficient View Frustum Culling</a>

testLineSegment
bool testLineSegment(Vector3d a, Vector3d b)

Test whether the given line segment, defined by the end points <code>a</code> and <code>b</code>, is partly or completely within the frustum defined by <code>this</code> frustum culler.

testLineSegment
bool testLineSegment(float aX, float aY, float aZ, float bX, float bY, float bZ)

Test whether the given line segment, defined by the end points <code>(aX, aY, aZ)</code> and <code>(bX, bY, bZ)</code>, is partly or completely within the frustum defined by <code>this</code> frustum culler.

testPlaneXY
bool testPlaneXY(Vector2d min, Vector2d max)

Test whether the given XY-plane (at <code>Z = 0</code>) is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler. The plane is specified via its <code>min</code> and <code>max</code> corner coordinates. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns <code>true</code> for planes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem.

testPlaneXY
bool testPlaneXY(float minX, float minY, float maxX, float maxY)

Test whether the given XY-plane (at <code>Z = 0</code>) is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler. The plane is specified via its min and max corner coordinates. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns <code>true</code> for planes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem. <p> Reference: <a href="http://old.cescg.org/CESCG-2002/DSykoraJJelinek/">Efficient View Frustum Culling</a>

testPlaneXZ
bool testPlaneXZ(float minX, float minZ, float maxX, float maxZ)

Test whether the given XZ-plane (at <code>Y = 0</code>) is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler. The plane is specified via its min and max corner coordinates. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns <code>true</code> for planes that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem. <p> Reference: <a href="http://old.cescg.org/CESCG-2002/DSykoraJJelinek/">Efficient View Frustum Culling</a>

testPoint
bool testPoint(Vector3d point)

Test whether the given point is within the frustum defined by <code>this</code> frustum culler.

testPoint
bool testPoint(float x, float y, float z)

Test whether the given point <code>(x, y, z)</code> is within the frustum defined by <code>this</code> frustum culler.

testSphere
bool testSphere(Vector3d center, double radius)

Test whether the given sphere is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns <code>true</code> for spheres that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem.

testSphere
bool testSphere(double x, double y, double z, double r)

Test whether the given sphere is partly or completely within or outside of the frustum defined by <code>this</code> frustum culler. <p> The algorithm implemented by this method is conservative. This means that in certain circumstances a <i>false positive</i> can occur, when the method returns <code>true</code> for spheres that do not intersect the frustum. See <a href="http://iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm">iquilezles.org</a> for an examination of this problem.

Static variables

INSIDE
int INSIDE;

Return value of {@link #intersectAab(float, float, float, float, float, float) intersectAab()} and its different overloads indicating that the axis-aligned box is fully inside of the frustum.

INTERSECT
int INTERSECT;

Return value of {@link #intersectAab(float, float, float, float, float, float) intersectAab()} and its different overloads indicating that the axis-aligned box intersects the frustum.

OUTSIDE
int OUTSIDE;

Return value of {@link #intersectSphere(Vector3d, float)} or {@link #intersectSphere(float, float, float, float)} indicating that the sphere is completely outside of the frustum.

PLANE_MASK_NX
int PLANE_MASK_NX;

The value in a bitmask for {@link #intersectAab(float, float, float, float, float, float, int) intersectAab()} that identifies the plane with equation <code>x=-1</code> when using the identity frustum.

PLANE_MASK_NY
int PLANE_MASK_NY;

The value in a bitmask for {@link #intersectAab(float, float, float, float, float, float, int) intersectAab()} that identifies the plane with equation <code>y=-1</code> when using the identity frustum.

PLANE_MASK_NZ
int PLANE_MASK_NZ;

The value in a bitmask for {@link #intersectAab(float, float, float, float, float, float, int) intersectAab()} that identifies the plane with equation <code>z=-1</code> when using the identity frustum.

PLANE_MASK_PX
int PLANE_MASK_PX;

The value in a bitmask for {@link #intersectAab(float, float, float, float, float, float, int) intersectAab()} that identifies the plane with equation <code>x=1</code> when using the identity frustum.

PLANE_MASK_PY
int PLANE_MASK_PY;

The value in a bitmask for {@link #intersectAab(float, float, float, float, float, float, int) intersectAab()} that identifies the plane with equation <code>y=1</code> when using the identity frustum.

PLANE_MASK_PZ
int PLANE_MASK_PZ;

The value in a bitmask for {@link #intersectAab(float, float, float, float, float, float, int) intersectAab()} that identifies the plane with equation <code>z=1</code> when using the identity frustum.

PLANE_NX
int PLANE_NX;

Return value of {@link #intersectAab(float, float, float, float, float, float) intersectAab()} and its different overloads identifying the plane with equation <code>x=-1</code> when using the identity frustum.

PLANE_NY
int PLANE_NY;

Return value of {@link #intersectAab(float, float, float, float, float, float) intersectAab()} and its different overloads identifying the plane with equation <code>y=-1</code> when using the identity frustum.

PLANE_NZ
int PLANE_NZ;

Return value of {@link #intersectAab(float, float, float, float, float, float) intersectAab()} and its different overloads identifying the plane with equation <code>z=-1</code> when using the identity frustum.

PLANE_PX
int PLANE_PX;

Return value of {@link #intersectAab(float, float, float, float, float, float) intersectAab()} and its different overloads identifying the plane with equation <code>x=1</code> when using the identity frustum.

PLANE_PY
int PLANE_PY;

Return value of {@link #intersectAab(float, float, float, float, float, float) intersectAab()} and its different overloads identifying the plane with equation <code>y=1</code> when using the identity frustum.

PLANE_PZ
int PLANE_PZ;

Return value of {@link #intersectAab(float, float, float, float, float, float) intersectAab()} and its different overloads identifying the plane with equation <code>z=1</code> when using the identity frustum.

Meta