com.jme.bounding
Class BoundingBox

java.lang.Object
  extended bycom.jme.scene.Spatial
      extended bycom.jme.scene.Geometry
          extended bycom.jme.scene.TriMesh
              extended bycom.jme.scene.shape.Box
                  extended bycom.jme.bounding.BoundingBox
All Implemented Interfaces:
BoundingVolume, java.io.Serializable

public class BoundingBox
extends Box
implements BoundingVolume

BoundingBox defines an axis-aligned cube that defines a container for a group of vertices of a particular piece of geometry. This box defines a center and extents from that center along the x, y and z axis.

A typical usage is to allow the class define the center and radius by calling either containAABB or averagePoints. A call to computeFramePoint in turn calls containAABB.

Version:
$Id: BoundingBox.java,v 1.24 2004/12/06 19:04:10 mojomonkey Exp $
Author:
Joshua Slack
See Also:
Serialized Form

Field Summary
 int[] checkPlanes
          These define the array of planes that are check during view culling.
 
Fields inherited from class com.jme.scene.shape.Box
AXIS_X, AXIS_Y, AXIS_Z, center, xExtent, yExtent, zExtent
 
Fields inherited from class com.jme.scene.TriMesh
indices, triangleQuantity
 
Fields inherited from class com.jme.scene.Geometry
bound, color, colorBuf, normal, normBuf, texBuf, texture, vertBuf, vertex, vertQuantity
 
Fields inherited from class com.jme.scene.Spatial
currentStates, defaultStateList, forceCull, forceView, frustrumIntersects, geometricalControllers, lightCombineMode, localRotation, localScale, localTranslation, name, parent, queueDistance, renderQueueMode, renderStateList, textureCombineMode, worldBound, worldRotation, worldScale, worldTranslation, zOrder
 
Constructor Summary
BoundingBox()
          Default contstructor instantiates a new BoundingBox object.
BoundingBox(java.lang.String name)
          Contstructor instantiates a new BoundingBox object with given specs.
BoundingBox(java.lang.String name, Vector3f center, float xExtent, float yExtent, float zExtent)
          Contstructor instantiates a new BoundingBox object with given specs.
BoundingBox(Vector3f center, float xExtent, float yExtent, float zExtent)
          Contstructor instantiates a new BoundingBox object with given specs.
 
Method Summary
 java.lang.Object clone(BoundingVolume store)
          clone creates a new BoundingBox object containing the same data as this one.
 void computeFromPoints(Vector3f[] points)
          computeFromPoints creates a new Bounding Box from a given set of points.
 void containAABB(Vector3f[] points)
          containAABB creates a minimum-volume axis-aligned bounding box of the points, then selects the smallest enclosing sphere of the box with the sphere centered at the boxes center.
 float distanceTo(Vector3f point)
          Find the distance from the center of this Bounding Volume to the given point.
 Vector3f getCenter(Vector3f store)
          Stores the current center of this BoundingBox into the store vector.
 int getCheckPlane(int index)
          getCheckPlane returns a specific check plane.
 Vector3f getOrigCenter()
          Returns the original, unrotated center of the bounding box.
 Vector3f getOrigExtent()
          Gets the original, unrotated extent of the box.
 void initCheckPlanes()
          Not to be called by users.
 boolean intersects(BoundingVolume bv)
          intersects determines if this Bounding Box intersects with another given bounding volume.
 boolean intersects(Ray ray)
          determines if this bounding box intersects with a given ray object.
 boolean intersectsBoundingBox(BoundingBox bb)
          determines if this bounding box intersects a given bounding box.
 boolean intersectsOBB2(OBB2 obb)
          determines if this bounding box intersects with a given OBB2 bounding.
 boolean intersectsOrientedBoundingBox(OrientedBoundingBox obb)
          determines if this bounding box intersects with a given oriented bounding box.
 boolean intersectsSphere(BoundingSphere bs)
          determines if this bounding box intersects a given bounding sphere.
 BoundingVolume merge(BoundingVolume volume)
          merge combines this sphere with a second bounding sphere.
 BoundingVolume mergeLocal(BoundingVolume volume)
          mergeLocal combines this sphere with a second bounding sphere locally.
 void recomputeMesh()
          recomputeMesh regenerates the BoundingBox based on new model information.
 void setCheckPlane(int index, int value)
          setCheckPlane indentifies the value of one of the spheres checked planes.
 void setOrigCenter(Vector3f origCenter)
          Sets the bounding box's original center.
 void setOrigExtent(Vector3f origExtent)
          Sets the box's original extent.
 java.lang.String toString()
          toString returns the string representation of this object.
 BoundingVolume transform(Quaternion rotate, Vector3f translate, Vector3f scale)
          transform modifies the center of the box to reflect the change made via a rotation, translation and scale.
 BoundingVolume transform(Quaternion rotate, Vector3f translate, Vector3f scale, BoundingVolume store)
          transform modifies the center of the box to reflect the change made via a rotation, translation and scale.
 int whichSide(Plane plane)
          whichSide takes a plane (typically provided by a view frustum) to determine which side this bound is on.
 
Methods inherited from class com.jme.scene.shape.Box
clone, computeVertices, getCenter, setCenter, setData, setData
 
Methods inherited from class com.jme.scene.TriMesh
clearBuffers, draw, drawBounds, findCollisions, findTriangleCollision, findTrianglePick, findWorldRotMat, getIndexAsBuffer, getIndices, getMeshAsTriangles, getTriangle, getTriangle, getTriangleQuantity, hasCollision, hasTriangleCollision, putClone, reconstruct, setIndexBuffer, setIndices, updateCollisionTree, updateIndexBuffer
 
Methods inherited from class com.jme.scene.Geometry
applyRenderState, applyStates, copyTextureCoords, findPick, getAllTextures, getCloneID, getColorAsFloatBuffer, getColors, getModelBound, getNormalAsFloatBuffer, getNormals, getNumberOfUnits, getTextureAsFloatBuffer, getTextureAsFloatBuffer, getTextures, getTextures, getVBOColorID, getVBONormalID, getVBOTextureID, getVBOVertexID, getVerticeAsFloatBuffer, getVertices, getVertQuantity, isVBOColorEnabled, isVBONormalEnabled, isVBOTextureEnabled, isVBOVertexEnabled, randomVertice, reconstruct, setAllTextures, setColor, setColors, setFloatBuffer, setForceView, setModelBound, setNormal, setNormalBuffer, setNormals, setRandomColors, setSolidColor, setTexture, setTexture, setTextureBuffer, setTextureCoord, setTextures, setTextures, setVBOColorEnabled, setVBOColorID, setVBONormalEnabled, setVBONormalID, setVBOTextureEnabled, setVBOTextureID, setVBOVertexEnabled, setVBOVertexID, setVertex, setVertexBuffer, setVertices, updateColorBuffer, updateColorBuffer, updateModelBound, updateNormalBuffer, updateNormalBuffer, updateTextureBuffer, updateTextureBuffer, updateTextureBuffer, updateVertexBuffer, updateVertexBuffer, updateWorldBound
 
Methods inherited from class com.jme.scene.Spatial
addController, applyDefaultStates, calculateCollisions, calculatePick, clearCurrentState, clearCurrentStates, clearRenderState, getController, getControllers, getCurrentState, getLastFrustumIntersection, getLightCombineMode, getLocalRotation, getLocalScale, getLocalTranslation, getName, getParent, getRenderQueueMode, getRenderStateList, getTextureCombineMode, getWorldBound, getWorldRotation, getWorldScale, getWorldTranslation, getZOrder, isForceCulled, isForceView, onDraw, onDrawBounds, propagateBoundToRoot, propagateStatesFromRoot, removeController, removeFromParent, setForceCull, setLightCombineMode, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalTranslation, setName, setParent, setRenderQueueMode, setRenderState, setTextureCombineMode, setWorldBound, setZOrder, updateGeometricState, updateRenderState, updateRenderState, updateWorldData
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

checkPlanes

public int[] checkPlanes
These define the array of planes that are check during view culling.

Constructor Detail

BoundingBox

public BoundingBox()
Default contstructor instantiates a new BoundingBox object.


BoundingBox

public BoundingBox(java.lang.String name)
Contstructor instantiates a new BoundingBox object with given specs.


BoundingBox

public BoundingBox(Vector3f center,
                   float xExtent,
                   float yExtent,
                   float zExtent)
Contstructor instantiates a new BoundingBox object with given specs.


BoundingBox

public BoundingBox(java.lang.String name,
                   Vector3f center,
                   float xExtent,
                   float yExtent,
                   float zExtent)
Contstructor instantiates a new BoundingBox object with given specs.

Method Detail

initCheckPlanes

public void initCheckPlanes()
Not to be called by users. This function initializes the check planes for the AABB.

Specified by:
initCheckPlanes in interface BoundingVolume

computeFromPoints

public void computeFromPoints(Vector3f[] points)
computeFromPoints creates a new Bounding Box from a given set of points. It uses the containAABB method as default.

Specified by:
computeFromPoints in interface BoundingVolume
Parameters:
points - the points to contain.

containAABB

public void containAABB(Vector3f[] points)
containAABB creates a minimum-volume axis-aligned bounding box of the points, then selects the smallest enclosing sphere of the box with the sphere centered at the boxes center.

Parameters:
points - the list of points.

transform

public BoundingVolume transform(Quaternion rotate,
                                Vector3f translate,
                                Vector3f scale)
transform modifies the center of the box to reflect the change made via a rotation, translation and scale.

Specified by:
transform in interface BoundingVolume
Parameters:
rotate - the rotation change.
translate - the translation change.
scale - the size change.
Returns:
the new bounding volume.

transform

public BoundingVolume transform(Quaternion rotate,
                                Vector3f translate,
                                Vector3f scale,
                                BoundingVolume store)
transform modifies the center of the box to reflect the change made via a rotation, translation and scale.

Specified by:
transform in interface BoundingVolume
Parameters:
rotate - the rotation change.
translate - the translation change.
scale - the size change.
store - box to store result in
Returns:
the new bounding volume.

whichSide

public int whichSide(Plane plane)
whichSide takes a plane (typically provided by a view frustum) to determine which side this bound is on.

Specified by:
whichSide in interface BoundingVolume
Parameters:
plane - the plane to check against.
Returns:
the side on which this bounding volume lies.
See Also:
Point

merge

public BoundingVolume merge(BoundingVolume volume)
merge combines this sphere with a second bounding sphere. This new sphere contains both bounding spheres and is returned.

Specified by:
merge in interface BoundingVolume
Parameters:
volume - the sphere to combine with this sphere.
Returns:
the new sphere

mergeLocal

public BoundingVolume mergeLocal(BoundingVolume volume)
mergeLocal combines this sphere with a second bounding sphere locally. Altering this sphere to contain both the original and the additional sphere volumes;

Specified by:
mergeLocal in interface BoundingVolume
Parameters:
volume - the sphere to combine with this sphere.
Returns:
this

clone

public java.lang.Object clone(BoundingVolume store)
clone creates a new BoundingBox object containing the same data as this one.

Specified by:
clone in interface BoundingVolume
Parameters:
store - where to store the cloned information. if null or wrong class, a new store is created.
Returns:
the new BoundingBox

getCheckPlane

public int getCheckPlane(int index)
getCheckPlane returns a specific check plane. This plane identitifies the previous value of the visibility check.

Specified by:
getCheckPlane in interface BoundingVolume
Parameters:
index -
Returns:

setCheckPlane

public void setCheckPlane(int index,
                          int value)
setCheckPlane indentifies the value of one of the spheres checked planes. That is what plane of the view frustum has been checked for intersection.

Specified by:
setCheckPlane in interface BoundingVolume
Parameters:
index -
value -

recomputeMesh

public void recomputeMesh()
recomputeMesh regenerates the BoundingBox based on new model information.

Specified by:
recomputeMesh in interface BoundingVolume

distanceTo

public float distanceTo(Vector3f point)
Find the distance from the center of this Bounding Volume to the given point.

Specified by:
distanceTo in interface BoundingVolume
Parameters:
point - The point to get the distance to
Returns:
distance

getCenter

public Vector3f getCenter(Vector3f store)
Stores the current center of this BoundingBox into the store vector.

Specified by:
getCenter in interface BoundingVolume
Parameters:
store - The vector to store the center into.
Returns:
The store vector, after setting it's contents to the center

toString

public java.lang.String toString()
toString returns the string representation of this object. The form is: "Radius: RRR.SSSS Center: ".

Overrides:
toString in class Spatial
Returns:
the string representation of this.

getOrigCenter

public Vector3f getOrigCenter()
Returns the original, unrotated center of the bounding box.

Returns:
The box's original center.

setOrigCenter

public void setOrigCenter(Vector3f origCenter)
Sets the bounding box's original center. In most cases, users will simply want to use computefrompoints

Parameters:
origCenter - New original center
See Also:
computeFromPoints(com.jme.math.Vector3f[])

getOrigExtent

public Vector3f getOrigExtent()
Gets the original, unrotated extent of the box.

Returns:
The box's original extent.

setOrigExtent

public void setOrigExtent(Vector3f origExtent)
Sets the box's original extent. In most cases, users will simply want to use computefrompoints.

Parameters:
origExtent - The new extent.
See Also:
computeFromPoints(com.jme.math.Vector3f[])

intersects

public boolean intersects(BoundingVolume bv)
intersects determines if this Bounding Box intersects with another given bounding volume. If so, true is returned, otherwise, false is returned.

Specified by:
intersects in interface BoundingVolume
Parameters:
bv - the second volume to test against.
Returns:
true if this volume intersects the given volume.
See Also:
BoundingVolume.intersects(com.jme.bounding.BoundingVolume)

intersectsSphere

public boolean intersectsSphere(BoundingSphere bs)
determines if this bounding box intersects a given bounding sphere.

Specified by:
intersectsSphere in interface BoundingVolume
Parameters:
bs - the bounding sphere to test against.
Returns:
true if this volume intersects the given bounding sphere.
See Also:
BoundingVolume.intersectsSphere(com.jme.bounding.BoundingSphere)

intersectsBoundingBox

public boolean intersectsBoundingBox(BoundingBox bb)
determines if this bounding box intersects a given bounding box. If the two boxes intersect in any way, true is returned. Otherwise, false is returned.

Specified by:
intersectsBoundingBox in interface BoundingVolume
Parameters:
bb - the bounding box to test against.
Returns:
true if this volume intersects the given bounding box.
See Also:
BoundingVolume.intersectsBoundingBox(com.jme.bounding.BoundingBox)

intersectsOrientedBoundingBox

public boolean intersectsOrientedBoundingBox(OrientedBoundingBox obb)
determines if this bounding box intersects with a given oriented bounding box. NOTE: Not currently supported, false always returned.

Specified by:
intersectsOrientedBoundingBox in interface BoundingVolume
Parameters:
obb - the bounding box to test against.
Returns:
true if this volume intersects the given oriented bounding box.
See Also:
BoundingVolume.intersectsOrientedBoundingBox(com.jme.bounding.OrientedBoundingBox)

intersectsOBB2

public boolean intersectsOBB2(OBB2 obb)
determines if this bounding box intersects with a given OBB2 bounding.

Specified by:
intersectsOBB2 in interface BoundingVolume
Parameters:
obb - the bounding box to test against.
Returns:
true if this volume intersects the given oriented bounding box.
See Also:
BoundingVolume.intersectsOBB2(com.jme.bounding.OBB2)

intersects

public boolean intersects(Ray ray)
determines if this bounding box intersects with a given ray object. If an intersection has occurred, true is returned, otherwise false is returned.

Specified by:
intersects in interface BoundingVolume
Parameters:
ray - the ray to test.
Returns:
true if this volume is intersected by a given ray.
See Also:
BoundingVolume.intersects(com.jme.math.Ray)