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.ObjectRepresents 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 classFrustum.CornersHolds the eight corner points of a frustum.
-
Field Summary
Fields Modifier and Type Field Description protected Plane[]allPlanesHolds all six frustum planes in an array in the order left, right, bottom, top, near, far.protected Planebottomprotected Planefarprotected Planeleftprotected Planenearprotected Planerightprotected Planetop
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(Extent extent)Indicates whether a specifiedExtentis fully within this frustum.booleancontains(Vec4 point)Indicates whether a specified point is within this frustum.booleanequals(java.lang.Object obj)static FrustumfromPerspective(double width, double height, double near, double far)Creates aFrustumfrom three sets of parallel clipping planes (a parallel projectionMatrix).static FrustumfromPerspective(Angle horizontalFieldOfView, int viewportWidth, int viewportHeight, double near, double far)Creates aFrustumfrom a horizontal field-of-view, viewport aspect ratio and distance to near and far depth clipping planes.static FrustumfromPerspectiveVecs(Vec4 vTL, Vec4 vTR, Vec4 vBL, Vec4 vBR, double near, double far)Creates aFrustumfrom four edge vectors, viewport aspect ratio and distance to near and far planes.static FrustumfromProjectionMatrix(Matrix projectionMatrix)Creates a frustum by extracting the six frustum planes from a projection matrix.Plane[]getAllPlanes()Returns all the planes.PlanegetBottom()Returns the bottom plane.Frustum.CornersgetCorners()Returns the eight corners of this frustum.PlanegetFar()Returns the far plane.PlanegetLeft()Returns the left plane.PlanegetNear()Returns the near plane.PlanegetRight()Returns the right plane.PlanegetTop()Returns the top plane.inthashCode()booleanintersects(Extent extent)Indicates whether a specifiedExtentintersects this frustum.booleanintersectsSegment(Vec4 pa, Vec4 pb)Determines whether a line segment intersects this frustum.java.lang.StringtoString()FrustumtransformBy(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 sixPlanes 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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 aFrustumfrom 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 aFrustumfrom 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 aFrustumfrom 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 specifiedExtentintersects 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 specifiedExtentis 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.
-
-