Package gov.nasa.worldwind.geom
Class Frustum
- java.lang.Object
-
- gov.nasa.worldwind.geom.Frustum
-
- Direct Known Subclasses:
PickPointFrustum
public class Frustum extends java.lang.Object
Represents a view frustum composed of six planes: left, right, bottom, top, near far.Frustum instances are immutable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Frustum.Corners
Holds the eight corner points of a frustum.
-
Field Summary
Fields Modifier and Type Field Description protected Plane[]
allPlanes
Holds all six frustum planes in an array in the order left, right, bottom, top, near, far.protected Plane
bottom
protected Plane
far
protected Plane
left
protected Plane
near
protected Plane
right
protected Plane
top
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(Extent extent)
Indicates whether a specifiedExtent
is fully within this frustum.boolean
contains(Vec4 point)
Indicates whether a specified point is within this frustum.boolean
equals(java.lang.Object obj)
static Frustum
fromPerspective(double width, double height, double near, double far)
Creates aFrustum
from three sets of parallel clipping planes (a parallel projectionMatrix).static Frustum
fromPerspective(Angle horizontalFieldOfView, int viewportWidth, int viewportHeight, double near, double far)
Creates aFrustum
from a horizontal field-of-view, viewport aspect ratio and distance to near and far depth clipping planes.static Frustum
fromPerspectiveVecs(Vec4 vTL, Vec4 vTR, Vec4 vBL, Vec4 vBR, double near, double far)
Creates aFrustum
from four edge vectors, viewport aspect ratio and distance to near and far planes.static Frustum
fromProjectionMatrix(Matrix projectionMatrix)
Creates a frustum by extracting the six frustum planes from a projection matrix.Plane[]
getAllPlanes()
Returns all the planes.Plane
getBottom()
Returns the bottom plane.Frustum.Corners
getCorners()
Returns the eight corners of this frustum.Plane
getFar()
Returns the far plane.Plane
getLeft()
Returns the left plane.Plane
getNear()
Returns the near plane.Plane
getRight()
Returns the right plane.Plane
getTop()
Returns the top plane.int
hashCode()
boolean
intersects(Extent extent)
Indicates whether a specifiedExtent
intersects this frustum.boolean
intersectsSegment(Vec4 pa, Vec4 pb)
Determines whether a line segment intersects this frustum.java.lang.String
toString()
Frustum
transformBy(Matrix matrix)
Returns a copy of this frustum transformed by a specifiedMatrix
.
-
-
-
Field Detail
-
left
protected final Plane left
-
right
protected final Plane right
-
bottom
protected final Plane bottom
-
top
protected final Plane top
-
near
protected final Plane near
-
far
protected final Plane far
-
allPlanes
protected final Plane[] allPlanes
Holds all six frustum planes in an array in the order left, right, bottom, top, near, far.
-
-
Constructor Detail
-
Frustum
public Frustum()
Constructs a frustum two meters wide centered at the origin. Primarily used for testing.
-
Frustum
public Frustum(Plane left, Plane right, Plane bottom, Plane top, Plane near, Plane far)
Create a frustum from sixPlane
s defining the frustum boundaries.None of the arguments may be null.
- Parameters:
near
- the near planefar
- the far planeleft
- the left planeright
- the right planetop
- the top planebottom
- the bottom plane- Throws:
java.lang.IllegalArgumentException
- if any argument is null.
-
-
Method Detail
-
getLeft
public final Plane getLeft()
Returns the left plane.- Returns:
- the left plane.
-
getRight
public final Plane getRight()
Returns the right plane.- Returns:
- the right plane.
-
getBottom
public final Plane getBottom()
Returns the bottom plane.- Returns:
- the bottom plane.
-
getTop
public final Plane getTop()
Returns the top plane.- Returns:
- the top plane.
-
getNear
public final Plane getNear()
Returns the near plane.- Returns:
- the left plane.
-
getFar
public final Plane getFar()
Returns the far plane.- Returns:
- the left plane.
-
getAllPlanes
public Plane[] getAllPlanes()
Returns all the planes.- Returns:
- an array of the frustum planes, in the order left, right, bottom, top, near, far.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
fromProjectionMatrix
public static Frustum fromProjectionMatrix(Matrix projectionMatrix)
Creates a frustum by extracting the six frustum planes from a projection matrix.- Parameters:
projectionMatrix
- the projection matrix to extract the frustum planes from.- Returns:
- a frustum defined by the extracted planes.
- Throws:
java.lang.IllegalArgumentException
- if the projection matrix is null.
-
fromPerspective
public static Frustum fromPerspective(Angle horizontalFieldOfView, int viewportWidth, int viewportHeight, double near, double far)
Creates aFrustum
from a horizontal field-of-view, viewport aspect ratio and distance to near and far depth clipping planes. The near plane must be closer than the far plane, and both near and far values must be positive.- Parameters:
horizontalFieldOfView
- horizontal field-of-view angle in the range (0, 180)viewportWidth
- the width of the viewport in screen pixelsviewportHeight
- the height of the viewport in screen pixelsnear
- distance to the near depth clipping planefar
- distance to far depth clipping plane- Returns:
- Frustum configured from the specified perspective parameters.
- Throws:
java.lang.IllegalArgumentException
- if fov is not in the range (0, 180), if either near or far are negative, or near is greater than or equal to far
-
fromPerspective
public static Frustum fromPerspective(double width, double height, double near, double far)
Creates aFrustum
from three sets of parallel clipping planes (a parallel projectionMatrix). In this case, the near and far depth clipping planes may be negative.- Parameters:
near
- distance to the near depth clipping planefar
- distance to far depth clipping planewidth
- horizontal dimension of the near clipping planeheight
- vertical dimension of the near clipping plane- Returns:
- a Frustum configured with the specified perspective parameters.
- Throws:
java.lang.IllegalArgumentException
- if the difference of any plane set (lright - left, top - bottom, far - near) is less than or equal to zero.
-
fromPerspectiveVecs
public static Frustum fromPerspectiveVecs(Vec4 vTL, Vec4 vTR, Vec4 vBL, Vec4 vBR, double near, double far)
Creates aFrustum
from four edge vectors, viewport aspect ratio and distance to near and far planes. The edge vectors connect the near corners of the frustum to the far corners. The near plane must be closer than the far plane, and both planes must be positive.- Parameters:
vTL
- vector defining the top-left of the frustumvTR
- vector defining the top-right of the frustumvBL
- vector defining the bottom-left of the frustumvBR
- vector defining the bottom-right of the frustumnear
- distance to the near planefar
- distance to far plane- Returns:
- Frustum that was created
- Throws:
java.lang.IllegalArgumentException
- if any of the vectors are null, if either near or far are negative, or near is greater than or equal to far
-
intersects
public boolean intersects(Extent extent)
Indicates whether a specifiedExtent
intersects this frustum.- Parameters:
extent
- the Extent to test.- Returns:
- true if the extent intersects this frustum, otherwise false.
- Throws:
java.lang.IllegalArgumentException
- if the extent is null.
-
intersectsSegment
public boolean intersectsSegment(Vec4 pa, Vec4 pb)
Determines whether a line segment intersects this frustum.- Parameters:
pa
- one end of the segment.pb
- the other end of the segment.- Returns:
- true if the segment intersects or is contained in the frustum, otherwise false.
- Throws:
java.lang.IllegalArgumentException
- if either point is null.
-
contains
public final boolean contains(Extent extent)
Indicates whether a specifiedExtent
is fully within this frustum.- Parameters:
extent
- the Extent to test.- Returns:
- true if the extent is fully within this frustum, otherwise false.
- Throws:
java.lang.IllegalArgumentException
- if the extent is null.
-
contains
public final boolean contains(Vec4 point)
Indicates whether a specified point is within this frustum.- Parameters:
point
- the point to test.- Returns:
- true if the point is within the frustum, otherwise false.
- Throws:
java.lang.IllegalArgumentException
- if the point is null.
-
transformBy
public Frustum transformBy(Matrix matrix)
Returns a copy of this frustum transformed by a specifiedMatrix
.- Parameters:
matrix
- the Matrix to apply to this frustum.- Returns:
- a new frustum transformed by the specified matrix.
- Throws:
java.lang.IllegalArgumentException
- if the matrix is null.
-
getCorners
public Frustum.Corners getCorners()
Returns the eight corners of this frustum.- Returns:
- the eight frustum corners.
-
-