Package com.jme3.bounding
Class BoundingSphere
java.lang.Object
com.jme3.bounding.BoundingVolume
com.jme3.bounding.BoundingSphere
- All Implemented Interfaces:
Collidable
,Savable
,Cloneable
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
.-
Nested Class Summary
Nested classes/interfaces inherited from class com.jme3.bounding.BoundingVolume
BoundingVolume.Type
-
Field Summary
Fields inherited from class com.jme3.bounding.BoundingVolume
center, checkPlane
-
Constructor Summary
ConstructorDescriptionDefault constructor instantiates a newBoundingSphere
object.BoundingSphere
(float r, Vector3f c) Constructor instantiates a newBoundingSphere
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
(FloatBuffer points) Calculates a minimum bounding sphere for the set of points.clone
(BoundingVolume store) clone
creates a new BoundingSphere object containing the same data as this one.int
collideWith
(Collidable other) int
collideWith
(Collidable other, CollisionResults results) Check collision with another Collidable.void
computeFromPoints
(FloatBuffer points) computeFromPoints
creates a new Bounding Sphere from a given set of points.void
computeFromTris
(Triangle[] tris, int start, int end) computeFromTris
creates a new Bounding Box from a given set of triangles.boolean
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.boolean
Tests for exact equality with the argument, distinguishing -0 from 0.float
getRadius
returns the radius of the bounding sphere.getType()
getType returns the type of bounding volume this is.float
int
hashCode()
Returns a hash code.boolean
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
intersects
(Vector3f point) Determines if a given point intersects (touches or is inside) this bounding volume.boolean
determines if this bounding volume and a given bounding box are intersecting.boolean
determines if this bounding volume and a given bounding sphere are intersecting.boolean
isSimilar
(BoundingSphere sphere, float epsilon) Tests for approximate equality with the specified bounding sphere, using the specified tolerance.merge
(BoundingVolume volume) merge
combines this sphere with a second bounding sphere.mergeLocal
(BoundingVolume volume) mergeLocal
combines this sphere with a second bounding sphere locally.void
read
(JmeImporter importer) void
setRadius
(float radius) setRadius
sets the radius of this bounding sphere.toString()
toString
returns the string representation of this object.transform
(Matrix4f trans, BoundingVolume store) transform
(Transform trans, BoundingVolume store) transform
modifies the center of the sphere to reflect the change made via a rotation, translation and scale.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.jme3.bounding.BoundingVolume
clone, distanceSquaredTo, distanceTo, getCenter, getCenter, getCheckPlane, setCenter, setCenter, setCheckPlane, transform
-
Constructor Details
-
BoundingSphere
public BoundingSphere()Default constructor instantiates a newBoundingSphere
object. -
BoundingSphere
Constructor instantiates a newBoundingSphere
object.- Parameters:
r
- the radius of the sphere.c
- the center of the sphere.
-
-
Method Details
-
getType
Description copied from class:BoundingVolume
getType returns the type of bounding volume this is.- Specified by:
getType
in classBoundingVolume
- Returns:
- an enum value
-
getRadius
public float getRadius()getRadius
returns the radius of the bounding sphere.- Returns:
- the radius 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.
-
computeFromPoints
computeFromPoints
creates a new Bounding Sphere from a given set of points. It uses thecalcWelzl
method as default.- Specified by:
computeFromPoints
in classBoundingVolume
- Parameters:
points
- the points to contain.
-
computeFromTris
computeFromTris
creates a new Bounding Box from a given set of triangles. It is used in OBBTree calculations.- Parameters:
tris
- triangle data (unaffected)start
- the index of the first triangle to be usedend
- the index of the triangle after the last one to be used
-
calcWelzl
Calculates a minimum bounding sphere for the set of points. The algorithm was originally found in C++ at
http://flipcode.com/archives/Smallest_Enclosing_Spheres.shtml
and translated to java by Cep21- Parameters:
points
- The points to calculate the minimum bounds from.
-
averagePoints
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
transform
modifies the center of the sphere to reflect the change made via a rotation, translation and scale.- Specified by:
transform
in classBoundingVolume
- Parameters:
trans
- the transform to applystore
- sphere to store result in- Returns:
- either store or a new BoundingSphere
-
transform
- Specified by:
transform
in classBoundingVolume
-
whichSide
whichSide
takes a plane (typically provided by a view frustum) to determine which side this bound is on.- Specified by:
whichSide
in classBoundingVolume
- Parameters:
plane
- the plane to check against.- Returns:
- side
-
merge
merge
combines this sphere with a second bounding sphere. This new sphere contains both bounding spheres and is returned.- Specified by:
merge
in classBoundingVolume
- Parameters:
volume
- the sphere to combine with this sphere.- Returns:
- a new sphere
-
mergeLocal
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 classBoundingVolume
- Parameters:
volume
- the sphere to combine with this sphere.- Returns:
- this
-
clone
clone
creates a new BoundingSphere object containing the same data as this one.- Specified by:
clone
in classBoundingVolume
- Parameters:
store
- where to store the cloned information. if null or wrong class, a new store is created.- Returns:
- the new BoundingSphere
-
equals
Tests for exact equality with the argument, distinguishing -0 from 0. Ifother
is null, false is returned. Either way, the current instance is unaffected.- Overrides:
equals
in classBoundingVolume
- Parameters:
other
- the object to compare (may be null, unaffected)- Returns:
- true if
this
andother
have identical values, otherwise false
-
hashCode
public int hashCode()Returns a hash code. If two bounding boxes have identical values, they will have the same hash code. The current instance is unaffected.- Overrides:
hashCode
in classBoundingVolume
- Returns:
- a 32-bit value for use in hashing
-
isSimilar
Tests for approximate equality with the specified bounding sphere, using the specified tolerance. Ifother
is null, false is returned. Either way, the current instance is unaffected.- Parameters:
sphere
- the bounding sphere to compare (unaffected) or null for noneepsilon
- the tolerance for each component- Returns:
- true if all components are within tolerance, otherwise false
-
toString
toString
returns the string representation of this object. The form is: "Radius: RRR.SSSS Center: vector". -
intersects
Description copied from class: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 classBoundingVolume
- Parameters:
bv
- the second volume to test against.- Returns:
- true if this volume intersects the given volume.
-
intersectsSphere
Description copied from class:BoundingVolume
determines if this bounding volume and a given bounding sphere are intersecting.- Specified by:
intersectsSphere
in classBoundingVolume
- Parameters:
bs
- the bounding sphere to test against.- Returns:
- true if this volume intersects the given bounding sphere.
-
intersectsBoundingBox
Description copied from class:BoundingVolume
determines if this bounding volume and a given bounding box are intersecting.- Specified by:
intersectsBoundingBox
in classBoundingVolume
- Parameters:
bb
- the bounding box to test against.- Returns:
- true if this volume intersects the given bounding box.
-
intersects
Description copied from class:BoundingVolume
determines if a ray intersects this bounding volume.- Specified by:
intersects
in classBoundingVolume
- Parameters:
ray
- the ray to test.- Returns:
- true if this volume is intersected by a given ray.
-
collideWith
Description copied from interface:Collidable
Check collision with another Collidable.- Parameters:
other
- The object to check collision againstresults
- Will contain the list ofCollisionResult
s.- Returns:
- how many collisions were found between this and other
-
collideWith
- Overrides:
collideWith
in classBoundingVolume
-
contains
Description copied from class:BoundingVolume
determines if a given point is contained within this bounding volume. If the point is on the edge of the bounding volume, this method will return false. Use intersects(Vector3f) to check for edge intersection.- Specified by:
contains
in classBoundingVolume
- Parameters:
point
- the point to check- Returns:
- true if the point lies within this bounding volume.
-
intersects
Description copied from class:BoundingVolume
Determines if a given point intersects (touches or is inside) this bounding volume.- Specified by:
intersects
in classBoundingVolume
- Parameters:
point
- the point to check- Returns:
- true if the point lies within this bounding volume.
-
distanceToEdge
Description copied from class:BoundingVolume
Find the distance from the nearest edge of this Bounding Volume to the given point.- Specified by:
distanceToEdge
in classBoundingVolume
- Parameters:
point
- The point to get the distance to- Returns:
- distance
-
write
- Specified by:
write
in interfaceSavable
- Overrides:
write
in classBoundingVolume
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSavable
- Overrides:
read
in classBoundingVolume
- Throws:
IOException
-
getVolume
public float getVolume()- Specified by:
getVolume
in classBoundingVolume
-