com.jme.bounding
Class BoundingBox

java.lang.Object
  extended by com.jme.bounding.BoundingVolume
      extended by com.jme.bounding.BoundingBox
All Implemented Interfaces:
Savable, java.io.Serializable

public class BoundingBox
extends 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 4131 2009-03-19 20:15:28Z blaine.dev $
Author:
Joshua Slack
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jme.bounding.BoundingVolume
BoundingVolume.Type
 
Field Summary
 float xExtent
           
 float yExtent
           
 float zExtent
           
 
Fields inherited from class com.jme.bounding.BoundingVolume
_compVect1, _compVect2, _compVect3, center, checkPlane
 
Constructor Summary
BoundingBox()
          Default constructor instantiates a new BoundingBox object.
BoundingBox(Vector3f c, float x, float y, float z)
          Contstructor instantiates a new BoundingBox object with given specs.
 
Method Summary
 BoundingVolume clone(BoundingVolume store)
          clone creates a new BoundingBox object containing the same data as this one.
 void computeFromPoints(java.nio.FloatBuffer points)
          computeFromPoints creates a new Bounding Box from a given set of points.
 void computeFromTris(int[] indices, TriMesh mesh, int start, int end)
           
 void computeFromTris(Triangle[] tris, int start, int end)
          computeFromTris creates a new Bounding Box from a given set of triangles.
 void containAABB(java.nio.FloatBuffer 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.
 boolean contains(Vector3f point)
          determines if a given point is contained within this bounding volume.
 float distanceToEdge(Vector3f point)
          Find the distance from the nearest edge of this Bounding Volume to the given point.
 Vector3f getExtent(Vector3f store)
          Query extent.
 BoundingVolume.Type getType()
          getType returns the type of bounding volume this is.
 float getVolume()
           
 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 intersectsCapsule(BoundingCapsule bc)
          determines if this bounding box intersects with a given bounding capsule.
 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.
 IntersectionRecord intersectsWhere(Ray ray)
          determines if a ray intersects this bounding volume and if so, where.
 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 read(JMEImporter e)
           
 java.lang.String toString()
          toString returns the string representation of this object.
 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.
 Plane.Side whichSide(Plane plane)
          whichSide takes a plane (typically provided by a view frustum) to determine which side this bound is on.
 void write(JMEExporter e)
           
 
Methods inherited from class com.jme.bounding.BoundingVolume
distanceSquaredTo, distanceTo, getCenter, getCenter, getCheckPlane, getClassTag, setCenter, setCheckPlane, transform
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

xExtent

public float xExtent

yExtent

public float yExtent

zExtent

public float zExtent
Constructor Detail

BoundingBox

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


BoundingBox

public BoundingBox(Vector3f c,
                   float x,
                   float y,
                   float z)
Contstructor instantiates a new BoundingBox object with given specs.

Method Detail

getType

public BoundingVolume.Type getType()
Description copied from class: BoundingVolume
getType returns the type of bounding volume this is.

Specified by:
getType in class BoundingVolume

computeFromPoints

public void computeFromPoints(java.nio.FloatBuffer points)
computeFromPoints creates a new Bounding Box from a given set of points. It uses the containAABB method as default.

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

computeFromTris

public void computeFromTris(Triangle[] tris,
                            int start,
                            int end)
computeFromTris creates a new Bounding Box from a given set of triangles. It is used in OBBTree calculations.

Specified by:
computeFromTris in class BoundingVolume
Parameters:
tris -
start -
end -

computeFromTris

public void computeFromTris(int[] indices,
                            TriMesh mesh,
                            int start,
                            int end)
Specified by:
computeFromTris in class BoundingVolume

containAABB

public void containAABB(java.nio.FloatBuffer 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,
                                BoundingVolume store)
transform modifies the center of the box to reflect the change made via a rotation, translation and scale.

Specified by:
transform in class 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 Plane.Side 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 class BoundingVolume
Parameters:
plane - the plane to check against.
Returns:
the side on which this bounding volume lies.

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 class 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 class BoundingVolume
Parameters:
volume - the sphere to combine with this sphere.
Returns:
this

clone

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

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

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 java.lang.Object
Returns:
the string representation of this.

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 class 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 class 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 class 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.

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

intersectsCapsule

public boolean intersectsCapsule(BoundingCapsule bc)
determines if this bounding box intersects with a given bounding capsule.

Specified by:
intersectsCapsule in class BoundingVolume
Parameters:
bc - the bounding capsule to test against.
Returns:
true if this volume instersects the given bounding capsule.
See Also:
BoundingVolume.intersectsCapsule(BoundingCapsule)

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 class 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)

intersectsWhere

public IntersectionRecord intersectsWhere(Ray ray)
Description copied from class: BoundingVolume
determines if a ray intersects this bounding volume and if so, where.

Specified by:
intersectsWhere in class BoundingVolume
Parameters:
ray - the ray to test.
Returns:
an IntersectionRecord containing information about any intersections made by the given Ray with this bounding
See Also:
BoundingVolume.intersectsWhere(com.jme.math.Ray)

contains

public boolean contains(Vector3f point)
Description copied from class: BoundingVolume
determines if a given point is contained within this bounding volume.

Specified by:
contains in class BoundingVolume
Parameters:
point - the point to check
Returns:
true if the point lies within this bounding volume.

distanceToEdge

public float distanceToEdge(Vector3f point)
Description copied from class: BoundingVolume
Find the distance from the nearest edge of this Bounding Volume to the given point.

Specified by:
distanceToEdge in class BoundingVolume
Parameters:
point - The point to get the distance to
Returns:
distance

getExtent

public Vector3f getExtent(Vector3f store)
Query extent.

Parameters:
store - where extent gets stored - null to return a new vector
Returns:
store / new vector

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Overrides:
write in class BoundingVolume
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Overrides:
read in class BoundingVolume
Throws:
java.io.IOException

getVolume

public float getVolume()
Specified by:
getVolume in class BoundingVolume