Package com.jme3.bounding
Class BoundingBox
java.lang.Object
com.jme3.bounding.BoundingVolume
com.jme3.bounding.BoundingBox
- All Implemented Interfaces:
Collidable
,Savable
,Cloneable
BoundingBox
describes a bounding volume as an axis-aligned box.
Instances may be initialized by invoking the
containAABB
method.-
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
ConstructorDescriptionInstantiate aBoundingBox
without initializing it.BoundingBox
(BoundingBox source) Instantiate aBoundingBox
equivalent to an existing box.BoundingBox
(Vector3f c, float x, float y, float z) Instantiate aBoundingBox
with given center and extents.BoundingBox
(Vector3f min, Vector3f max) Instantiate a BoundingBox with the specified extremes. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkMinMax
(Vector3f min, Vector3f max, Vector3f point) clone
(BoundingVolume store) clone
creates a new BoundingBox 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 Box from a given set of points.void
computeFromTris
(int[] indices, Mesh 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
(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
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.Query extent.Determine the maximum coordinate value for each axis.Determine the minimum coordinate value for each axis.getType()
getType returns the type of bounding volume this is.float
float
Determine the X-axis distance between the center and the boundary.float
Determine the Y-axis distance between the center and the boundary.float
Determine the Z-axis distance between the center and the boundary.int
hashCode()
Returns a hash code.boolean
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
intersects
(Vector3f point) Determines if a given point intersects (touches or is inside) this bounding volume.boolean
intersects
(Vector3f v1, Vector3f v2, Vector3f v3) C code ported from http://www.cs.lth.se/home/Tomas_Akenine_Moller/code/tribox3.txtboolean
determines if this bounding box intersects a given bounding box.boolean
determines if this bounding box intersects a given bounding sphere.boolean
isSimilar
(BoundingBox aabb, float epsilon) Tests for approximate equality with the specified bounding box, using the specified tolerance.merge
(BoundingVolume volume) merge
combines this bounding box locally with a second bounding volume.mergeLocal
(BoundingVolume volume) mergeLocal
combines this bounding box locally with a second bounding volume.void
read
(JmeImporter importer) void
Reconfigure with the specified extremes.void
setXExtent
(float xExtent) Alter the X-axis distance between the center and the boundary.void
setYExtent
(float yExtent) Alter the Y-axis distance between the center and the boundary.void
setZExtent
(float zExtent) Alter the Z-axis distance between the center and the boundary.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 box 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
-
BoundingBox
public BoundingBox()Instantiate aBoundingBox
without initializing it. -
BoundingBox
Instantiate aBoundingBox
with given center and extents.- Parameters:
c
- the coordinates of the center of the box (not null, not altered)x
- the X-extent of the box (0 or greater, may be +Infinity)y
- the Y-extent of the box (0 or greater, may be +Infinity)z
- the Z-extent of the box (0 or greater, may be +Infinity)
-
BoundingBox
Instantiate aBoundingBox
equivalent to an existing box.- Parameters:
source
- the existing box (not null, not altered)
-
BoundingBox
Instantiate a BoundingBox with the specified extremes.- Parameters:
min
- the desired minimum coordinate value for each axis (not null, not altered)max
- the desired maximum coordinate value for each axis (not null, not altered)
-
-
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
-
computeFromPoints
computeFromPoints
creates a new Bounding Box from a given set of points. It uses thecontainAABB
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
-
computeFromTris
-
checkMinMax
-
containAABB
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
transform
modifies the center of the box to reflect the change made via a rotation, translation and scale.- Specified by:
transform
in classBoundingVolume
- Parameters:
trans
- the transform to applystore
- box to store result in- Returns:
- the new bounding volume.
-
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:
- the side on which this bounding volume lies.
-
merge
merge
combines this bounding box locally with a second bounding volume. The result contains both the original box and the second volume.- Specified by:
merge
in classBoundingVolume
- Parameters:
volume
- the bounding volume to combine with this box (or null) (not altered)- Returns:
- this box (with its components modified) or null if the second volume is of some type other than AABB or Sphere
-
mergeLocal
mergeLocal
combines this bounding box locally with a second bounding volume. The result contains both the original box and the second volume.- Specified by:
mergeLocal
in classBoundingVolume
- Parameters:
volume
- the bounding volume to combine with this box (or null) (not altered)- Returns:
- this box (with its components modified) or null if the second volume is of some type other than AABB or Sphere
-
clone
clone
creates a new BoundingBox 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 BoundingBox
-
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 box, using the specified tolerance. Ifother
is null, false is returned. Either way, the current instance is unaffected.- Parameters:
aabb
- the bounding box 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: "[Center: vector xExtent: X.XX yExtent: Y.YY zExtent: Z.ZZ]". -
intersects
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 classBoundingVolume
- Parameters:
bv
- the second volume to test against.- Returns:
- true if this volume intersects the given volume.
- See Also:
-
intersectsSphere
determines if this bounding box intersects a given bounding sphere.- Specified by:
intersectsSphere
in classBoundingVolume
- Parameters:
bs
- the bounding sphere to test against.- Returns:
- true if this volume intersects the given bounding sphere.
- See Also:
-
intersectsBoundingBox
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 classBoundingVolume
- Parameters:
bb
- the bounding box to test against.- Returns:
- true if this volume intersects the given bounding box.
- See Also:
-
intersects
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 classBoundingVolume
- Parameters:
ray
- the ray to test.- Returns:
- true if this volume is intersected by a given ray.
- See Also:
-
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
-
intersects
C code ported from http://www.cs.lth.se/home/Tomas_Akenine_Moller/code/tribox3.txt- Parameters:
v1
- The first point in the trianglev2
- The second point in the trianglev3
- The third point in the triangle- Returns:
- True if the bounding box intersects the triangle, false otherwise.
-
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
-
getExtent
Query extent.- Parameters:
store
- where extent gets stored - null to return a new vector- Returns:
- store / new vector
-
getXExtent
public float getXExtent()Determine the X-axis distance between the center and the boundary.- Returns:
- the distance
-
getYExtent
public float getYExtent()Determine the Y-axis distance between the center and the boundary.- Returns:
- the distance
-
getZExtent
public float getZExtent()Determine the Z-axis distance between the center and the boundary.- Returns:
- the distance
-
setXExtent
public void setXExtent(float xExtent) Alter the X-axis distance between the center and the boundary.- Parameters:
xExtent
- the desired distance (≥0)
-
setYExtent
public void setYExtent(float yExtent) Alter the Y-axis distance between the center and the boundary.- Parameters:
yExtent
- the desired distance (≥0)
-
setZExtent
public void setZExtent(float zExtent) Alter the Z-axis distance between the center and the boundary.- Parameters:
zExtent
- the desired distance (≥0)
-
getMin
Determine the minimum coordinate value for each axis.- Parameters:
store
- storage for the result (modified if not null)- Returns:
- either storeResult or a new vector
-
getMax
Determine the maximum coordinate value for each axis.- Parameters:
store
- storage for the result (modified if not null)- Returns:
- either storeResult or a new vector
-
setMinMax
Reconfigure with the specified extremes.- Parameters:
min
- the desired minimum coordinate value for each axis (not null, not altered)max
- the desired maximum coordinate value for each axis (not null, not altered)
-
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
-