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
    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 high
    AABBox(float lx, float ly, float lz, float hx, float hy, float hz)
    Create an AABBox specifying the coordinates of the low and high
    Create an AABBox copying all values from the given one
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    contains(float x, float y)
    Check if the x & y coordinates are bounded/contained by this AABBox
    final boolean
    contains(float x, float y, float z)
    Check if the xyz coordinates are bounded/contained by this AABBox.
    final AABBox
    copy(AABBox src)
    Copy given AABBox 'src' values to this AABBox.
    final boolean
     
    final float[]
    Get the Center of this AABBox
    final float
     
    final float
     
    final float[]
    Get the max xyz-coordinates
    final float[]
    Get the min xyz-coordinates
    final float
     
    final float
     
    final float
     
    final float
     
    final float
     
    final float
     
    final float[]
    getRayIntersection(float[] result, Ray ray, float epsilon, boolean assumeIntersection, float[] tmp1V3, float[] tmp2V3, float[] tmp3V3)
    Return intersection of a Ray with this bounding box, or null if none exist.
    final float
    Get the size of this AABBox where the size is represented by the length of the vector between low and high.
    final float
     
    final int
     
    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
    final boolean
    Check if Ray 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
    resets this box to the inverse low/high, allowing the next resize(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(AABBox newBox)
    Resize the AABBox to encapsulate another AABox
    final AABBox
    resize(AABBox newBox, jogamp.graph.geom.plane.AffineTransform t, float[] tmpV3)
    Resize the AABBox to encapsulate another AABox, which will be transformed on the fly first.
    final AABBox
    Rotate this AABBox by a float[3] vector
    final AABBox
    scale(float size, float[] tmpV3)
    Scale this AABBox by a constant
    final 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
     
    final AABBox
    translate(float[] t)
    Translate this AABBox by a float[3] vector

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • AABBox

      public AABBox()
      Create an Axis Aligned bounding box (AABBox) where the low and and high MAX float Values.
    • 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-coordinate
      ly - min y-coordnate
      lz - min z-coordinate
      hx - max x-coordinate
      hy - max y-coordinate
      hz - max z-coordinate
    • AABBox

      public AABBox(float[] low, float[] high)
      Create a AABBox defining the low and high
      Parameters:
      low - min xyz-coordinates
      high - max xyz-coordinates
  • Method Details

    • reset

      public final AABBox reset()
      resets this box to the inverse low/high, allowing the next resize(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

      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-coordinates
      high - 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-coordinate
      ly - min y-coordnate
      lz - min z-coordinate
      hx - max x-coordinate
      hy - max y-coordinate
      hz - max z-coordinate
      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, jogamp.graph.geom.plane.AffineTransform t, float[] tmpV3)
      Resize the AABBox to encapsulate another AABox, which will be transformed on the fly first.
      Parameters:
      newBox - AABBox to be encapsulated in
      t - the AffineTransform applied on newBox on the fly
      tmpV3 - temp float[3] 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 value
      y - y-axis coordinate value
      z - 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 values
      offset - 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
    • 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 value
      y - 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 value
      y - y-axis coordinate value
      z - 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-coord
      y - lower left y-coord
      w - width
      h - hight
      Returns:
      true if this AABBox might have a common region with this 2D region
    • intersectsRay

      public final boolean intersectsRay(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
       
      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 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: 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 - vec3
      ray -
      epsilon -
      assumeIntersection - 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 - temp vec3
      tmp2V3 - temp vec3
      tmp3V3 - 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

      public final AABBox scale(float size, float[] tmpV3)
      Scale this AABBox by a constant
      Parameters:
      size - a constant float value
      tmpV3 - caller provided temporary 3-component vector
      Returns:
      this AABBox for chaining
    • translate

      public final AABBox translate(float[] 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 - the Quaternion 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

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • 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 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 - P x Mv matrix
      view -
      useCenterZ -
      vec3Tmp0 - 3 component vector for temp storage
      vec4Tmp1 - 4 component vector for temp storage
      vec4Tmp2 - 4 component vector for temp storage
      Returns:
    • toString

      public final String toString()
      Overrides:
      toString in class Object