Class BoundingBox

java.lang.Object
com.jme3.bounding.BoundingVolume
com.jme3.bounding.BoundingBox
All Implemented Interfaces:
Collidable, Savable, Cloneable

public class BoundingBox extends BoundingVolume
BoundingBox describes a bounding volume as an axis-aligned box.
Instances may be initialized by invoking the containAABB method.
  • Constructor Details

    • BoundingBox

      public BoundingBox()
      Instantiate a BoundingBox without initializing it.
    • BoundingBox

      public BoundingBox(Vector3f c, float x, float y, float z)
      Instantiate a BoundingBox 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

      public BoundingBox(BoundingBox source)
      Instantiate a BoundingBox equivalent to an existing box.
      Parameters:
      source - the existing box (not null, not altered)
    • BoundingBox

      public BoundingBox(Vector3f min, Vector3f max)
      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

      public BoundingVolume.Type getType()
      Description copied from class: BoundingVolume
      getType returns the type of bounding volume this is.
      Specified by:
      getType in class BoundingVolume
      Returns:
      an enum value
    • computeFromPoints

      public void computeFromPoints(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.
      Parameters:
      tris - triangle data (unaffected)
      start - the index of the first triangle to be used
      end - the index of the triangle after the last one to be used
    • computeFromTris

      public void computeFromTris(int[] indices, Mesh mesh, int start, int end)
    • checkMinMax

      public static void checkMinMax(Vector3f min, Vector3f max, Vector3f point)
    • containAABB

      public 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.
      Parameters:
      points - the list of points.
    • transform

      public BoundingVolume transform(Transform trans, 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:
      trans - the transform to apply
      store - box to store result in
      Returns:
      the new bounding volume.
    • transform

      public BoundingVolume transform(Matrix4f trans, BoundingVolume store)
      Specified by:
      transform in class BoundingVolume
    • 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 bounding box locally with a second bounding volume. The result contains both the original box and the second volume.
      Specified by:
      merge in class BoundingVolume
      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

      public BoundingVolume mergeLocal(BoundingVolume volume)
      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 class BoundingVolume
      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

      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
    • equals

      public boolean equals(Object other)
      Tests for exact equality with the argument, distinguishing -0 from 0. If other is null, false is returned. Either way, the current instance is unaffected.
      Overrides:
      equals in class BoundingVolume
      Parameters:
      other - the object to compare (may be null, unaffected)
      Returns:
      true if this and other 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 class BoundingVolume
      Returns:
      a 32-bit value for use in hashing
    • isSimilar

      public boolean isSimilar(BoundingBox aabb, float epsilon)
      Tests for approximate equality with the specified bounding box, using the specified tolerance. If other is null, false is returned. Either way, the current instance is unaffected.
      Parameters:
      aabb - the bounding box to compare (unaffected) or null for none
      epsilon - the tolerance for each component
      Returns:
      true if all components are within tolerance, otherwise false
    • toString

      public String toString()
      toString returns the string representation of this object. The form is: "[Center: vector xExtent: X.XX yExtent: Y.YY zExtent: Z.ZZ]".
      Overrides:
      toString in class 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:
    • 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:
    • 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:
    • 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:
    • collideWith

      public int collideWith(Collidable other, CollisionResults results)
      Description copied from interface: Collidable
      Check collision with another Collidable.
      Parameters:
      other - The object to check collision against
      results - Will contain the list of CollisionResults.
      Returns:
      how many collisions were found between this and other
    • collideWith

      public int collideWith(Collidable other)
      Overrides:
      collideWith in class BoundingVolume
    • intersects

      public boolean intersects(Vector3f v1, Vector3f v2, Vector3f v3)
      Parameters:
      v1 - The first point in the triangle
      v2 - The second point in the triangle
      v3 - The third point in the triangle
      Returns:
      True if the bounding box intersects the triangle, false otherwise.
    • contains

      public boolean contains(Vector3f point)
      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 class BoundingVolume
      Parameters:
      point - the point to check
      Returns:
      true if the point lies within this bounding volume.
    • intersects

      public boolean intersects(Vector3f point)
      Description copied from class: BoundingVolume
      Determines if a given point intersects (touches or is inside) this bounding volume.
      Specified by:
      intersects 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
    • 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

      public Vector3f getMin(Vector3f store)
      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

      public Vector3f getMax(Vector3f store)
      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

      public void setMinMax(Vector3f min, Vector3f max)
      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

      public void write(JmeExporter e) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class BoundingVolume
      Throws:
      IOException
    • read

      public void read(JmeImporter importer) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class BoundingVolume
      Throws:
      IOException
    • getVolume

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