com.threerings.math
Class Frustum

java.lang.Object
  extended by com.threerings.math.Frustum

public class Frustum
extends Object

A pyramidal frustum.


Nested Class Summary
static class Frustum.IntersectionType
          Intersection types indicating that the frustum does not intersect, intersects, or fully contains, respectively, the parameter.
 
Field Summary
protected  Box _bounds
          The frustum's bounding box (as derived from the vertices).
protected  Plane[] _planes
          The planes of the frustum (as derived from the vertices).
protected static Vector3f _vertex
          A working vertex.
protected  Vector3f[] _vertices
          The vertices of the frustum.
 
Constructor Summary
Frustum()
          Creates an empty (invalid) frustum.
 
Method Summary
 Box getBounds()
          Returns a reference to the bounds of this frustum.
 Box getBoundsUnderRotation(Matrix3f matrix, Box result)
          Computes the bounds of the frustum under the supplied rotation and places the results in the box provided.
 float getDistance(Vector3f point)
          Determines the maximum signed distance of the point from the planes of the frustum.
 Frustum.IntersectionType getIntersectionType(Box box)
          Checks whether the frustum intersects the specified box.
 Vector3f[] getVertices()
          Returns a reference to the frustum's array of vertices.
 Frustum setToFrustum(float left, float right, float bottom, float top, float near, float far)
          Sets this frustum to one pointing in the Z- direction with the specified parameters determining its size and shape (see the OpenGL documentation for glFrustum).
 Frustum setToOrtho(float left, float right, float bottom, float top, float near, float far)
          Sets this frustum to an orthographic one pointing in the Z- direction with the specified parameters determining its size (see the OpenGL documentation for glOrtho).
 Frustum setToPerspective(float fovy, float aspect, float znear, float zfar)
          Sets this frustum to one pointing in the Z- direction with the specified parameters determining its size and shape (see the OpenGL documentation for gluPerspective).
 Frustum setToProjection(float left, float right, float bottom, float top, float near, float far, Vector3f nearFarNormal, boolean ortho, boolean mirrored)
          Sets this frustum to a perspective or orthographic projection with the specified parameters determining its size and shape.
 Frustum transform(Transform3D transform)
          Transforms this frustum by the specified transformation.
 Frustum transform(Transform3D transform, Frustum result)
          Transforms this frustum by the specified transformation, placing the result in the object provided.
 Frustum transformLocal(Transform3D transform)
          Transforms this frustum in-place by the specified transformation.
protected  void updateDerivedState()
          Sets the planes and bounding box of the frustum based on its vertices.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_vertices

protected Vector3f[] _vertices
The vertices of the frustum.


_planes

protected Plane[] _planes
The planes of the frustum (as derived from the vertices). The plane normals point out of the frustum.


_bounds

protected Box _bounds
The frustum's bounding box (as derived from the vertices).


_vertex

protected static Vector3f _vertex
A working vertex.

Constructor Detail

Frustum

public Frustum()
Creates an empty (invalid) frustum.

Method Detail

getVertices

public Vector3f[] getVertices()
Returns a reference to the frustum's array of vertices.


getBounds

public Box getBounds()
Returns a reference to the bounds of this frustum.


setToPerspective

public Frustum setToPerspective(float fovy,
                                float aspect,
                                float znear,
                                float zfar)
Sets this frustum to one pointing in the Z- direction with the specified parameters determining its size and shape (see the OpenGL documentation for gluPerspective).

Parameters:
fovy - the vertical field of view, in radians.
aspect - the aspect ratio (width over height).
znear - the distance to the near clip plane.
zfar - the distance to the far clip plane.
Returns:
a reference to this frustum, for chaining.

setToFrustum

public Frustum setToFrustum(float left,
                            float right,
                            float bottom,
                            float top,
                            float near,
                            float far)
Sets this frustum to one pointing in the Z- direction with the specified parameters determining its size and shape (see the OpenGL documentation for glFrustum).

Returns:
a reference to this frustum, for chaining.

setToOrtho

public Frustum setToOrtho(float left,
                          float right,
                          float bottom,
                          float top,
                          float near,
                          float far)
Sets this frustum to an orthographic one pointing in the Z- direction with the specified parameters determining its size (see the OpenGL documentation for glOrtho).

Returns:
a reference to this frustum, for chaining.

setToProjection

public Frustum setToProjection(float left,
                               float right,
                               float bottom,
                               float top,
                               float near,
                               float far,
                               Vector3f nearFarNormal,
                               boolean ortho,
                               boolean mirrored)
Sets this frustum to a perspective or orthographic projection with the specified parameters determining its size and shape.

Returns:
a reference to this frustum, for chaining.

transformLocal

public Frustum transformLocal(Transform3D transform)
Transforms this frustum in-place by the specified transformation.

Returns:
a reference to this frustum, for chaining.

transform

public Frustum transform(Transform3D transform)
Transforms this frustum by the specified transformation.

Returns:
a new frustum containing the result.

transform

public Frustum transform(Transform3D transform,
                         Frustum result)
Transforms this frustum by the specified transformation, placing the result in the object provided.

Returns:
a reference to the result frustum, for chaining.

getDistance

public float getDistance(Vector3f point)
Determines the maximum signed distance of the point from the planes of the frustum. If the distance is less than or equal to zero, the point lies inside the frustum.


getIntersectionType

public Frustum.IntersectionType getIntersectionType(Box box)
Checks whether the frustum intersects the specified box.


getBoundsUnderRotation

public Box getBoundsUnderRotation(Matrix3f matrix,
                                  Box result)
Computes the bounds of the frustum under the supplied rotation and places the results in the box provided.

Returns:
a reference to the result box, for chaining.

updateDerivedState

protected void updateDerivedState()
Sets the planes and bounding box of the frustum based on its vertices.