Class AABBox
- java.lang.Object
-
- com.jogamp.opengl.math.geom.AABBox
-
public class AABBox extends Object
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
Constructors Constructor Description AABBox()Create an Axis Aligned bounding box (AABBox) with the inverse low/high, allowing the nextresize(float, float, float)command to hit.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 highAABBox(AABBox src)Create an AABBox copying all values from the given one
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(float x, float y)Check if the x & y coordinates are bounded/contained by this AABBoxbooleancontains(float x, float y, float z)Check if the xyz coordinates are bounded/contained by this AABBox.AABBoxcopy(AABBox src)Copy given AABBox 'src' values to this AABBox.booleanequals(Object obj)Vec3fgetCenter()Get the Center of this AABBoxfloatgetDepth()floatgetHeight()Vec3fgetHigh()Get the max xyz-coordinatesVec3fgetLow()Get the min xyz-coordinatesfloatgetMaxX()floatgetMaxY()floatgetMaxZ()floatgetMinX()floatgetMinY()floatgetMinZ()Vec3fgetRayIntersection(Vec3f result, Ray ray, float epsilon, boolean assumeIntersection)Return intersection of aRaywith this bounding box, or null if none exist.floatgetSize()Get the size of this AABBox where the size is represented by the length of the vector between low and high.floatgetWidth()inthashCode()booleanintersects2DRegion(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 rangebooleanintersectsRay(Ray ray)Check ifRayintersects this bounding box.AABBoxmapToWindow(AABBox result, Matrix4f mat4PMv, Recti viewport, boolean useCenterZ)Assume this bounding box as being in object space and compute the window bounding box.AABBoxreset()Resets this box to the inverse low/high, allowing the nextresize(float, float, float)command to hit.AABBoxresize(float[] xyz)Resize the AABBox to encapsulate the passed xyz-coordinates.AABBoxresize(float[] xyz, int offset)Resize the AABBox to encapsulate the passed xyz-coordinates.AABBoxresize(float x, float y, float z)Resize the AABBox to encapsulate the passed xyz-coordinates.AABBoxresize(AABBox newBox)Resize the AABBox to encapsulate another AABoxAABBoxresize(AABBox newBox, AffineTransform t, Vec3f tmpV3)Resize the AABBox to encapsulate another AABox, which will be transformed on the fly first.AABBoxresize(Vec3f xyz)Resize the AABBox to encapsulate the passed xyz-coordinates.AABBoxrotate(Quaternion quat)Rotate this AABBox by a float[3] vectorAABBoxscale(float size)Scale this AABBox by a constant around fixed centerAABBoxscale2(float size)Scale this AABBox by a constant, recomputing centerAABBoxsetSize(float[] low, float[] high)Set size of the AABBox specifying the coordinates of the low and high.AABBoxsetSize(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.AABBoxsetSize(Vec3f low, Vec3f high)Set size of the AABBox specifying the coordinates of the low and high.StringtoString()AABBoxtransform(Matrix4f mat, AABBox out)Transform this box using the givenMatrix4fintooutAABBoxtransformMv(PMVMatrix pmv, AABBox out)AABBoxtranslate(float dx, float dy, float dz)Translate this AABBox by a float[3] vectorAABBoxtranslate(Vec3f t)Translate this AABBox by a float[3] vector
-
-
-
Constructor Detail
-
AABBox
public AABBox()
Create an Axis Aligned bounding box (AABBox) with the inverse low/high, allowing the nextresize(float, float, float)command to hit.The dimension, i.e.
getWidth()abdgetHeight()isFloat.isInfinite()thereafter.- See Also:
reset()
-
AABBox
public AABBox(AABBox src)
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 Detail
-
reset
public final AABBox reset()
Resets this box to the inverse low/high, allowing the nextresize(float, float, float)command to hit.The dimension, i.e.
getWidth()abdgetHeight()isFloat.isInfinite()thereafter.- Returns:
- this AABBox for chaining
-
getHigh
public final Vec3f getHigh()
Get the max xyz-coordinates- Returns:
- max xyz coordinates
-
getLow
public final Vec3f getLow()
Get the min xyz-coordinates- Returns:
- min xyz coordinates
-
copy
public final AABBox copy(AABBox src)
Copy given AABBox 'src' values to this AABBox.- Parameters:
src- source AABBox- Returns:
- this AABBox for chaining
-
setSize
public final AABBox setSize(float[] low, float[] high)
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
public 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.- 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
-
setSize
public final AABBox setSize(Vec3f low, Vec3f high)
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
-
resize
public final AABBox resize(AABBox newBox)
Resize the AABBox to encapsulate another AABox- Parameters:
newBox- AABBox to be encapsulated in- Returns:
- this AABBox for chaining
-
resize
public final AABBox resize(AABBox newBox, AffineTransform t, Vec3f tmpV3)
Resize the AABBox to encapsulate another AABox, which will be transformed on the fly first.- Parameters:
newBox- AABBox to be encapsulated int- theAffineTransformapplied on newBox on the flytmpV3- temporary storage- Returns:
- this AABBox for chaining
-
resize
public final AABBox resize(float x, float y, float z)
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
public final AABBox resize(float[] xyz, int offset)
Resize the AABBox to encapsulate the passed xyz-coordinates.- Parameters:
xyz- xyz-axis coordinate valuesoffset- of the array- Returns:
- this AABBox for chaining
-
resize
public final AABBox resize(float[] xyz)
Resize the AABBox to encapsulate the passed xyz-coordinates.- Parameters:
xyz- xyz-axis coordinate values- Returns:
- this AABBox for chaining
-
resize
public final AABBox resize(Vec3f xyz)
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
public final boolean intersectsRay(Ray ray)
Check ifRayintersects 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 Vec3f getRayIntersection(Vec3f result, Ray ray, float epsilon, boolean assumeIntersection)
Return intersection of aRaywith 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.- 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 Vec3f getCenter()
Get the Center of this AABBox- Returns:
- the xyz-coordinates of the center of the AABBox
-
scale
public final AABBox scale(float size)
Scale this AABBox by a constant around fixed centerhigh and low is recomputed by scaling its distance to fixed center.
- Parameters:
size- a constant float value- Returns:
- this AABBox for chaining
- See Also:
#scale2(float, float[])
-
scale2
public final AABBox scale2(float size)
Scale this AABBox by a constant, recomputing centerhigh and low is scaled and center recomputed.
- Parameters:
size- a constant float value- Returns:
- this AABBox for chaining
- See Also:
#scale(float, float[])
-
translate
public final AABBox translate(float dx, float dy, float dz)
Translate this AABBox by a float[3] vector- Parameters:
dx- the translation x-componentdy- the translation y-componentdz- the translation z-componentt- the float[3] translation vector- Returns:
- this AABBox for chaining
-
translate
public final AABBox translate(Vec3f t)
Translate this AABBox by a float[3] vector- Parameters:
t- the float[3] translation vector- Returns:
- this AABBox for chaining
-
rotate
public final AABBox rotate(Quaternion quat)
Rotate this AABBox by a float[3] vector- Parameters:
quat- theQuaternionused 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()
-
transform
public AABBox transform(Matrix4f mat, AABBox out)
Transform this box using the givenMatrix4fintoout
-
mapToWindow
public AABBox mapToWindow(AABBox result, Matrix4f mat4PMv, Recti viewport, boolean useCenterZ)
Assume this bounding box as being in object space and compute the window bounding box.If
useCenterZistrue, only 4mapObjToWinCoordsoperations are made on points [1..4] usinggetCenter()'s z-value. Otherwise 8mapObjToWinCoordsoperation on all 8 points are performed..z() ------ [4] | | | | .y() ------ [3]
- Parameters:
mat4PMv- [projection] x [modelview] matrix, i.e. P x Mvviewport- viewport rectangleuseCenterZ-vec3Tmp0- 3 component vector for temp storagevec4Tmp1- 4 component vector for temp storagevec4Tmp2- 4 component vector for temp storage- Returns:
-
-