NASA World Wind

gov.nasa.worldwind.geom
Class Frustum

java.lang.Object
  extended by gov.nasa.worldwind.geom.Frustum
Direct Known Subclasses:
PickPointFrustum

public class Frustum
extends Object

Represents a view frustum composed of six planes: left, right, bottom, top, near far.

Frustum instances are immutable.


Nested Class Summary
static class Frustum.Corners
          Holds the eight corner points of a frustum.
 
Field Summary
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
           
 
Constructor Summary
Frustum()
          Constructs a frustum two meters wide centered at the origin.
Frustum(Plane left, Plane right, Plane bottom, Plane top, Plane near, Plane far)
          Create a frustum from six Planes defining the frustum boundaries.
 
Method Summary
 boolean contains(Extent extent)
          Indicates whether a specified Extent is fully within this frustum.
 boolean contains(Vec4 point)
          Indicates whether a specified point is within this frustum.
 boolean equals(Object obj)
           
static Frustum fromPerspective(Angle horizontalFieldOfView, int viewportWidth, int viewportHeight, double near, double far)
          Creates a Frustum from a horizontal field-of-view, viewport aspect ratio and distance to near and far depth clipping planes.
static Frustum fromPerspective(double width, double height, double near, double far)
          Creates a Frustum from three sets of parallel clipping planes (a parallel projectionMatrix).
static Frustum fromPerspectiveVecs(Vec4 vTL, Vec4 vTR, Vec4 vBL, Vec4 vBR, double near, double far)
          Creates a Frustum 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 specified Extent intersects this frustum.
 boolean intersectsSegment(Vec4 pa, Vec4 pb)
          Determines whether a line segment intersects this frustum.
 String toString()
           
 Frustum transformBy(Matrix matrix)
          Returns a copy of this frustum transformed by a specified Matrix.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

allPlanes

protected final Plane[] allPlanes
Holds all six frustum planes in an array in the order left, right, bottom, top, near, far.


bottom

protected final Plane bottom

far

protected final Plane far

left

protected final Plane left

near

protected final Plane near

right

protected final Plane right

top

protected final Plane top
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 six Planes defining the frustum boundaries.

None of the arguments may be null.

Parameters:
near - the near plane
far - the far plane
left - the left plane
right - the right plane
top - the top plane
bottom - the bottom plane
Throws:
IllegalArgumentException - if any argument is null.
Method Detail

contains

public final boolean contains(Extent extent)
Indicates whether a specified Extent is fully within this frustum.

Parameters:
extent - the Extent to test.
Returns:
true if the extent is fully within this frustum, otherwise false.
Throws:
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:
IllegalArgumentException - if the point is null.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

fromPerspective

public static Frustum fromPerspective(Angle horizontalFieldOfView,
                                      int viewportWidth,
                                      int viewportHeight,
                                      double near,
                                      double far)
Creates a Frustum 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 pixels
viewportHeight - the height of the viewport in screen pixels
near - distance to the near depth clipping plane
far - distance to far depth clipping plane
Returns:
Frustum configured from the specified perspective parameters.
Throws:
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 a Frustum 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 plane
far - distance to far depth clipping plane
width - horizontal dimension of the near clipping plane
height - vertical dimension of the near clipping plane
Returns:
a Frustum configured with the specified perspective parameters.
Throws:
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 a Frustum 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 frustum
vTR - vector defining the top-right of the frustum
vBL - vector defining the bottom-left of the frustum
vBR - vector defining the bottom-right of the frustum
near - distance to the near plane
far - distance to far plane
Returns:
Frustum that was created
Throws:
IllegalArgumentException - if any of the vectors are null, if either near or far are negative, or near is greater than or equal to far

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:
IllegalArgumentException - if the projection matrix is null.

getAllPlanes

public Plane[] getAllPlanes()
Returns all the planes.

Returns:
an array of the frustum planes, in the order left, right, bottom, top, near, far.

getBottom

public final Plane getBottom()
Returns the bottom plane.

Returns:
the bottom plane.

getCorners

public Frustum.Corners getCorners()
Returns the eight corners of this frustum.

Returns:
the eight frustum corners.

getFar

public final Plane getFar()
Returns the far plane.

Returns:
the left plane.

getLeft

public final Plane getLeft()
Returns the left plane.

Returns:
the left plane.

getNear

public final Plane getNear()
Returns the near plane.

Returns:
the left plane.

getRight

public final Plane getRight()
Returns the right plane.

Returns:
the right plane.

getTop

public final Plane getTop()
Returns the top plane.

Returns:
the top plane.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

intersects

public boolean intersects(Extent extent)
Indicates whether a specified Extent intersects this frustum.

Parameters:
extent - the Extent to test.
Returns:
true if the extent intersects this frustum, otherwise false.
Throws:
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:
IllegalArgumentException - if either point is null.

toString

public String toString()
Overrides:
toString in class Object

transformBy

public Frustum transformBy(Matrix matrix)
Returns a copy of this frustum transformed by a specified Matrix.

Parameters:
matrix - the Matrix to apply to this frustum.
Returns:
a new frustum transformed by the specified matrix.
Throws:
IllegalArgumentException - if the matrix is null.

NASA World Wind