Package com.jogamp.opengl.math.geom
Class AABBox
java.lang.Object
com.jogamp.opengl.math.geom.AABBox
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
-
Constructor Summary
ConstructorsConstructorDescriptionAABBox()
Create an Axis Aligned bounding box (AABBox) where the low and and high MAX float Values.AABBox
(float[] low, float[] high) Create a AABBox defining the low and highAABBox
(float lx, float ly, float lz, float hx, float hy, float hz) Create an AABBox specifying the coordinates of the low and highCreate an AABBox copying all values from the given one -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
contains
(float x, float y) Check if the x & y coordinates are bounded/contained by this AABBoxfinal boolean
contains
(float x, float y, float z) Check if the xyz coordinates are bounded/contained by this AABBox.final AABBox
Copy given AABBox 'src' values to this AABBox.final boolean
final float[]
Get the Center of this AABBoxfinal float
getDepth()
final float
final float[]
getHigh()
Get the max xyz-coordinatesfinal float[]
getLow()
Get the min xyz-coordinatesfinal float
getMaxX()
final float
getMaxY()
final float
getMaxZ()
final float
getMinX()
final float
getMinY()
final float
getMinZ()
final float[]
getRayIntersection
(float[] result, Ray ray, float epsilon, boolean assumeIntersection, float[] tmp1V3, float[] tmp2V3, float[] tmp3V3) Return intersection of aRay
with this bounding box, or null if none exist.final float
getSize()
Get the size of this AABBox where the size is represented by the length of the vector between low and high.final float
getWidth()
final int
hashCode()
final boolean
intersects2DRegion
(float x, float y, float w, float h) Check if there is a common region between this AABBox and the passed 2D region irrespective of z rangefinal boolean
intersectsRay
(Ray ray) Check ifRay
intersects this bounding box.mapToWindow
(AABBox result, float[] mat4PMv, int[] view, boolean useCenterZ, float[] vec3Tmp0, float[] vec4Tmp1, float[] vec4Tmp2) Assume this bounding box as being in object space and compute the window bounding box.final AABBox
reset()
resets this box to the inverse low/high, allowing the nextresize(float, float, float)
command to hit.final AABBox
resize
(float[] xyz) Resize the AABBox to encapsulate the passed xyz-coordinates.final AABBox
resize
(float[] xyz, int offset) Resize the AABBox to encapsulate the passed xyz-coordinates.final AABBox
resize
(float x, float y, float z) Resize the AABBox to encapsulate the passed xyz-coordinates.final AABBox
Resize the AABBox to encapsulate another AABoxfinal AABBox
Resize the AABBox to encapsulate another AABox, which will be transformed on the fly first.final AABBox
rotate
(Quaternion quat) Rotate this AABBox by a float[3] vectorfinal AABBox
scale
(float size, float[] tmpV3) Scale this AABBox by a constantfinal AABBox
setSize
(float[] low, float[] high) Set size of the AABBox specifying the coordinates of the low and high.final AABBox
setSize
(float lx, float ly, float lz, float hx, float hy, float hz) Set size of the AABBox specifying the coordinates of the low and high.final String
toString()
final AABBox
translate
(float[] t) Translate this AABBox by a float[3] vector
-
Constructor Details
-
AABBox
public AABBox()Create an Axis Aligned bounding box (AABBox) where the low and and high MAX float Values. -
AABBox
Create an AABBox copying all values from the given one- Parameters:
src
- the box value to be used for the new instance
-
AABBox
public AABBox(float lx, float ly, float lz, float hx, float hy, float hz) Create an AABBox specifying the coordinates of the low and high- Parameters:
lx
- min x-coordinately
- min y-coordnatelz
- min z-coordinatehx
- max x-coordinatehy
- max y-coordinatehz
- max z-coordinate
-
AABBox
public AABBox(float[] low, float[] high) Create a AABBox defining the low and high- Parameters:
low
- min xyz-coordinateshigh
- max xyz-coordinates
-
-
Method Details
-
reset
resets this box to the inverse low/high, allowing the nextresize(float, float, float)
command to hit.- Returns:
- this AABBox for chaining
-
getHigh
public final float[] getHigh()Get the max xyz-coordinates- Returns:
- a float array containing the max xyz coordinates
-
getLow
public final float[] getLow()Get the min xyz-coordinates- Returns:
- a float array containing the min xyz coordinates
-
copy
Copy given AABBox 'src' values to this AABBox.- Parameters:
src
- source AABBox- Returns:
- this AABBox for chaining
-
setSize
Set size of the AABBox specifying the coordinates of the low and high.- Parameters:
low
- min xyz-coordinateshigh
- max xyz-coordinates- Returns:
- this AABBox for chaining
-
setSize
Set size of the AABBox specifying the coordinates of the low and high.- Parameters:
lx
- min x-coordinately
- min y-coordnatelz
- min z-coordinatehx
- max x-coordinatehy
- max y-coordinatehz
- max z-coordinate- Returns:
- this AABBox for chaining
-
resize
Resize the AABBox to encapsulate another AABox- Parameters:
newBox
- AABBox to be encapsulated in- Returns:
- this AABBox for chaining
-
resize
Resize the AABBox to encapsulate another AABox, which will be transformed on the fly first.- Parameters:
newBox
- AABBox to be encapsulated int
- theAffineTransform
applied on newBox on the flytmpV3
- temp float[3] storage- Returns:
- this AABBox for chaining
-
resize
Resize the AABBox to encapsulate the passed xyz-coordinates.- Parameters:
x
- x-axis coordinate valuey
- y-axis coordinate valuez
- z-axis coordinate value- Returns:
- this AABBox for chaining
-
resize
Resize the AABBox to encapsulate the passed xyz-coordinates.- Parameters:
xyz
- xyz-axis coordinate valuesoffset
- of the array- Returns:
- this AABBox for chaining
-
resize
Resize the AABBox to encapsulate the passed xyz-coordinates.- Parameters:
xyz
- xyz-axis coordinate values- Returns:
- this AABBox for chaining
-
contains
public final boolean contains(float x, float y) Check if the x & y coordinates are bounded/contained by this AABBox- Parameters:
x
- x-axis coordinate valuey
- y-axis coordinate value- Returns:
- true if x belong to (low.x, high.x) and y belong to (low.y, high.y)
-
contains
public final boolean contains(float x, float y, float z) Check if the xyz coordinates are bounded/contained by this AABBox.- Parameters:
x
- x-axis coordinate valuey
- y-axis coordinate valuez
- z-axis coordinate value- 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)
-
intersects2DRegion
public final boolean intersects2DRegion(float x, float y, float w, float h) Check if there is a common region between this AABBox and the passed 2D region irrespective of z range- Parameters:
x
- lower left x-coordy
- lower left y-coordw
- widthh
- hight- Returns:
- true if this AABBox might have a common region with this 2D region
-
intersectsRay
Check ifRay
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
- Parameters:
ray
-- Returns:
-
getRayIntersection
public final float[] getRayIntersection(float[] result, Ray ray, float epsilon, boolean assumeIntersection, float[] tmp1V3, float[] tmp2V3, float[] tmp3V3) Return intersection of aRay
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: p.terdiman@codercorner.com (original author)
[1] http://www.codercorner.com/RayAABB.cpp [2] http://tog.acm.org/resources/GraphicsGems/gems/RayBox.c
- Parameters:
result
- vec3ray
-epsilon
-assumeIntersection
- if true, method assumes an intersection, i.e. by pre-checking viaintersectsRay(Ray)
. In this case method will not validate a possible non-intersection and just computes coordinates.tmp1V3
- temp vec3tmp2V3
- temp vec3tmp3V3
- temp vec3- Returns:
- float[3] result of intersection coordinates, or null if none exists
-
getSize
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:
- a float representing the size of the AABBox
-
getCenter
public final float[] getCenter()Get the Center of this AABBox- Returns:
- the xyz-coordinates of the center of the AABBox
-
scale
Scale this AABBox by a constant- Parameters:
size
- a constant float valuetmpV3
- caller provided temporary 3-component vector- Returns:
- this AABBox for chaining
-
translate
Translate this AABBox by a float[3] vector- Parameters:
t
- the float[3] translation vector- Returns:
- this AABBox for chaining
-
rotate
Rotate this AABBox by a float[3] vector- Parameters:
quat
- theQuaternion
used for rotation- Returns:
- this AABBox for chaining
-
getMinX
public final float getMinX() -
getMinY
public final float getMinY() -
getMinZ
public final float getMinZ() -
getMaxX
public final float getMaxX() -
getMaxY
public final float getMaxY() -
getMaxZ
public final float getMaxZ() -
getWidth
public final float getWidth() -
getHeight
public final float getHeight() -
getDepth
public final float getDepth() -
equals
-
hashCode
public final int hashCode() -
mapToWindow
public AABBox mapToWindow(AABBox result, float[] mat4PMv, int[] view, boolean useCenterZ, float[] vec3Tmp0, float[] vec4Tmp1, float[] vec4Tmp2) Assume this bounding box as being in object space and compute the window bounding box.If
useCenterZ
istrue
, only 4mapObjToWinCoords
operations are made on points [1..4] usinggetCenter()
's z-value. Otherwise 8mapObjToWinCoords
operation on all 8 points are performed.[2] ------ [4] | | | | [1] ------ [3]
- Parameters:
mat4PMv
- P x Mv matrixview
-useCenterZ
-vec3Tmp0
- 3 component vector for temp storagevec4Tmp1
- 4 component vector for temp storagevec4Tmp2
- 4 component vector for temp storage- Returns:
-
toString
-