public class BoundingSphere extends 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. containAABB
or averagePoints
. A call to
computeFramePoint
in turn calls containAABB
.BoundingVolume.Type
center, checkPlane
Constructor and Description |
---|
BoundingSphere()
Default constructor instantiates a new
BoundingSphere
object. |
BoundingSphere(float r,
Vector3f c)
Constructor instantiates a new
BoundingSphere object. |
Modifier and Type | Method and Description |
---|---|
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(java.nio.FloatBuffer points)
Calculates a minimum bounding sphere for the set of points.
|
BoundingVolume |
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(java.nio.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 |
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.
|
float |
getRadius()
getRadius returns the radius of the bounding sphere. |
BoundingVolume.Type |
getType()
getType returns the type of bounding volume this is.
|
float |
getVolume() |
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 |
intersects(Vector3f point)
Determines if a given point intersects (touches or is inside) this bounding volume.
|
boolean |
intersectsBoundingBox(BoundingBox bb)
determines if this bounding volume and a given 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 |
read(JmeImporter e) |
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(Matrix4f trans,
BoundingVolume store) |
BoundingVolume |
transform(Transform trans,
BoundingVolume store)
transform modifies the center of the sphere 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) |
clone, distanceSquaredTo, distanceTo, getCenter, getCenter, getCheckPlane, setCenter, setCenter, setCheckPlane, transform
public BoundingSphere()
BoundingSphere
object.public BoundingSphere(float r, Vector3f c)
BoundingSphere
object.r
- the radius of the sphere.c
- the center of the sphere.public BoundingVolume.Type getType()
BoundingVolume
getType
in class BoundingVolume
public float getRadius()
getRadius
returns the radius of the bounding sphere.public void setRadius(float radius)
setRadius
sets the radius of this bounding sphere.radius
- the new radius of the bounding sphere.public void computeFromPoints(java.nio.FloatBuffer points)
computeFromPoints
creates a new Bounding Sphere from a
given set of points. It uses the calcWelzl
method as
default.computeFromPoints
in class BoundingVolume
points
- the points to contain.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.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 usedpublic void calcWelzl(java.nio.FloatBuffer points)
points
- The points to calculate the minimum bounds from.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.points
- the list of points to contain.public BoundingVolume transform(Transform trans, BoundingVolume store)
transform
modifies the center of the sphere to reflect the
change made via a rotation, translation and scale.transform
in class BoundingVolume
trans
- the transform to applystore
- sphere to store result inpublic BoundingVolume transform(Matrix4f trans, BoundingVolume store)
transform
in class BoundingVolume
public Plane.Side whichSide(Plane plane)
whichSide
takes a plane (typically provided by a view
frustum) to determine which side this bound is on.whichSide
in class BoundingVolume
plane
- the plane to check against.public BoundingVolume merge(BoundingVolume volume)
merge
combines this sphere with a second bounding sphere.
This new sphere contains both bounding spheres and is returned.merge
in class BoundingVolume
volume
- the sphere to combine with this sphere.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;mergeLocal
in class BoundingVolume
volume
- the sphere to combine with this sphere.public BoundingVolume clone(BoundingVolume store)
clone
creates a new BoundingSphere object containing the
same data as this one.clone
in class BoundingVolume
store
- where to store the cloned information. if null or wrong class,
a new store is created.public java.lang.String toString()
toString
returns the string representation of this object.
The form is: "Radius: RRR.SSSS Center: vector".toString
in class java.lang.Object
public boolean intersects(BoundingVolume bv)
BoundingVolume
intersects
in class BoundingVolume
bv
- the second volume to test against.public boolean intersectsSphere(BoundingSphere bs)
BoundingVolume
intersectsSphere
in class BoundingVolume
bs
- the bounding sphere to test against.public boolean intersectsBoundingBox(BoundingBox bb)
BoundingVolume
intersectsBoundingBox
in class BoundingVolume
bb
- the bounding box to test against.public boolean intersects(Ray ray)
BoundingVolume
intersects
in class BoundingVolume
ray
- the ray to test.public int collideWith(Collidable other, CollisionResults results)
Collidable
other
- The object to check collision againstresults
- Will contain the list of CollisionResult
s.public int collideWith(Collidable other)
collideWith
in class BoundingVolume
public boolean contains(Vector3f point)
BoundingVolume
contains
in class BoundingVolume
point
- the point to checkpublic boolean intersects(Vector3f point)
BoundingVolume
intersects
in class BoundingVolume
point
- the point to checkpublic float distanceToEdge(Vector3f point)
BoundingVolume
distanceToEdge
in class BoundingVolume
point
- The point to get the distance topublic void write(JmeExporter e) throws java.io.IOException
write
in interface Savable
write
in class BoundingVolume
java.io.IOException
public void read(JmeImporter e) throws java.io.IOException
read
in interface Savable
read
in class BoundingVolume
java.io.IOException
public float getVolume()
getVolume
in class BoundingVolume