com.badlogic.gdx.math.collision
Class BoundingBox

java.lang.Object
  extended by com.badlogic.gdx.math.collision.BoundingBox
All Implemented Interfaces:
Serializable

public class BoundingBox
extends Object
implements 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.

Author:
[email protected]
See Also:
Serialized Form

Field Summary
 Vector3 max
           
 Vector3 min
           
 
Constructor Summary
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
 BoundingBox clr()
          Sets the minimum and maximum vector to zeros
 boolean contains(BoundingBox b)
          Returns whether the given bounding box is contained in this bounding box.
 boolean contains(Vector3 v)
          Returns whether the given vector is contained in this bounding box.
 BoundingBox ext(BoundingBox a_bounds)
          Extends this bounding box by the given bounding box.
 BoundingBox ext(BoundingBox bounds, Matrix4 transform)
          Extends this bounding box by the given transformed bounding box.
 BoundingBox ext(float x, float y, float z)
          Extends the bounding box by the given vector.
 BoundingBox ext(Vector3 point)
          Extends the bounding box to incorporate the given Vector3.
 Vector3 getCenter()
           
 Vector3[] getCorners()
           
 Vector3 getDimensions()
           
 Vector3 getMax()
           
 Vector3 getMin()
           
 BoundingBox inf()
          Sets the minimum and maximum vector to positive and negative infinity.
 boolean intersects(BoundingBox b)
          Returns whether the given bounding box is intersecting this bounding box (at least one point in).
 boolean isValid()
          Returns whether this bounding box is valid.
 BoundingBox mul(Matrix4 matrix)
          Multiplies the bounding box by the given matrix.
 BoundingBox set(BoundingBox bounds)
          Sets the given bounding box.
 BoundingBox set(List<Vector3> points)
          Sets the bounding box minimum and maximum vector from the given points.
 BoundingBox set(Vector3[] points)
          Sets the bounding box minimum and maximum vector from the given points.
 BoundingBox set(Vector3 minimum, Vector3 maximum)
          Sets the given minimum and maximum vector.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

min

public final Vector3 min

max

public final Vector3 max
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()
Returns:
the center of the bounding box

getCorners

public Vector3[] getCorners()
Returns:
the corners of this bounding box

getDimensions

public Vector3 getDimensions()
Returns:
The dimensions of this bounding box on all three axis

getMin

public Vector3 getMin()
Returns:
The minimum vector

getMax

public Vector3 getMax()
Returns:
The maximum vector

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.

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(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 min != max and min < max.

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(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 matrix)
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:
matrix - 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

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 String toString()
Overrides:
toString in class 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.


Copyright © 2013. All Rights Reserved.