j3d.org Code

org.j3d.util.frustum
Class ViewFrustum

java.lang.Object
  extended by org.j3d.util.frustum.ViewFrustum

public abstract class ViewFrustum
extends java.lang.Object

A utility for tracking the ViewFrustum planes and determining if a triangle or point is visible.

Because Java3D can have multiple canvases that view a single scenegraph, the view frustum must be a bit more complex than the traditional case. It must take into account that every canvas has its own viewplatform, and they may not be looking at the same thing. That means, for culling, they will need to assemble the union of all the spaces for each canvas.

The frustum is for the previous Java3D frame that has just been rendered.

Version:
$Revision: 1.4 $
Author:
Paul Byrne, Justin Couch

Field Summary
static int CLIPPED
          The geometry has been clipped to the view frustum
static int IN
          The geometry is in the view frustum, either partially or completely
protected  int numCanvases
          The number of different canvases provided
static int OUT
          The geometry is outside the view frustum
 
Constructor Summary
ViewFrustum(int numCanvases)
          Create a new instance that on a given number of canvases that contribute to the total view frustum.
 
Method Summary
 void getBounds(javax.vecmath.Point3d min, javax.vecmath.Point3d max)
          Convenience method to fetch the axis-aligned bounding box that the view frustum encloses.
protected abstract  void getInverseWorldProjection(int id, javax.vecmath.Matrix4d matrix)
          Request from the renderer-specific canvas the inverse projection matrix for the given canvasId.
 int isPointInFrustum(javax.vecmath.Point3d p1)
          Checks if the point is inside the view frustum.
 int isTriangleInFrustum(float p1X, float p1Y, float p1Z, float p2X, float p2Y, float p2Z, float p3X, float p3Y, float p3Z)
          Determines if the triangle defined by the 3 points is visible in the view frustum.
 int isTriangleInFrustum(javax.vecmath.Point3d p1, javax.vecmath.Point3d p2, javax.vecmath.Point3d p3)
          Determines if the triangle defined by the 3 points is visible in the view frustum.
 void manualPlatformMove(javax.vecmath.Matrix4d tx)
          Manually re-orient the view frustum by this given matrix.
 void viewingPlatformMoved()
          This method must be called when the view platform transform group has been updated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IN

public static final int IN
The geometry is in the view frustum, either partially or completely

See Also:
Constant Field Values

OUT

public static final int OUT
The geometry is outside the view frustum

See Also:
Constant Field Values

CLIPPED

public static final int CLIPPED
The geometry has been clipped to the view frustum

See Also:
Constant Field Values

numCanvases

protected final int numCanvases
The number of different canvases provided

Constructor Detail

ViewFrustum

public ViewFrustum(int numCanvases)
Create a new instance that on a given number of canvases that contribute to the total view frustum.

Parameters:
numCanvases - The number of canvases contributing to this frustum
Method Detail

viewingPlatformMoved

public void viewingPlatformMoved()
This method must be called when the view platform transform group has been updated. Until this method is called the frustum will not be valid


manualPlatformMove

public void manualPlatformMove(javax.vecmath.Matrix4d tx)
Manually re-orient the view frustum by this given matrix. This is used for doing predictive work about where the user will be in the next rendered frame. This assumes that you have called the viewingPlatformMoved() method first for this frame.

Parameters:
tx - The transform used to modify the points with

isTriangleInFrustum

public int isTriangleInFrustum(float p1X,
                               float p1Y,
                               float p1Z,
                               float p2X,
                               float p2Y,
                               float p2Z,
                               float p3X,
                               float p3Y,
                               float p3Z)
Determines if the triangle defined by the 3 points is visible in the view frustum.

IN is returned for any triangle which is partially or completely in the view frustum. OUT is returned if the triangle is outside the frustum.

In some cases triangles which are not visible will be reported as IN, however the converse is not true. All triangles which have any part in the frustum will be reported as IN.

Parameters:
p1X - The x component of the first point of the triangle
p1Y - The y component of the first point of the triangle
p1Z - The z component of the first point of the triangle
p2X - The x component of the second point of the triangle
p2Y - The y component of the second point of the triangle
p2Z - The z component of the second point of the triangle
p3X - The x component of the third point of the triangle
p3Y - The y component of the third point of the triangle
p3Z - The z component of the third point of the triangle
Returns:
IN, OUT indicating triangle is visible in the View Frustum

isTriangleInFrustum

public int isTriangleInFrustum(javax.vecmath.Point3d p1,
                               javax.vecmath.Point3d p2,
                               javax.vecmath.Point3d p3)
Determines if the triangle defined by the 3 points is visible in the view frustum.

IN is returned for any triangle which is partially or completely in the view frustum. OUT is returned if the triangle is outside the frustum.

In some cases triangles which are not visible will be reported as IN, however the converse is not true. All triangles which have any part in the frustum will be reported as IN.

Parameters:
p1 - The first point of the triangle
p2 - The first point of the triangle
p3 - The first point of the triangle
Returns:
IN, OUT indicating triangle is visible in the View Frustum

isPointInFrustum

public int isPointInFrustum(javax.vecmath.Point3d p1)
Checks if the point is inside the view frustum.

Returns:
IN, OUT indicating point is inside or outside the View Frustum

getBounds

public void getBounds(javax.vecmath.Point3d min,
                      javax.vecmath.Point3d max)
Convenience method to fetch the axis-aligned bounding box that the view frustum encloses. The two structures passed in are filled with the appropriate information.

Parameters:
min - The min corner vertex (+X, +Y and +Z values)
max - The max corner vertex (+X, +Y and +Z values)

getInverseWorldProjection

protected abstract void getInverseWorldProjection(int id,
                                                  javax.vecmath.Matrix4d matrix)
Request from the renderer-specific canvas the inverse projection matrix for the given canvasId.

Parameters:
id - The ID of the canvas
matrix - The matrix to copy the data into

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org