com.jme.bounding
Class BoundingSphere

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

public class BoundingSphere
extends Sphere
implements BoundingVolume

BoundingSphere defines a sphere that defines a container for a group of vertices of a particular piece of geometry. This sphere defines a radius and a center.

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: BoundingSphere.java,v 1.24 2005/02/24 06:58:51 renanse Exp $
Author:
Mark Powell
See Also:
Serialized Form

Field Summary
 int[] checkPlanes
           
 
Fields inherited from class com.jme.scene.shape.Sphere
center, radius
 
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
BoundingSphere()
          Default contstructor instantiates a new BoundingSphere object.
BoundingSphere(float radius, Vector3f center)
          Constructor instantiates a new BoundingSphere object.
BoundingSphere(java.lang.String name, float radius, Vector3f center)
          Constructor instantiates a new BoundingSphere object.
 
Method Summary
 void averagePoints(Vector3f[] points)
          averagePoints selects the sphere center to be the average of the points and the sphere radius to be the smallest value to enclose all points.
 void calcWelzl(Vector3f[] points)
          Calculates a minimum bounding sphere for the set of points.
 java.lang.Object clone(BoundingVolume store)
          clone creates a new BoundingSphere object containing the same data as this one.
 void computeFromPoints(Vector3f[] points)
          computeFromPoints creates a new Bounding Sphere from a given set of points.
 float distanceTo(Vector3f point)
          Find the distance from the center of this Bounding Volume to the given point.
 Vector3f getCenter()
          getCenter returns the center of the bounding sphere.
 Vector3f getCenter(Vector3f store)
          Stores the current center of this BoundingSphere into the store vector.
 int getCheckPlane(int index)
          getCheckPlane returns a specific check plane.
 float getRadius()
          getRadius returns the radius of the bounding sphere.
 void initCheckPlanes()
          initCheckPlanes resets the checkplanes to their standard order.
 boolean intersects(BoundingVolume bv)
          determines if this bounding volume and a second given volume are intersecting.
 boolean intersects(Ray ray)
          determines if a ray intersects this bounding volume.
 boolean intersectsBoundingBox(BoundingBox bb)
          determines if this bounding volume and a given bounding box are intersecting.
 boolean intersectsOBB2(OBB2 obb)
          determines if this bounding volume and a given oriented bounding box are intersecting.
 boolean intersectsOrientedBoundingBox(OrientedBoundingBox obb)
          determines if this bounding volume and a given oriented bounding box are intersecting.
 boolean intersectsSphere(BoundingSphere bs)
          determines if this bounding volume and a given bounding sphere are intersecting.
 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 BoundingSphere based on new model information.
 void setCenter(Vector3f center)
          setCenter sets the center of the bounding sphere.
 void setCheckPlane(int index, int value)
          setCheckPlane indentifies the value of one of the spheres checked planes.
 void setRadius(float radius)
          setRadius sets the radius of this bounding sphere.
 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 sphere 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 sphere 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.Sphere
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

checkPlanes

public int[] checkPlanes
Constructor Detail

BoundingSphere

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


BoundingSphere

public BoundingSphere(float radius,
                      Vector3f center)
Constructor instantiates a new BoundingSphere object.

Parameters:
radius - the radius of the sphere.
center - the center of the sphere.

BoundingSphere

public BoundingSphere(java.lang.String name,
                      float radius,
                      Vector3f center)
Constructor instantiates a new BoundingSphere object.

Parameters:
radius - the radius of the sphere.
center - the center of the sphere.
Method Detail

initCheckPlanes

public void initCheckPlanes()
Description copied from interface: BoundingVolume
initCheckPlanes resets the checkplanes to their standard order.

Specified by:
initCheckPlanes in interface BoundingVolume

getRadius

public float getRadius()
getRadius returns the radius of the bounding sphere.

Returns:
the radius of the bounding sphere.

getCenter

public Vector3f getCenter()
getCenter returns the center of the bounding sphere.

Overrides:
getCenter in class Sphere
Returns:
the center of the bounding sphere.

setRadius

public void setRadius(float radius)
setRadius sets the radius of this bounding sphere.

Parameters:
radius - the new radius of the bounding sphere.

setCenter

public void setCenter(Vector3f center)
setCenter sets the center of the bounding sphere.

Overrides:
setCenter in class Sphere
Parameters:
center - the new center of the bounding sphere.
See Also:
Sphere.setData(com.jme.math.Vector3f, int, int, float, boolean)

computeFromPoints

public void computeFromPoints(Vector3f[] points)
computeFromPoints creates a new Bounding Sphere 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.

calcWelzl

public void calcWelzl(Vector3f[] points)
Calculates a minimum bounding sphere for the set of points. The algorithm was originally found at http://www.flipcode.com/cgi-bin/msg.cgi?showThread=COTD-SmallestEnclosingSpheres&forum=cotd&id=-1 in C++ and translated to java by Cep21

Parameters:
points - The points to calculate the minimum bounds from.

averagePoints

public void averagePoints(Vector3f[] points)
averagePoints selects the sphere center to be the average of the points and the sphere radius to be the smallest value to enclose all points.

Parameters:
points - the list of points to contain.

transform

public BoundingVolume transform(Quaternion rotate,
                                Vector3f translate,
                                Vector3f scale)
transform modifies the center of the sphere 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:
BoundingVolume

transform

public BoundingVolume transform(Quaternion rotate,
                                Vector3f translate,
                                Vector3f scale,
                                BoundingVolume store)
transform modifies the center of the sphere 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 - sphere to store result in
Returns:
BoundingVolume

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:
side
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 BoundingSphere 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 BoundingSphere

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

intersects

public boolean intersects(BoundingVolume bv)
Description copied from interface: BoundingVolume
determines if this bounding volume and a second given volume are intersecting. Intersecting being: one volume contains another, one volume overlaps another or one volume touches another.

Specified by:
intersects in interface BoundingVolume
Parameters:
bv - the second volume to test against.
Returns:
true if this volume intersects the given volume.

intersectsSphere

public boolean intersectsSphere(BoundingSphere bs)
Description copied from interface: BoundingVolume
determines if this bounding volume and a given bounding sphere are intersecting.

Specified by:
intersectsSphere in interface BoundingVolume
Parameters:
bs - the bounding sphere to test against.
Returns:
true if this volume intersects the given bounding sphere.

intersectsBoundingBox

public boolean intersectsBoundingBox(BoundingBox bb)
Description copied from interface: BoundingVolume
determines if this bounding volume and a given bounding box are intersecting.

Specified by:
intersectsBoundingBox in interface BoundingVolume
Parameters:
bb - the bounding box to test against.
Returns:
true if this volume intersects the given bounding box.

intersectsOrientedBoundingBox

public boolean intersectsOrientedBoundingBox(OrientedBoundingBox obb)
Description copied from interface: BoundingVolume
determines if this bounding volume and a given oriented bounding box are intersecting.

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.

intersectsOBB2

public boolean intersectsOBB2(OBB2 obb)
Description copied from interface: BoundingVolume
determines if this bounding volume and a given oriented bounding box are intersecting.

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.

intersects

public boolean intersects(Ray ray)
Description copied from interface: BoundingVolume
determines if a ray intersects this bounding volume.

Specified by:
intersects in interface BoundingVolume
Parameters:
ray - the ray to test.
Returns:
true if this volume is intersected by a given ray.