Package com.badlogic.gdx.math.collision
Class BoundingBox
- java.lang.Object
-
- com.badlogic.gdx.math.collision.BoundingBox
-
- All Implemented Interfaces:
java.io.Serializable
public class BoundingBox extends java.lang.Object implements java.io.SerializableEncapsulates 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
-
-
Constructor Summary
Constructors Constructor Description BoundingBox()Constructs a new bounding box with the minimum and maximum vector set to zeros.BoundingBox(BoundingBox bounds)Constructs a new bounding box from the given bounding box.BoundingBox(Vector3 minimum, Vector3 maximum)Constructs the new bounding box using the given minimum and maximum vector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BoundingBoxclr()Sets the minimum and maximum vector to zeros.booleancontains(BoundingBox b)Returns whether the given bounding box is contained in this bounding box.booleancontains(OrientedBoundingBox obb)Returns whether the given oriented bounding box is contained in this oriented bounding box.booleancontains(Vector3 v)Returns whether the given vector is contained in this bounding box.BoundingBoxext(float x, float y, float z)Extends the bounding box by the given vector.BoundingBoxext(BoundingBox a_bounds)Extends this bounding box by the given bounding box.BoundingBoxext(BoundingBox bounds, Matrix4 transform)Extends this bounding box by the given transformed bounding box.BoundingBoxext(Vector3 point)Extends the bounding box to incorporate the givenVector3.BoundingBoxext(Vector3 center, float radius)Extends this bounding box by the given sphere.Vector3getCenter(Vector3 out)floatgetCenterX()floatgetCenterY()floatgetCenterZ()Vector3getCorner000(Vector3 out)Vector3getCorner001(Vector3 out)Vector3getCorner010(Vector3 out)Vector3getCorner011(Vector3 out)Vector3getCorner100(Vector3 out)Vector3getCorner101(Vector3 out)Vector3getCorner110(Vector3 out)Vector3getCorner111(Vector3 out)floatgetDepth()Vector3getDimensions(Vector3 out)floatgetHeight()Vector3getMax(Vector3 out)Vector3getMin(Vector3 out)floatgetWidth()BoundingBoxinf()Sets the minimum and maximum vector to positive and negative infinity.booleanintersects(BoundingBox b)Returns whether the given bounding box is intersecting this bounding box (at least one point in).booleanisValid()Returns whether this bounding box is valid.BoundingBoxmul(Matrix4 transform)Multiplies the bounding box by the given matrix.BoundingBoxset(BoundingBox bounds)Sets the given bounding box.BoundingBoxset(Vector3[] points)Sets the bounding box minimum and maximum vector from the given points.BoundingBoxset(Vector3 minimum, Vector3 maximum)Sets the given minimum and maximum vector.BoundingBoxset(java.util.List<Vector3> points)Sets the bounding box minimum and maximum vector from the given points.java.lang.StringtoString()voidupdate()
-
-
-
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
-
-
Method Detail
-
getCenter
public Vector3 getCenter(Vector3 out)
- Parameters:
out- TheVector3to 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- TheVector3to 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- TheVector3to receive the minimum values.- Returns:
- The vector specified with the out argument
-
getMax
public Vector3 getMax(Vector3 out)
- Parameters:
out- TheVector3to 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 vectormaximum- The maximum vector- Returns:
- This bounding box for chaining.
-
update
public void update()
-
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 givenVector3.- 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:
- 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 centerradius- 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 boxtransform- 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:
toStringin classjava.lang.Object
-
ext
public BoundingBox ext(float x, float y, float z)
Extends the bounding box by the given vector.- Parameters:
x- The x-coordinatey- The y-coordinatez- The z-coordinate- Returns:
- This bounding box for chaining.
-
-