Top Description Fields Constructors Methods
com.jogamp.opengl.math.geom

public Class AABBox

extends Object
Class Inheritance
Imports
jogamp.graph.geom.plane.AffineTransform, com.jogamp.opengl.math.FloatUtil, .Quaternion, .Ray, .VectorUtil

Axis Aligned Bounding Box. Defined by two 3D coordinates (low and high) The low being the the lower left corner of the box, and the high being the upper right corner of the box.

A few references for collision detection, intersections:

http://www.realtimerendering.com/intersections.html
http://www.codercorner.com/RayAABB.cpp
http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter0.htm
http://realtimecollisiondetection.net/files/levine_swept_sat.txt

Field Summary

Modifier and TypeField and Description
private final float[]
private static final boolean
private final float[]
private final float[]

Constructor Summary

AccessConstructor and Description
public
AABBox()

Create an Axis Aligned bounding box (AABBox) where the low and and high MAX float Values.

public
AABBox(final AABBox
the box value to be used for the new instance
src
)

Create an AABBox copying all values from the given one

public
AABBox(final float
min x-coordinate
lx
,
final float
min y-coordnate
ly
,
final float
min z-coordinate
lz
,
final float
max x-coordinate
hx
,
final float
max y-coordinate
hy
,
final float
max z-coordinate
hz
)

Create an AABBox specifying the coordinates of the low and high

public
AABBox(final float[]
min xyz-coordinates
low
,
final float[]
max xyz-coordinates
high
)

Create a AABBox defining the low and high

Method Summary

Modifier and TypeMethod and Description
private final void
public final boolean

Returns:

true if x belong to (low.x, high.x) and y belong to (low.y, high.y)
contains
(final float
x-axis coordinate value
x
,
final float
y-axis coordinate value
y
)

Check if the x & y coordinates are bounded/contained by this AABBox

public final boolean

Returns:

true if x belong to (low.x, high.x) and y belong to (low.y, high.y) and z belong to (low.z, high.z)
contains
(final float
x-axis coordinate value
x
,
final float
y-axis coordinate value
y
,
final float
z-axis coordinate value
z
)

Check if the xyz coordinates are bounded/contained by this AABBox.

public final AABBox

Returns:

this AABBox for chaining
copy
(final AABBox
source AABBox
src
)

Copy given AABBox 'src' values to this AABBox.

public final boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public final float[]

Returns:

the xyz-coordinates of the center of the AABBox
getCenter
()

Get the Center of this AABBox

public final float
public final float
public final float[]

Returns:

a float array containing the max xyz coordinates
getHigh
()

Get the max xyz-coordinates

public final float[]

Returns:

a float array containing the min xyz coordinates
getLow
()

Get the min xyz-coordinates

public final float
public final float
public final float
public final float
public final float
public final float
public final float[]

Returns:

float[3] result of intersection coordinates, or null if none exists
getRayIntersection
(final float[]
vec3
result
,
final Ray ray, final float epsilon, final boolean
if true, method assumes an intersection, i.e. by pre-checking via intersectsRay(Ray). In this case method will not validate a possible non-intersection and just computes coordinates.
assumeIntersection
,
final float[]
temp vec3
tmp1V3
,
final float[]
temp vec3
tmp2V3
,
final float[]
temp vec3
tmp3V3
)

Return intersection of a Ray with this bounding box, or null if none exist.

public final float

Returns:

a float representing the size of the AABBox
getSize
()

Get the size of this AABBox where the size is represented by the length of the vector between low and high.

public final float
public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public final boolean

Returns:

true if this AABBox might have a common region with this 2D region
intersects2DRegion
(final float
lower left x-coord
x
,
final float
lower left y-coord
y
,
final float
width
w
,
final float
hight
h
)

Check if there is a common region between this AABBox and the passed 2D region irrespective of z range

public final boolean
intersectsRay(final Ray ray)

Check if Ray intersects this bounding box.

public AABBox
mapToWindow(final AABBox result, final float[]
P x Mv matrix
mat4PMv
,
final int[] view, final boolean useCenterZ, final float[]
3 component vector for temp storage
vec3Tmp0
,
final float[]
4 component vector for temp storage
vec4Tmp1
,
final float[]
4 component vector for temp storage
vec4Tmp2
)

Assume this bounding box as being in object space and compute the window bounding box.

public final AABBox

Returns:

this AABBox for chaining
reset
()

resets this box to the inverse low/high, allowing the next resize(float, float, float) command to hit.

public final AABBox

Returns:

this AABBox for chaining
resize
(final AABBox
AABBox to be encapsulated in
newBox
)

Resize the AABBox to encapsulate another AABox

public final AABBox

Returns:

this AABBox for chaining
resize
(final AABBox
AABBox to be encapsulated in
newBox
,
final AffineTransform
the AffineTransform applied on newBox on the fly
t
,
final float[]
temp float[3] storage
tmpV3
)

Resize the AABBox to encapsulate another AABox, which will be transformed on the fly first.

public final AABBox

Returns:

this AABBox for chaining
resize
(final float
x-axis coordinate value
x
,
final float
y-axis coordinate value
y
,
final float
z-axis coordinate value
z
)

Resize the AABBox to encapsulate the passed xyz-coordinates.

public final AABBox

Returns:

this AABBox for chaining
resize
(final float[]
xyz-axis coordinate values
xyz
,
final int
of the array
offset
)

Resize the AABBox to encapsulate the passed xyz-coordinates.

public final AABBox

Returns:

this AABBox for chaining
resize
(final float[]
xyz-axis coordinate values
xyz
)

Resize the AABBox to encapsulate the passed xyz-coordinates.

public final AABBox

Returns:

this AABBox for chaining
rotate
(final Quaternion
the Quaternion used for rotation
quat
)

Rotate this AABBox by a float[3] vector

public final AABBox

Returns:

this AABBox for chaining
scale
(final float
a constant float value
size
,
final float[]
caller provided temporary 3-component vector
tmpV3
)

Scale this AABBox by a constant

private final void
setHigh(final float hx, final float hy, final float hz)

private final void
setLow(final float lx, final float ly, final float lz)

public final AABBox

Returns:

this AABBox for chaining
setSize
(final float[]
min xyz-coordinates
low
,
final float[]
max xyz-coordinates
high
)

Set size of the AABBox specifying the coordinates of the low and high.

public final AABBox

Returns:

this AABBox for chaining
setSize
(final float
min x-coordinate
lx
,
final float
min y-coordnate
ly
,
final float
min z-coordinate
lz
,
final float
max x-coordinate
hx
,
final float
max y-coordinate
hy
,
final float
max z-coordinate
hz
)

Set size of the AABBox specifying the coordinates of the low and high.

public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public final AABBox

Returns:

this AABBox for chaining
translate
(final float[]
the float[3] translation vector
t
)

Translate this AABBox by a float[3] vector

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

centerback to summary
private final float[] center
DEBUGback to summary
private static final boolean DEBUG
highback to summary
private final float[] high
lowback to summary
private final float[] low

Constructor Detail

AABBoxback to summary
public AABBox()

Create an Axis Aligned bounding box (AABBox) where the low and and high MAX float Values.

AABBoxback to summary
public AABBox(final AABBox src)

Create an AABBox copying all values from the given one

Parameters
src:AABBox

the box value to be used for the new instance

AABBoxback to summary
public AABBox(final float lx, final float ly, final float lz, final float hx, final float hy, final float hz)

Create an AABBox specifying the coordinates of the low and high

Parameters
lx:float

min x-coordinate

ly:float

min y-coordnate

lz:float

min z-coordinate

hx:float

max x-coordinate

hy:float

max y-coordinate

hz:float

max z-coordinate

AABBoxback to summary
public AABBox(final float[] low, final float[] high)

Create a AABBox defining the low and high

Parameters
low:float[]

min xyz-coordinates

high:float[]

max xyz-coordinates

Method Detail

computeCenterback to summary
private final void computeCenter()
containsback to summary
public final boolean contains(final float x, final float y)

Check if the x & y coordinates are bounded/contained by this AABBox

Parameters
x:float

x-axis coordinate value

y:float

y-axis coordinate value

Returns:boolean

true if x belong to (low.x, high.x) and y belong to (low.y, high.y)

containsback to summary
public final boolean contains(final float x, final float y, final float z)

Check if the xyz coordinates are bounded/contained by this AABBox.

Parameters
x:float

x-axis coordinate value

y:float

y-axis coordinate value

z:float

z-axis coordinate value

Returns:boolean

true if x belong to (low.x, high.x) and y belong to (low.y, high.y) and z belong to (low.z, high.z)

copyback to summary
public final AABBox copy(final AABBox src)

Copy given AABBox 'src' values to this AABBox.

Parameters
src:AABBox

source AABBox

Returns:AABBox

this AABBox for chaining

equalsback to summary
public final boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getCenterback to summary
public final float[] getCenter()

Get the Center of this AABBox

Returns:float[]

the xyz-coordinates of the center of the AABBox

getDepthback to summary
public final float getDepth()
getHeightback to summary
public final float getHeight()
getHighback to summary
public final float[] getHigh()

Get the max xyz-coordinates

Returns:float[]

a float array containing the max xyz coordinates

getLowback to summary
public final float[] getLow()

Get the min xyz-coordinates

Returns:float[]

a float array containing the min xyz coordinates

getMaxXback to summary
public final float getMaxX()
getMaxYback to summary
public final float getMaxY()
getMaxZback to summary
public final float getMaxZ()
getMinXback to summary
public final float getMinX()
getMinYback to summary
public final float getMinY()
getMinZback to summary
public final float getMinZ()
getRayIntersectionback to summary
public final float[] getRayIntersection(final float[] result, final Ray ray, final float epsilon, final boolean assumeIntersection, final float[] tmp1V3, final float[] tmp2V3, final float[] tmp3V3)

Return intersection of a Ray with this bounding box, or null if none exist.

  • Original code by Andrew Woo, from "Graphics Gems", Academic Press, 1990 [2]
  • Optimized code by Pierre Terdiman, 2000 (~20-30% faster on my Celeron 500)
  • Epsilon value added by Klaus Hartmann.

Method is based on the requirements:

  • the integer representation of 0.0f is 0x00000000
  • the sign bit of the float is the most significant one

Report bugs: [email protected] (original author)

[1] http://www.codercorner.com/RayAABB.cpp
[2] http://tog.acm.org/resources/GraphicsGems/gems/RayBox.c
Parameters
result:float[]

vec3

assumeIntersection:boolean

if true, method assumes an intersection, i.e. by pre-checking via intersectsRay(Ray). In this case method will not validate a possible non-intersection and just computes coordinates.

tmp1V3:float[]

temp vec3

tmp2V3:float[]

temp vec3

tmp3V3:float[]

temp vec3

Returns:float[]

float[3] result of intersection coordinates, or null if none exists

getSizeback to summary
public final float getSize()

Get the size of this AABBox where the size is represented by the length of the vector between low and high.

Returns:float

a float representing the size of the AABBox

getWidthback to summary
public final float getWidth()
hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
intersects2DRegionback to summary
public final boolean intersects2DRegion(final float x, final float y, final float w, final float h)

Check if there is a common region between this AABBox and the passed 2D region irrespective of z range

Parameters
x:float

lower left x-coord

y:float

lower left y-coord

w:float

width

h:float

hight

Returns:boolean

true if this AABBox might have a common region with this 2D region

intersectsRayback to summary
public final boolean intersectsRay(final Ray ray)

Check if Ray intersects this bounding box.

Versions uses the SAT[1], testing 6 axes. Original code for OBBs from MAGIC. Rewritten for AABBs and reorganized for early exits[2].

[1] SAT = Separating Axis Theorem
[2] http://www.codercorner.com/RayAABB.cpp
mapToWindowback to summary
public AABBox mapToWindow(final AABBox result, final float[] mat4PMv, final int[] view, final boolean useCenterZ, final float[] vec3Tmp0, final float[] vec4Tmp1, final float[] vec4Tmp2)

Assume this bounding box as being in object space and compute the window bounding box.

If useCenterZ is true, only 4 mapObjToWinCoords operations are made on points [1..4] using getCenter()'s z-value. Otherwise 8 mapObjToWinCoords operation on all 8 points are performed.

 [2] ------ [4]
  |          |
  |          |
 [1] ------ [3]
Parameters
mat4PMv:float[]

P x Mv matrix

vec3Tmp0:float[]

3 component vector for temp storage

vec4Tmp1:float[]

4 component vector for temp storage

vec4Tmp2:float[]

4 component vector for temp storage

resetback to summary
public final AABBox reset()

resets this box to the inverse low/high, allowing the next resize(float, float, float) command to hit.

Returns:AABBox

this AABBox for chaining

resizeback to summary
public final AABBox resize(final AABBox newBox)

Resize the AABBox to encapsulate another AABox

Parameters
newBox:AABBox

AABBox to be encapsulated in

Returns:AABBox

this AABBox for chaining

resizeback to summary
public final AABBox resize(final AABBox newBox, final AffineTransform t, final float[] tmpV3)

Resize the AABBox to encapsulate another AABox, which will be transformed on the fly first.

Parameters
newBox:AABBox

AABBox to be encapsulated in

t:AffineTransform

the AffineTransform applied on newBox on the fly

tmpV3:float[]

temp float[3] storage

Returns:AABBox

this AABBox for chaining

resizeback to summary
public final AABBox resize(final float x, final float y, final float z)

Resize the AABBox to encapsulate the passed xyz-coordinates.

Parameters
x:float

x-axis coordinate value

y:float

y-axis coordinate value

z:float

z-axis coordinate value

Returns:AABBox

this AABBox for chaining

resizeback to summary
public final AABBox resize(final float[] xyz, final int offset)

Resize the AABBox to encapsulate the passed xyz-coordinates.

Parameters
xyz:float[]

xyz-axis coordinate values

offset:int

of the array

Returns:AABBox

this AABBox for chaining

resizeback to summary
public final AABBox resize(final float[] xyz)

Resize the AABBox to encapsulate the passed xyz-coordinates.

Parameters
xyz:float[]

xyz-axis coordinate values

Returns:AABBox

this AABBox for chaining

rotateback to summary
public final AABBox rotate(final Quaternion quat)

Rotate this AABBox by a float[3] vector

Parameters
quat:Quaternion

the Quaternion used for rotation

Returns:AABBox

this AABBox for chaining

scaleback to summary
public final AABBox scale(final float size, final float[] tmpV3)

Scale this AABBox by a constant

Parameters
size:float

a constant float value

tmpV3:float[]

caller provided temporary 3-component vector

Returns:AABBox

this AABBox for chaining

setHighback to summary
private final void setHigh(final float hx, final float hy, final float hz)
setLowback to summary
private final void setLow(final float lx, final float ly, final float lz)
setSizeback to summary
public final AABBox setSize(final float[] low, final float[] high)

Set size of the AABBox specifying the coordinates of the low and high.

Parameters
low:float[]

min xyz-coordinates

high:float[]

max xyz-coordinates

Returns:AABBox

this AABBox for chaining

setSizeback to summary
public final AABBox setSize(final float lx, final float ly, final float lz, final float hx, final float hy, final float hz)

Set size of the AABBox specifying the coordinates of the low and high.

Parameters
lx:float

min x-coordinate

ly:float

min y-coordnate

lz:float

min z-coordinate

hx:float

max x-coordinate

hy:float

max y-coordinate

hz:float

max z-coordinate

Returns:AABBox

this AABBox for chaining

toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
translateback to summary
public final AABBox translate(final float[] t)

Translate this AABBox by a float[3] vector

Parameters
t:float[]

the float[3] translation vector

Returns:AABBox

this AABBox for chaining