de.gaffga.parrotengine.boundings
Class AABoundingBox

java.lang.Object
  extended by de.gaffga.parrotengine.boundings.AABoundingBox

public class AABoundingBox
extends java.lang.Object

This is an axis aligned bounding box.

Author:
Stefan Gaffga

Nested Class Summary
static class AABoundingBox.AABoundingBoxSides
          The different planes that are bordering the box.
 
Constructor Summary
AABoundingBox()
          Default constructor.
AABoundingBox(AABoundingBox box)
          Copy constructor.
AABoundingBox(Vector center, double width, double height, double depth)
          Constructs a new axis aligned bounding box from a center point and the extensions in three dimensions.
AABoundingBox(Vector p0, Vector p1)
          Constructs a new axis aligned bounding box from two opposite points.
 
Method Summary
 boolean contains(Vector v)
          Checks whether a given point is contained within this bounding box.
 Vector getCenter()
          Returns the center of the box.
 double getDepth()
          Returns the depth of the box.
 double getDistance(Vector p)
          Calculates the distance of a point to the box.
 double getHeight()
          Returns the height of the box.
 Vector getHitpoint(Ray ray2)
          Checks whether the box hits the given ray and returns the nearest hitpoint.
 Vector getP0()
          Returns the first corner point.
 Vector getP1()
          Returns the second (opposite of first) corner point.
 Plane getPlane(AABoundingBox.AABoundingBoxSides plane)
          Returns a specifiy plane of the box.
 Plane[] getPlanes()
          Returns the array of the planes that are bordering this box.
 AABoundingBox getQuadBox(int idx)
          Returns a given smaller bounding box for QuadTree use.
 Rectangle3D getSide(AABoundingBox.AABoundingBoxSides side)
          Returns a specific side of the box as a Rectangle3D.
 Vector[] getVertices()
          Returns the vertex list of this bounding box - the 8 points that form the box.
 double getWidth()
          Returns the width of the box.
 void initFromOppositePoints(Vector p0, Vector p1)
          (Re)initializes this AABoundingBox using two opposite points.
static AABoundingBox mul(AABoundingBox box, Matrix mat)
          Creates a new AABoundingBox that completely contains the given bounding box that is transformed using the given matrix.
 java.lang.String toString()
          Returns a string representation of this object.
 void union(AABoundingBox box)
          Unify the current bounding box with the given.
static AABoundingBox union(AABoundingBox box1, AABoundingBox box2)
          Constructs a new AABoundingBox that contains the two given.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AABoundingBox

public AABoundingBox()
Default constructor.


AABoundingBox

public AABoundingBox(Vector center,
                     double width,
                     double height,
                     double depth)
Constructs a new axis aligned bounding box from a center point and the extensions in three dimensions.

Parameters:
center - the center of the box
width - the width of the box
height - the height of the box
depth - the depth of the box

AABoundingBox

public AABoundingBox(AABoundingBox box)
Copy constructor.

Parameters:
box - the box to copy

AABoundingBox

public AABoundingBox(Vector p0,
                     Vector p1)
Constructs a new axis aligned bounding box from two opposite points.

Parameters:
p0 - the first point
p1 - the second point
Method Detail

initFromOppositePoints

public void initFromOppositePoints(Vector p0,
                                   Vector p1)
(Re)initializes this AABoundingBox using two opposite points.

Parameters:
p0 - the first point
p1 - the second point

getQuadBox

public AABoundingBox getQuadBox(int idx)
Returns a given smaller bounding box for QuadTree use. The height is kept the same for all four smaller boxes. Seen from top-down: index 0 = back left index 1 = back right index 2 = front right index 3 = front left

Parameters:
idx - the index of the smaller cube - can be 0 to 3.
Returns:
the newly created smaller AABoundingBox

contains

public boolean contains(Vector v)
Checks whether a given point is contained within this bounding box.

Parameters:
v - the point to test
Returns:
true if the point is in the box, false otherwise

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
the string

getVertices

public Vector[] getVertices()
Returns the vertex list of this bounding box - the 8 points that form the box.

Returns:
the list of the points

mul

public static AABoundingBox mul(AABoundingBox box,
                                Matrix mat)
Creates a new AABoundingBox that completely contains the given bounding box that is transformed using the given matrix.

Parameters:
box - the box to transform
mat - the matrix to use for transformation
Returns:
the newly created BoundingBox

union

public static AABoundingBox union(AABoundingBox box1,
                                  AABoundingBox box2)
Constructs a new AABoundingBox that contains the two given.

Parameters:
box1 - the first bounding box
box2 - the second bounding box
Returns:
the newly created bounding box that surrounds the two given

union

public void union(AABoundingBox box)
Unify the current bounding box with the given.

Parameters:
box - the bounding box to add

getP0

public Vector getP0()
Returns the first corner point.

Returns:
the first corner

getP1

public Vector getP1()
Returns the second (opposite of first) corner point.

Returns:
the second corner

getPlane

public Plane getPlane(AABoundingBox.AABoundingBoxSides plane)
Returns a specifiy plane of the box.

Parameters:
plane - the desired plane
Returns:
the plane object

getSide

public Rectangle3D getSide(AABoundingBox.AABoundingBoxSides side)
Returns a specific side of the box as a Rectangle3D.

Parameters:
side - the side to return
Returns:
the Rectangle3D object that specifies the side

getPlanes

public Plane[] getPlanes()
Returns the array of the planes that are bordering this box.

Returns:
the array of planes

getCenter

public Vector getCenter()
Returns the center of the box.

Returns:
the center point

getHitpoint

public Vector getHitpoint(Ray ray2)
Checks whether the box hits the given ray and returns the nearest hitpoint.

Parameters:
ray2 - the ray to test the box against
Returns:
the hitpoint or null if none exists

getDistance

public double getDistance(Vector p)
Calculates the distance of a point to the box.

Parameters:
p - the point
Returns:
the distance

getWidth

public double getWidth()
Returns the width of the box.

Returns:
the width

getHeight

public double getHeight()
Returns the height of the box.

Returns:
the height

getDepth

public double getDepth()
Returns the depth of the box.

Returns:
the depth