Class FrustumIntersection
- java.lang.Object
-
- org.joml.FrustumIntersection
-
public class FrustumIntersection extends java.lang.Object
Efficiently performs frustum intersection tests by caching the frustum planes of an arbitrary transformationmatrix
.This class is preferred over the frustum intersection methods in
Matrix4fc
when many objects need to be culled by the same static frustum.- Author:
- Kai Burjack
-
-
Field Summary
Fields Modifier and Type Field Description static int
INSIDE
Return value ofintersectAab()
and its different overloads indicating that the axis-aligned box is fully inside of the frustum.static int
INTERSECT
Return value ofintersectAab()
and its different overloads indicating that the axis-aligned box intersects the frustum.static int
OUTSIDE
Return value ofintersectSphere(Vector3fc, float)
orintersectSphere(float, float, float, float)
indicating that the sphere is completely outside of the frustum.static int
PLANE_MASK_NX
The value in a bitmask forintersectAab()
that identifies the plane with equationx=-1
when using the identity frustum.static int
PLANE_MASK_NY
The value in a bitmask forintersectAab()
that identifies the plane with equationy=-1
when using the identity frustum.static int
PLANE_MASK_NZ
The value in a bitmask forintersectAab()
that identifies the plane with equationz=-1
when using the identity frustum.static int
PLANE_MASK_PX
The value in a bitmask forintersectAab()
that identifies the plane with equationx=1
when using the identity frustum.static int
PLANE_MASK_PY
The value in a bitmask forintersectAab()
that identifies the plane with equationy=1
when using the identity frustum.static int
PLANE_MASK_PZ
The value in a bitmask forintersectAab()
that identifies the plane with equationz=1
when using the identity frustum.static int
PLANE_NX
Return value ofintersectAab()
and its different overloads identifying the plane with equationx=-1
when using the identity frustum.static int
PLANE_NY
Return value ofintersectAab()
and its different overloads identifying the plane with equationy=-1
when using the identity frustum.static int
PLANE_NZ
Return value ofintersectAab()
and its different overloads identifying the plane with equationz=-1
when using the identity frustum.static int
PLANE_PX
Return value ofintersectAab()
and its different overloads identifying the plane with equationx=1
when using the identity frustum.static int
PLANE_PY
Return value ofintersectAab()
and its different overloads identifying the plane with equationy=1
when using the identity frustum.static int
PLANE_PZ
Return value ofintersectAab()
and its different overloads identifying the plane with equationz=1
when using the identity frustum.
-
Constructor Summary
Constructors Constructor Description FrustumIntersection()
Create a newFrustumIntersection
with undefined frustum planes.FrustumIntersection(Matrix4fc m)
Create a newFrustumIntersection
from the givenmatrix
by extracing the matrix's frustum planes.FrustumIntersection(Matrix4fc m, boolean allowTestSpheres)
Create a newFrustumIntersection
from the givenmatrix
by extracing the matrix's frustum planes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 theplane
.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 bythis
frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it.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 bythis
frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it.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 bythis
frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it.int
intersectAab(Vector3fc min, Vector3fc max)
Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined bythis
frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it.int
intersectAab(Vector3fc min, Vector3fc max, int mask)
Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined bythis
frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it.int
intersectAab(Vector3fc min, Vector3fc max, int mask, int startPlane)
Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined bythis
frustum culler and, if the box is not inside this frustum, return the index of the plane that culled it.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 bythis
frustum culler.int
intersectSphere(Vector3fc center, float radius)
Determine whether the given sphere is partly or completely within or outside of the frustum defined bythis
frustum culler.FrustumIntersection
set(Matrix4fc m)
FrustumIntersection
set(Matrix4fc m, boolean allowTestSpheres)
Update the stored frustum planes ofthis
FrustumIntersection
with the givenmatrix
and allow to optimize the frustum plane extraction in the case when no intersection test is needed for spheres.boolean
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 bythis
frustum culler.boolean
testAab(Vector3fc min, Vector3fc max)
Test whether the given axis-aligned box is partly or completely within or outside of the frustum defined bythis
frustum culler.boolean
testLineSegment(float aX, float aY, float aZ, float bX, float bY, float bZ)
Test whether the given line segment, defined by the end points(aX, aY, aZ)
and(bX, bY, bZ)
, is partly or completely within the frustum defined bythis
frustum culler.boolean
testLineSegment(Vector3fc a, Vector3fc b)
Test whether the given line segment, defined by the end pointsa
andb
, is partly or completely within the frustum defined bythis
frustum culler.boolean
testPlaneXY(float minX, float minY, float maxX, float maxY)
Test whether the given XY-plane (atZ = 0
) is partly or completely within or outside of the frustum defined bythis
frustum culler.boolean
testPlaneXY(Vector2fc min, Vector2fc max)
Test whether the given XY-plane (atZ = 0
) is partly or completely within or outside of the frustum defined bythis
frustum culler.boolean
testPlaneXZ(float minX, float minZ, float maxX, float maxZ)
Test whether the given XZ-plane (atY = 0
) is partly or completely within or outside of the frustum defined bythis
frustum culler.boolean
testPoint(float x, float y, float z)
Test whether the given point(x, y, z)
is within the frustum defined bythis
frustum culler.boolean
testPoint(Vector3fc point)
Test whether the given point is within the frustum defined bythis
frustum culler.boolean
testSphere(float x, float y, float z, float r)
Test whether the given sphere is partly or completely within or outside of the frustum defined bythis
frustum culler.boolean
testSphere(Vector3fc center, float radius)
Test whether the given sphere is partly or completely within or outside of the frustum defined bythis
frustum culler.
-
-
-
Field Detail
-
PLANE_NX
public static final int PLANE_NX
Return value ofintersectAab()
and its different overloads identifying the plane with equationx=-1
when using the identity frustum.- See Also:
- Constant Field Values
-
PLANE_PX
public static final int PLANE_PX
Return value ofintersectAab()
and its different overloads identifying the plane with equationx=1
when using the identity frustum.- See Also:
- Constant Field Values
-
PLANE_NY
public static final int PLANE_NY
Return value ofintersectAab()
and its different overloads identifying the plane with equationy=-1
when using the identity frustum.- See Also:
- Constant Field Values
-
PLANE_PY
public static final int PLANE_PY
Return value ofintersectAab()
and its different overloads identifying the plane with equationy=1
when using the identity frustum.- See Also:
- Constant Field Values
-
PLANE_NZ
public static final int PLANE_NZ
Return value ofintersectAab()
and its different overloads identifying the plane with equationz=-1
when using the identity frustum.- See Also:
- Constant Field Values
-
PLANE_PZ
public static final int PLANE_PZ
Return value ofintersectAab()
and its different overloads identifying the plane with equationz=1
when using the identity frustum.- See Also:
- Constant Field Values
-
INTERSECT
public static final int INTERSECT
Return value ofintersectAab()
and its different overloads indicating that the axis-aligned box intersects the frustum.- See Also:
- Constant Field Values
-
INSIDE
public static final int INSIDE
Return value ofintersectAab()
and its different overloads indicating that the axis-aligned box is fully inside of the frustum.- See Also:
- Constant Field Values
-
OUTSIDE
public static final int OUTSIDE
Return value ofintersectSphere(Vector3fc, float)
orintersectSphere(float, float, float, float)
indicating that the sphere is completely outside of the frustum.- See Also:
- Constant Field Values
-
PLANE_MASK_NX
public static final int PLANE_MASK_NX
The value in a bitmask forintersectAab()
that identifies the plane with equationx=-1
when using the identity frustum.- See Also:
- Constant Field Values
-
PLANE_MASK_PX
public static final int PLANE_MASK_PX
The value in a bitmask forintersectAab()
that identifies the plane with equationx=1
when using the identity frustum.- See Also:
- Constant Field Values
-
PLANE_MASK_NY
public static final int PLANE_MASK_NY
The value in a bitmask forintersectAab()
that identifies the plane with equationy=-1
when using the identity frustum.- See Also:
- Constant Field Values
-
PLANE_MASK_PY
public static final int PLANE_MASK_PY
The value in a bitmask forintersectAab()
that identifies the plane with equationy=1
when using the identity frustum.- See Also:
- Constant Field Values
-
PLANE_MASK_NZ
public static final int PLANE_MASK_NZ
The value in a bitmask forintersectAab()
that identifies the plane with equationz=-1
when using the identity frustum.- See Also:
- Constant Field Values
-
PLANE_MASK_PZ
public static final int PLANE_MASK_PZ
The value in a bitmask forintersectAab()
that identifies the plane with equationz=1
when using the identity frustum.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FrustumIntersection
public FrustumIntersection()
Create a newFrustumIntersection
with undefined frustum planes.Before using any of the frustum culling methods, make sure to define the frustum planes using
set(Matrix4fc)
.
-
FrustumIntersection
public FrustumIntersection(Matrix4fc m)
Create a newFrustumIntersection
from the givenmatrix
by extracing the matrix's frustum planes.In order to update the compute frustum planes later on, call
set(Matrix4fc)
.- Parameters:
m
- theMatrix4fc
to create the frustum culler from- See Also:
set(Matrix4fc)
-
FrustumIntersection
public FrustumIntersection(Matrix4fc m, boolean allowTestSpheres)
Create a newFrustumIntersection
from the givenmatrix
by extracing the matrix's frustum planes.In order to update the compute frustum planes later on, call
set(Matrix4fc)
.- Parameters:
m
- theMatrix4fc
to create the frustum culler fromallowTestSpheres
- whether the methodstestSphere(Vector3fc, float)
,testSphere(float, float, float, float)
,intersectSphere(Vector3fc, float)
orintersectSphere(float, float, float, float)
will used. If no spheres need to be tested, thenfalse
should be used- See Also:
set(Matrix4fc)
-
-
Method Detail
-
set
public FrustumIntersection set(Matrix4fc m)
Update the stored frustum planes ofthis
FrustumIntersection
with the givenmatrix
.Reference: Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix
- Parameters:
m
- thematrix
to updatethis
frustum culler's frustum planes from- Returns:
- this
-
set
public FrustumIntersection set(Matrix4fc m, boolean allowTestSpheres)
Update the stored frustum planes ofthis
FrustumIntersection
with the givenmatrix
and allow to optimize the frustum plane extraction in the case when no intersection test is needed for spheres.Reference: Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix
- Parameters:
m
- thematrix
to updatethis
frustum culler's frustum planes fromallowTestSpheres
- whether the methodstestSphere(Vector3fc, float)
,testSphere(float, float, float, float)
,intersectSphere(Vector3fc, float)
orintersectSphere(float, float, float, float)
will be used. If no spheres need to be tested, thenfalse
should be used- Returns:
- this
-
testPoint
public boolean testPoint(Vector3fc point)
Test whether the given point is within the frustum defined bythis
frustum culler.- Parameters:
point
- the point to test- Returns:
true
if the given point is inside the frustum;false
otherwise
-
testPoint
public boolean testPoint(float x, float y, float z)
Test whether the given point(x, y, z)
is within the frustum defined bythis
frustum culler.- Parameters:
x
- the x-coordinate of the pointy
- the y-coordinate of the pointz
- the z-coordinate of the point- Returns:
true
if the given point is inside the frustum;false
otherwise
-
testSphere
public boolean testSphere(Vector3fc center, float radius)
Test whether the given sphere is partly or completely within or outside of the frustum defined bythis
frustum culler.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
true
for spheres that do not intersect the frustum. See iquilezles.org for an examination of this problem.- Parameters:
center
- the sphere's centerradius
- the sphere's radius- Returns:
true
if the given sphere is partly or completely inside the frustum;false
otherwise
-
testSphere
public boolean testSphere(float x, float y, float z, float r)
Test whether the given sphere is partly or completely within or outside of the frustum defined bythis
frustum culler.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
true
for spheres that do not intersect the frustum. See iquilezles.org for an examination of this problem.- Parameters:
x
- the x-coordinate of the sphere's centery
- the y-coordinate of the sphere's centerz
- the z-coordinate of the sphere's centerr
- the sphere's radius- Returns:
true
if the given sphere is partly or completely inside the frustum;false
otherwise
-
intersectSphere
public int intersectSphere(Vector3fc center, float radius)
Determine whether the given sphere is partly or completely within or outside of the frustum defined bythis
frustum culler.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
INTERSECT
for spheres that do not intersect the frustum. See iquilezles.org for an examination of this problem.
-
intersectSphere
public 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 bythis
frustum culler.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
INTERSECT
for spheres that do not intersect the frustum. See iquilezles.org for an examination of this problem.- Parameters:
x
- the x-coordinate of the sphere's centery
- the y-coordinate of the sphere's centerz
- the z-coordinate of the sphere's centerr
- the sphere's radius- Returns:
INSIDE
if the given sphere is completely inside the frustum, orINTERSECT
if the sphere intersects the frustum, orOUTSIDE
if the sphere is outside of the frustum
-
testAab
public boolean testAab(Vector3fc min, Vector3fc max)
Test whether the given axis-aligned box is partly or completely within or outside of the frustum defined bythis
frustum culler. The box is specified via itsmin
andmax
corner coordinates.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
true
for boxes that do not intersect the frustum. See iquilezles.org for an examination of this problem.- Parameters:
min
- the minimum corner coordinates of the axis-aligned boxmax
- the maximum corner coordinates of the axis-aligned box- Returns:
true
if the axis-aligned box is completely or partly inside of the frustum;false
otherwise
-
testAab
public boolean 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 bythis
frustum culler. The box is specified via its min and max corner coordinates.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
true
for boxes that do not intersect the frustum. See iquilezles.org for an examination of this problem.Reference: Efficient View Frustum Culling
- Parameters:
minX
- the x-coordinate of the minimum cornerminY
- the y-coordinate of the minimum cornerminZ
- the z-coordinate of the minimum cornermaxX
- the x-coordinate of the maximum cornermaxY
- the y-coordinate of the maximum cornermaxZ
- the z-coordinate of the maximum corner- Returns:
true
if the axis-aligned box is completely or partly inside of the frustum;false
otherwise
-
testPlaneXY
public boolean testPlaneXY(Vector2fc min, Vector2fc max)
Test whether the given XY-plane (atZ = 0
) is partly or completely within or outside of the frustum defined bythis
frustum culler. The plane is specified via itsmin
andmax
corner coordinates.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
true
for planes that do not intersect the frustum. See iquilezles.org for an examination of this problem.- Parameters:
min
- the minimum corner coordinates of the XY-planemax
- the maximum corner coordinates of the XY-plane- Returns:
true
if the XY-plane is completely or partly inside of the frustum;false
otherwise
-
testPlaneXY
public boolean testPlaneXY(float minX, float minY, float maxX, float maxY)
Test whether the given XY-plane (atZ = 0
) is partly or completely within or outside of the frustum defined bythis
frustum culler. The plane is specified via its min and max corner coordinates.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
true
for planes that do not intersect the frustum. See iquilezles.org for an examination of this problem.Reference: Efficient View Frustum Culling
- Parameters:
minX
- the x-coordinate of the minimum cornerminY
- the y-coordinate of the minimum cornermaxX
- the x-coordinate of the maximum cornermaxY
- the y-coordinate of the maximum corner- Returns:
true
if the XY-plane is completely or partly inside of the frustum;false
otherwise
-
testPlaneXZ
public boolean testPlaneXZ(float minX, float minZ, float maxX, float maxZ)
Test whether the given XZ-plane (atY = 0
) is partly or completely within or outside of the frustum defined bythis
frustum culler. The plane is specified via its min and max corner coordinates.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
true
for planes that do not intersect the frustum. See iquilezles.org for an examination of this problem.Reference: Efficient View Frustum Culling
- Parameters:
minX
- the x-coordinate of the minimum cornerminZ
- the z-coordinate of the minimum cornermaxX
- the x-coordinate of the maximum cornermaxZ
- the z-coordinate of the maximum corner- Returns:
true
if the XZ-plane is completely or partly inside of the frustum;false
otherwise
-
intersectAab
public int intersectAab(Vector3fc min, Vector3fc max)
Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined bythis
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 itsmin
andmax
corner coordinates.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
INTERSECT
for boxes that do not intersect the frustum. See iquilezles.org for an examination of this problem.- Parameters:
min
- the minimum corner coordinates of the axis-aligned boxmax
- the maximum corner coordinates of the axis-aligned box- Returns:
- the index of the first plane that culled the box, if the box does not intersect the frustum;
or
INTERSECT
if the box intersects the frustum, orINSIDE
if the box is fully inside of the frustum. The plane index is one ofPLANE_NX
,PLANE_PX
,PLANE_NY
,PLANE_PY
,PLANE_NZ
andPLANE_PZ
-
intersectAab
public 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 bythis
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.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
INTERSECT
for boxes that do not intersect the frustum. See iquilezles.org for an examination of this problem.Reference: Efficient View Frustum Culling
- Parameters:
minX
- the x-coordinate of the minimum cornerminY
- the y-coordinate of the minimum cornerminZ
- the z-coordinate of the minimum cornermaxX
- the x-coordinate of the maximum cornermaxY
- the y-coordinate of the maximum cornermaxZ
- the z-coordinate of the maximum corner- Returns:
- the index of the first plane that culled the box, if the box does not intersect the frustum,
or
INTERSECT
if the box intersects the frustum, orINSIDE
if the box is fully inside of the frustum. The plane index is one ofPLANE_NX
,PLANE_PX
,PLANE_NY
,PLANE_PY
,PLANE_NZ
andPLANE_PZ
-
distanceToPlane
public 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 theplane
.- Parameters:
minX
- the x-coordinate of the minimum cornerminY
- the y-coordinate of the minimum cornerminZ
- the z-coordinate of the minimum cornermaxX
- the x-coordinate of the maximum cornermaxY
- the y-coordinate of the maximum cornermaxZ
- the z-coordinate of the maximum cornerplane
- one ofPLANE_NX
,PLANE_PX
,PLANE_NY
,PLANE_PY
,PLANE_NZ
andPLANE_PZ
- Returns:
- the signed distance of the axis-aligned box to the plane
-
intersectAab
public int intersectAab(Vector3fc min, Vector3fc max, int mask)
Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined bythis
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 itsmin
andmax
corner coordinates.This method differs from
intersectAab(Vector3fc, Vector3fc)
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 ofPLANE_MASK_NX
. Or in order to test all planes except the left plane, use a mask of(~0 ^ PLANE_MASK_NX)
.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
INTERSECT
for boxes that do not intersect the frustum. See iquilezles.org for an examination of this problem.- Parameters:
min
- the minimum corner coordinates of the axis-aligned boxmax
- the maximum corner coordinates of the axis-aligned boxmask
- contains as bitset all the planes that should be tested. This value can be any combination ofPLANE_MASK_NX
,PLANE_MASK_PX
,PLANE_MASK_NY
,PLANE_MASK_PY
,PLANE_MASK_NZ
andPLANE_MASK_PZ
- Returns:
- the index of the first plane that culled the box, if the box does not intersect the frustum,
or
INTERSECT
if the box intersects the frustum, orINSIDE
if the box is fully inside of the frustum. The plane index is one ofPLANE_NX
,PLANE_PX
,PLANE_NY
,PLANE_PY
,PLANE_NZ
andPLANE_PZ
-
intersectAab
public 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 bythis
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.This method differs from
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 ofPLANE_MASK_NX
. Or in order to test all planes except the left plane, use a mask of(~0 ^ PLANE_MASK_NX)
.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
INTERSECT
for boxes that do not intersect the frustum. See iquilezles.org for an examination of this problem.Reference: Efficient View Frustum Culling
- Parameters:
minX
- the x-coordinate of the minimum cornerminY
- the y-coordinate of the minimum cornerminZ
- the z-coordinate of the minimum cornermaxX
- the x-coordinate of the maximum cornermaxY
- the y-coordinate of the maximum cornermaxZ
- the z-coordinate of the maximum cornermask
- contains as bitset all the planes that should be tested. This value can be any combination ofPLANE_MASK_NX
,PLANE_MASK_PX
,PLANE_MASK_NY
,PLANE_MASK_PY
,PLANE_MASK_NZ
andPLANE_MASK_PZ
- Returns:
- the index of the first plane that culled the box, if the box does not intersect the frustum,
or
INTERSECT
if the box intersects the frustum, orINSIDE
if the box is fully inside of the frustum. The plane index is one ofPLANE_NX
,PLANE_PX
,PLANE_NY
,PLANE_PY
,PLANE_NZ
andPLANE_PZ
-
intersectAab
public int intersectAab(Vector3fc min, Vector3fc max, int mask, int startPlane)
Determine whether the given axis-aligned box is partly or completely within or outside of the frustum defined bythis
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 itsmin
andmax
corner coordinates.This method differs from
intersectAab(Vector3fc, Vector3fc)
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 ofPLANE_MASK_NX
. Or in order to test all planes except the left plane, use a mask of(~0 ^ PLANE_MASK_NX)
.In addition, the
startPlane
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 byintersectAab()
) and in the next frame use the return value as the argument to thestartPlane
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.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
INTERSECT
for boxes that do not intersect the frustum. See iquilezles.org for an examination of this problem.- Parameters:
min
- the minimum corner coordinates of the axis-aligned boxmax
- the maximum corner coordinates of the axis-aligned boxmask
- contains as bitset all the planes that should be tested. This value can be any combination ofPLANE_MASK_NX
,PLANE_MASK_PX
,PLANE_MASK_NY
,PLANE_MASK_PY
,PLANE_MASK_NZ
andPLANE_MASK_PZ
startPlane
- the first frustum plane to test the axis-aligned box against. It is one ofPLANE_NX
,PLANE_PX
,PLANE_NY
,PLANE_PY
,PLANE_NZ
andPLANE_PZ
- Returns:
- the index of the first plane that culled the box, if the box does not intersect the frustum,
or
INTERSECT
if the box intersects the frustum, orINSIDE
if the box is fully inside of the frustum. The plane index is one ofPLANE_NX
,PLANE_PX
,PLANE_NY
,PLANE_PY
,PLANE_NZ
andPLANE_PZ
-
intersectAab
public 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 bythis
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.This method differs from
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 ofPLANE_MASK_NX
. Or in order to test all planes except the left plane, use a mask of(~0 ^ PLANE_MASK_NX)
.In addition, the
startPlane
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 byintersectAab()
) and in the next frame use the return value as the argument to thestartPlane
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.The algorithm implemented by this method is conservative. This means that in certain circumstances a false positive can occur, when the method returns
INTERSECT
for boxes that do not intersect the frustum. See iquilezles.org for an examination of this problem.Reference: Efficient View Frustum Culling
- Parameters:
minX
- the x-coordinate of the minimum cornerminY
- the y-coordinate of the minimum cornerminZ
- the z-coordinate of the minimum cornermaxX
- the x-coordinate of the maximum cornermaxY
- the y-coordinate of the maximum cornermaxZ
- the z-coordinate of the maximum cornermask
- contains as bitset all the planes that should be tested. This value can be any combination ofPLANE_MASK_NX
,PLANE_MASK_PX
,PLANE_MASK_NY
,PLANE_MASK_PY
,PLANE_MASK_NZ
andPLANE_MASK_PZ
startPlane
- the first frustum plane to test the axis-aligned box against. It is one ofPLANE_NX
,PLANE_PX
,PLANE_NY
,PLANE_PY
,PLANE_NZ
andPLANE_PZ
- Returns:
- the index of the first plane that culled the box, if the box does not intersect the frustum,
or
INTERSECT
if the box intersects the frustum, orINSIDE
if the box is fully inside of the frustum. The plane index is one ofPLANE_NX
,PLANE_PX
,PLANE_NY
,PLANE_PY
,PLANE_NZ
andPLANE_PZ
-
testLineSegment
public boolean testLineSegment(Vector3fc a, Vector3fc b)
Test whether the given line segment, defined by the end pointsa
andb
, is partly or completely within the frustum defined bythis
frustum culler.- Parameters:
a
- the line segment's first end pointb
- the line segment's second end point- Returns:
true
if the given line segment is partly or completely inside the frustum;false
otherwise
-
testLineSegment
public boolean testLineSegment(float aX, float aY, float aZ, float bX, float bY, float bZ)
Test whether the given line segment, defined by the end points(aX, aY, aZ)
and(bX, bY, bZ)
, is partly or completely within the frustum defined bythis
frustum culler.- Parameters:
aX
- the x coordinate of the line segment's first end pointaY
- the y coordinate of the line segment's first end pointaZ
- the z coordinate of the line segment's first end pointbX
- the x coordinate of the line segment's second end pointbY
- the y coordinate of the line segment's second end pointbZ
- the z coordinate of the line segment's second end point- Returns:
true
if the given line segment is partly or completely inside the frustum;false
otherwise
-
-