Class BoundingBox

  • All Implemented Interfaces:
    java.io.Serializable

    public class BoundingBox
    extends java.lang.Object
    implements java.io.Serializable
    Encapsulates an axis aligned bounding box represented by a minimum and a maximum Vector. Additionally you can query for the bounding box's center, dimensions and corner points.
    See Also:
    Serialized Form
    • Field Detail

      • min

        public final Vector3 min
        Minimum vector. All XYZ components should be inferior to corresponding max components. Call update() if you manually change this vector.
      • max

        public final Vector3 max
        Maximum vector. All XYZ components should be superior to corresponding min components. Call update() if you manually change this vector.
    • Constructor Detail

      • BoundingBox

        public BoundingBox()
        Constructs a new bounding box with the minimum and maximum vector set to zeros.
      • BoundingBox

        public BoundingBox​(BoundingBox bounds)
        Constructs a new bounding box from the given bounding box.
        Parameters:
        bounds - The bounding box to copy
      • BoundingBox

        public BoundingBox​(Vector3 minimum,
                           Vector3 maximum)
        Constructs the new bounding box using the given minimum and maximum vector.
        Parameters:
        minimum - The minimum vector
        maximum - The maximum vector
    • Method Detail

      • getCenter

        public Vector3 getCenter​(Vector3 out)
        Parameters:
        out - The Vector3 to receive the center of the bounding box.
        Returns:
        The vector specified with the out argument.
      • getCenterX

        public float getCenterX()
      • getCenterY

        public float getCenterY()
      • getCenterZ

        public float getCenterZ()
      • getDimensions

        public Vector3 getDimensions​(Vector3 out)
        Parameters:
        out - The Vector3 to receive the dimensions of this bounding box on all three axis.
        Returns:
        The vector specified with the out argument
      • getWidth

        public float getWidth()
      • getHeight

        public float getHeight()
      • getDepth

        public float getDepth()
      • getMin

        public Vector3 getMin​(Vector3 out)
        Parameters:
        out - The Vector3 to receive the minimum values.
        Returns:
        The vector specified with the out argument
      • getMax

        public Vector3 getMax​(Vector3 out)
        Parameters:
        out - The Vector3 to receive the maximum values.
        Returns:
        The vector specified with the out argument
      • set

        public BoundingBox set​(BoundingBox bounds)
        Sets the given bounding box.
        Parameters:
        bounds - The bounds.
        Returns:
        This bounding box for chaining.
      • set

        public BoundingBox set​(Vector3 minimum,
                               Vector3 maximum)
        Sets the given minimum and maximum vector.
        Parameters:
        minimum - The minimum vector
        maximum - The maximum vector
        Returns:
        This bounding box for chaining.
      • update

        public void update()
        Should be called if you modify min and/or max vectors manually.
      • set

        public BoundingBox set​(Vector3[] points)
        Sets the bounding box minimum and maximum vector from the given points.
        Parameters:
        points - The points.
        Returns:
        This bounding box for chaining.
      • set

        public BoundingBox set​(java.util.List<Vector3> points)
        Sets the bounding box minimum and maximum vector from the given points.
        Parameters:
        points - The points.
        Returns:
        This bounding box for chaining.
      • inf

        public BoundingBox inf()
        Sets the minimum and maximum vector to positive and negative infinity.
        Returns:
        This bounding box for chaining.
      • ext

        public BoundingBox ext​(Vector3 point)
        Extends the bounding box to incorporate the given Vector3.
        Parameters:
        point - The vector
        Returns:
        This bounding box for chaining.
      • clr

        public BoundingBox clr()
        Sets the minimum and maximum vector to zeros.
        Returns:
        This bounding box for chaining.
      • isValid

        public boolean isValid()
        Returns whether this bounding box is valid. This means that max is greater than or equal to min.
        Returns:
        True in case the bounding box is valid, false otherwise
      • ext

        public BoundingBox ext​(BoundingBox a_bounds)
        Extends this bounding box by the given bounding box.
        Parameters:
        a_bounds - The bounding box
        Returns:
        This bounding box for chaining.
      • ext

        public BoundingBox ext​(Vector3 center,
                               float radius)
        Extends this bounding box by the given sphere.
        Parameters:
        center - Sphere center
        radius - Sphere radius
        Returns:
        This bounding box for chaining.
      • ext

        public BoundingBox ext​(BoundingBox bounds,
                               Matrix4 transform)
        Extends this bounding box by the given transformed bounding box.
        Parameters:
        bounds - The bounding box
        transform - The transformation matrix to apply to bounds, before using it to extend this bounding box.
        Returns:
        This bounding box for chaining.
      • mul

        public BoundingBox mul​(Matrix4 transform)
        Multiplies the bounding box by the given matrix. This is achieved by multiplying the 8 corner points and then calculating the minimum and maximum vectors from the transformed points.
        Parameters:
        transform - The matrix
        Returns:
        This bounding box for chaining.
      • contains

        public boolean contains​(BoundingBox b)
        Returns whether the given bounding box is contained in this bounding box.
        Parameters:
        b - The bounding box
        Returns:
        Whether the given bounding box is contained
      • contains

        public boolean contains​(OrientedBoundingBox obb)
        Returns whether the given oriented bounding box is contained in this oriented bounding box.
        Parameters:
        obb - The bounding box
        Returns:
        Whether the given oriented bounding box is contained
      • intersects

        public boolean intersects​(BoundingBox b)
        Returns whether the given bounding box is intersecting this bounding box (at least one point in).
        Parameters:
        b - The bounding box
        Returns:
        Whether the given bounding box is intersected
      • contains

        public boolean contains​(Vector3 v)
        Returns whether the given vector is contained in this bounding box.
        Parameters:
        v - The vector
        Returns:
        Whether the vector is contained or not.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • ext

        public BoundingBox ext​(float x,
                               float y,
                               float z)
        Extends the bounding box by the given vector.
        Parameters:
        x - The x-coordinate
        y - The y-coordinate
        z - The z-coordinate
        Returns:
        This bounding box for chaining.