jaulib v1.3.8
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
jau::math::geom::AABBox3f Class Reference

Axis Aligned Bounding Box. More...

#include <aabbox3f.hpp>

Collaboration diagram for jau::math::geom::AABBox3f:

Public Types

typedef jau::function< jau::math::Vec3f(const jau::math::Vec3f &)> transform_vec3f_func
 General purpose Vec3f transform function.
 

Public Member Functions

 AABBox3f () noexcept
 Create an Axis Aligned bounding box (aabbox3f) where the low and and high MAX float Values.
 
constexpr AABBox3f (AABBox3f &&o) noexcept=default
 
constexpr AABBox3f (const AABBox3f &o) noexcept=default
 
 AABBox3f (const Point3f &bl_, const Point3f &tr_) noexcept
 Create an aabbox3f with given bl (low) and tr (high)
 
float area2D () const noexcept
 Returns the assumed 2D area, i.e.
 
const Point3fcenter () const noexcept
 Returns computed center of this aabbox3f of low() and high().
 
bool contains (const AABBox3f &o) const noexcept
 Returns whether this aabbox3f fully contains given aabbox3f.
 
bool contains (const float x, const float y) const noexcept
 Check if the 2D point is bounded/contained by this aabbox3f.
 
bool contains (const float x, const float y, const float z) const noexcept
 Check if the 3D point is bounded/contained by this aabbox3f.
 
bool contains (const Point2f &p) const noexcept
 Check if the 2D point is bounded/contained by this aabbox3f.
 
bool contains (const Point3f &p) const noexcept
 Check if the 3D point is bounded/contained by this aabbox3f.
 
float depth () const noexcept
 
bool getRayIntersection (Vec3f &result, const Ray3f &ray, const float epsilon, const bool assumeIntersection) const noexcept
 Return intersection of a Ray with this bounding box, or false if none exist.
 
bool hasZeroArea2D () const noexcept
 Return true if get2DArea() is FloatUtil#isZero(float), considering epsilon.
 
bool hasZeroVolume () const noexcept
 Return true if getVolume() is FloatUtil#isZero(float), considering epsilon.
 
float height () const noexcept
 
const Point3fhigh () const noexcept
 Returns the maximum right-top-near (xyz) coordinate.
 
bool intersects (const AABBox3f &o) const noexcept
 Returns whether this aabbox3f intersects (partially contains) given aabbox3f.
 
bool intersects2DRegion (const float x, const float y, const float w, const float h) const noexcept
 Check if there is a common region between this AABBox and the passed 2D region irrespective of z range.
 
bool intersectsRay (const Ray3f &r) const noexcept
 Check if Ray intersects this bounding box.
 
bool intersectsRay0 (const Ray3f ray) const noexcept
 Check if Ray intersects this bounding box.
 
bool intersectsRay1 (const Ray3f &r) const noexcept
 Check if Ray intersects this bounding box.
 
const Point3flow () const noexcept
 Returns the minimum left-bottom-far (xyz) coordinate.
 
AABBox3fmapToWindow (AABBox3f &result, const Mat4f &mat4PMv, const Recti &viewport, bool useCenterZ) const noexcept
 Assume this bounding box as being in object space and compute the window bounding box.
 
AABBox3foperator= (AABBox3f &&) noexcept=default
 
AABBox3foperator= (const AABBox3f &) noexcept=default
 
AABBox3freset () noexcept
 Reset this box to the inverse low/high, allowing the next resize(float, float, float) command to hit.
 
AABBox3fresize (const AABBox3f &newBox, transform_vec3f_func &transform) noexcept
 Resize the aabbox3f to encapsulate another AABox, which will be transformed on the fly first.
 
AABBox3fresize (const AABBox3f &o) noexcept
 Resize the aabbox3f to encapsulate another AABox.
 
AABBox3fresize (const float x, const float y, const float z) noexcept
 Resize the aabbox3f to encapsulate the passed xyz-coordinates.
 
AABBox3fresize (const float xyz[]) noexcept
 Resize the aabbox3f to encapsulate the passed xyz-coordinates.
 
AABBox3fresize (const Point3f &p) noexcept
 Resize the aabbox3f to encapsulate the passed xyz-coordinates.
 
AABBox3fresizeHeight (const float deltaBottom, const float deltaTop) noexcept
 Resize height of this aabbox3f with explicit bottom- and top delta values.
 
AABBox3fresizeWidth (const float deltaLeft, const float deltaRight) noexcept
 Resize width of this aabbox3f with explicit left- and right delta values.
 
AABBox3fsetSize (const float low[], const float high[]) noexcept
 Set size of the aabbox3f specifying the coordinates of the low and high.
 
AABBox3fsetSize (const float lx, const float ly, const float lz, const float hx, const float hy, const float hz) noexcept
 Set size of the aabbox3f specifying the coordinates of the low and high.
 
AABBox3fsetSize (const Vec3f &low, const Vec3f &high) noexcept
 Set size of the aabbox3f specifying the coordinates of the low and high.
 
float size () const noexcept
 Get the size of this aabbox3f where the size is represented by the length of the vector between low and high.
 
std::string toString () const noexcept
 
AABBox3ftransform (const Mat4f &mat, AABBox3f &out) const noexcept
 Transform this box using the given Mat4f into out @endiliteral.

 
float volume () const noexcept
 Returns the volume, i.e.
 
float width () const noexcept
 

Detailed Description

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:

Definition at line 43 of file aabbox3f.hpp.

Member Typedef Documentation

◆ transform_vec3f_func

General purpose Vec3f transform function.

Definition at line 257 of file aabbox3f.hpp.

Constructor & Destructor Documentation

◆ AABBox3f() [1/4]

jau::math::geom::AABBox3f::AABBox3f ( )
inlinenoexcept

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

Definition at line 57 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ AABBox3f() [2/4]

jau::math::geom::AABBox3f::AABBox3f ( const Point3f & bl_,
const Point3f & tr_ )
inlinenoexcept

Create an aabbox3f with given bl (low) and tr (high)

Definition at line 64 of file aabbox3f.hpp.

◆ AABBox3f() [3/4]

jau::math::geom::AABBox3f::AABBox3f ( const AABBox3f & o)
constexprdefaultnoexcept

◆ AABBox3f() [4/4]

jau::math::geom::AABBox3f::AABBox3f ( AABBox3f && o)
constexprdefaultnoexcept

Member Function Documentation

◆ operator=() [1/2]

AABBox3f & jau::math::geom::AABBox3f::operator= ( const AABBox3f & )
defaultnoexcept

◆ operator=() [2/2]

AABBox3f & jau::math::geom::AABBox3f::operator= ( AABBox3f && )
defaultnoexcept

◆ reset()

AABBox3f & jau::math::geom::AABBox3f::reset ( )
inlinenoexcept

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

Returns
this aabbox3f for chaining

Definition at line 91 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ high()

const Point3f & jau::math::geom::AABBox3f::high ( ) const
inlinenoexcept

Returns the maximum right-top-near (xyz) coordinate.

Definition at line 99 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ low()

const Point3f & jau::math::geom::AABBox3f::low ( ) const
inlinenoexcept

Returns the minimum left-bottom-far (xyz) coordinate.

Definition at line 102 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ center()

const Point3f & jau::math::geom::AABBox3f::center ( ) const
inlinenoexcept

Returns computed center of this aabbox3f of low() and high().

Definition at line 105 of file aabbox3f.hpp.

◆ size()

float jau::math::geom::AABBox3f::size ( ) const
inlinenoexcept

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

Returns
a float representing the size of the aabbox3f

Definition at line 112 of file aabbox3f.hpp.

◆ width()

float jau::math::geom::AABBox3f::width ( ) const
inlinenoexcept

Definition at line 114 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ height()

float jau::math::geom::AABBox3f::height ( ) const
inlinenoexcept

Definition at line 116 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ depth()

float jau::math::geom::AABBox3f::depth ( ) const
inlinenoexcept

Definition at line 118 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ volume()

float jau::math::geom::AABBox3f::volume ( ) const
inlinenoexcept

Returns the volume, i.e.

width * height * depth

Definition at line 121 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ hasZeroVolume()

bool jau::math::geom::AABBox3f::hasZeroVolume ( ) const
inlinenoexcept

Return true if getVolume() is FloatUtil#isZero(float), considering epsilon.

Definition at line 124 of file aabbox3f.hpp.

◆ area2D()

float jau::math::geom::AABBox3f::area2D ( ) const
inlinenoexcept

Returns the assumed 2D area, i.e.

width * height while assuming low and high lies on same plane.

Definition at line 127 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ hasZeroArea2D()

bool jau::math::geom::AABBox3f::hasZeroArea2D ( ) const
inlinenoexcept

Return true if get2DArea() is FloatUtil#isZero(float), considering epsilon.

Definition at line 130 of file aabbox3f.hpp.

◆ setSize() [1/3]

AABBox3f & jau::math::geom::AABBox3f::setSize ( const float low[],
const float high[] )
inlinenoexcept

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

Parameters
lowmin xyz-coordinates
highmax xyz-coordinates
Returns
this aabbox3f for chaining

Definition at line 140 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ setSize() [2/3]

AABBox3f & jau::math::geom::AABBox3f::setSize ( const float lx,
const float ly,
const float lz,
const float hx,
const float hy,
const float hz )
inlinenoexcept

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

Parameters
lxmin x-coordinate
lymin y-coordnate
lzmin z-coordinate
hxmax x-coordinate
hymax y-coordinate
hzmax z-coordinate
Returns
this aabbox3f for chaining

Definition at line 156 of file aabbox3f.hpp.

◆ setSize() [3/3]

AABBox3f & jau::math::geom::AABBox3f::setSize ( const Vec3f & low,
const Vec3f & high )
inlinenoexcept

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

Parameters
lowmin xyz-coordinates
highmax xyz-coordinates
Returns
this aabbox3f for chaining

Definition at line 172 of file aabbox3f.hpp.

◆ resizeWidth()

AABBox3f & jau::math::geom::AABBox3f::resizeWidth ( const float deltaLeft,
const float deltaRight )
inlinenoexcept

Resize width of this aabbox3f with explicit left- and right delta values.

Parameters
deltaLeftpositive value will expand width, otherwise shrink width
deltaRightpositive value will expand width, otherwise shrink width
Returns
this aabbox3f for chaining

Definition at line 185 of file aabbox3f.hpp.

◆ resizeHeight()

AABBox3f & jau::math::geom::AABBox3f::resizeHeight ( const float deltaBottom,
const float deltaTop )
inlinenoexcept

Resize height of this aabbox3f with explicit bottom- and top delta values.

Parameters
deltaBottompositive value will expand height, otherwise shrink height
deltaToppositive value will expand height, otherwise shrink height
Returns
this aabbox3f for chaining

Definition at line 207 of file aabbox3f.hpp.

◆ resize() [1/5]

AABBox3f & jau::math::geom::AABBox3f::resize ( const AABBox3f & o)
inlinenoexcept

Resize the aabbox3f to encapsulate another AABox.

Parameters
newBoxaabbox3f to be encapsulated in
Returns
this aabbox3f for chaining

Definition at line 228 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ resize() [2/5]

AABBox3f & jau::math::geom::AABBox3f::resize ( const AABBox3f & newBox,
transform_vec3f_func & transform )
inlinenoexcept

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

Parameters
newBoxaabbox3f to be encapsulated in
transformthe transform function, applied on newBox on the fly
tmpV3temporary storage
Returns
this aabbox3f for chaining

Definition at line 266 of file aabbox3f.hpp.

◆ resize() [3/5]

AABBox3f & jau::math::geom::AABBox3f::resize ( const float x,
const float y,
const float z )
inlinenoexcept

Resize the aabbox3f to encapsulate the passed xyz-coordinates.

Parameters
xx-axis coordinate value
yy-axis coordinate value
zz-axis coordinate value
Returns
this aabbox3f for chaining

Definition at line 306 of file aabbox3f.hpp.

◆ resize() [4/5]

AABBox3f & jau::math::geom::AABBox3f::resize ( const float xyz[])
inlinenoexcept

Resize the aabbox3f to encapsulate the passed xyz-coordinates.

Parameters
xyzxyz-axis coordinate values
Returns
this aabbox3f for chaining

Definition at line 338 of file aabbox3f.hpp.

◆ resize() [5/5]

AABBox3f & jau::math::geom::AABBox3f::resize ( const Point3f & p)
inlinenoexcept

Resize the aabbox3f to encapsulate the passed xyz-coordinates.

Parameters
xyzxyz-axis coordinate values
Returns
this aabbox3f for chaining

Definition at line 348 of file aabbox3f.hpp.

◆ contains() [1/5]

bool jau::math::geom::AABBox3f::contains ( const float x,
const float y ) const
inlinenoexcept

Check if the 2D point is bounded/contained by this aabbox3f.

Returns
true if {x, y} belongs to {low, high}

Definition at line 356 of file aabbox3f.hpp.

◆ contains() [2/5]

bool jau::math::geom::AABBox3f::contains ( const Point2f & p) const
inlinenoexcept

Check if the 2D point is bounded/contained by this aabbox3f.

Returns
true if p belongs to {low, high}

Definition at line 365 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ contains() [3/5]

bool jau::math::geom::AABBox3f::contains ( const float x,
const float y,
const float z ) const
inlinenoexcept

Check if the 3D point is bounded/contained by this aabbox3f.

Returns
true if {x, y, z} belongs to {low, high}

Definition at line 371 of file aabbox3f.hpp.

◆ contains() [4/5]

bool jau::math::geom::AABBox3f::contains ( const Point3f & p) const
inlinenoexcept

Check if the 3D point is bounded/contained by this aabbox3f.

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

Definition at line 381 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ intersects()

bool jau::math::geom::AABBox3f::intersects ( const AABBox3f & o) const
inlinenoexcept

Returns whether this aabbox3f intersects (partially contains) given aabbox3f.

Definition at line 384 of file aabbox3f.hpp.

◆ contains() [5/5]

bool jau::math::geom::AABBox3f::contains ( const AABBox3f & o) const
inlinenoexcept

Returns whether this aabbox3f fully contains given aabbox3f.

Definition at line 402 of file aabbox3f.hpp.

◆ intersects2DRegion()

bool jau::math::geom::AABBox3f::intersects2DRegion ( const float x,
const float y,
const float w,
const float h ) const
inlinenoexcept

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

Parameters
xlower left x-coord
ylower left y-coord
wwidth
hhight
Returns
true if this AABBox might have a common region with this 2D region

Definition at line 420 of file aabbox3f.hpp.

◆ intersectsRay0()

bool jau::math::geom::AABBox3f::intersectsRay0 ( const Ray3f ray) const
inlinenoexcept

Check if Ray intersects this bounding box.

Versions uses the SAT[1], testing 6 axes with branching.

Original code for OBBs from MAGIC. Rewritten for AABBs and reorganized for early exits[2].

Parameters
ray
Returns
true if ray intersects with this box, otherwise false

Definition at line 451 of file aabbox3f.hpp.

◆ intersectsRay1()

bool jau::math::geom::AABBox3f::intersectsRay1 ( const Ray3f & r) const
inlinenoexcept

Check if Ray intersects this bounding box.

Fast, Branchless Ray/Bounding Box Intersections[3]

This variant of intersectsRay() is a bit slower but handles NaNs more consistently.

The idea to eliminate branches by relying on IEEE 754 floating point properties goes back to Brian Smits[1], and the implementation was fleshed out by Amy Williams. et al.[2].

Parameters
ray
Returns
true if ray intersects with this box, otherwise false

Definition at line 492 of file aabbox3f.hpp.

◆ intersectsRay()

bool jau::math::geom::AABBox3f::intersectsRay ( const Ray3f & r) const
inlinenoexcept

Check if Ray intersects this bounding box.

Fast, Branchless Ray/Bounding Box Intersections[3]

This variant of intersectsRay0() is a faster and doesn't handles NaNs perfectly. However, it may only cause false positives, which will be checked later.

The idea to eliminate branches by relying on IEEE 754 floating point properties goes back to Brian Smits[1], and the implementation was fleshed out by Amy Williams. et al.[2].

Parameters
ray
Returns
true if ray intersects with this box, otherwise false

Definition at line 533 of file aabbox3f.hpp.

◆ getRayIntersection()

bool jau::math::geom::AABBox3f::getRayIntersection ( Vec3f & result,
const Ray3f & ray,
const float epsilon,
const bool assumeIntersection ) const
inlinenoexcept

Return intersection of a Ray with this bounding box, or false 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.ter.nosp@m.dima.nosp@m.n@cod.nosp@m.erco.nosp@m.rner..nosp@m.com (original author)

Parameters
resultvec3
ray
epsilon
assumeIntersectionif 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.
Returns
true with having intersection coordinates stored in result, or false if none exists

Definition at line 578 of file aabbox3f.hpp.

◆ transform()

AABBox3f & jau::math::geom::AABBox3f::transform ( const Mat4f & mat,
AABBox3f & out ) const
inlinenoexcept

Transform this box using the given Mat4f into out @endiliteral.

Parameters
mattransformation Mat4f
outthe resulting AABBox3f
Returns
the resulting AABBox3f for chaining

Definition at line 771 of file aabbox3f.hpp.

Here is the caller graph for this function:

◆ mapToWindow()

AABBox3f & jau::math::geom::AABBox3f::mapToWindow ( AABBox3f & result,
const Mat4f & mat4PMv,
const Recti & viewport,
bool useCenterZ ) const
inlinenoexcept

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.

 .z() ------ [4]
  |          |
  |          |
 .y() ------ [3]
Parameters
mat4PMv[projection] x [modelview] matrix, i.e. P x Mv
viewportviewport rectangle
useCenterZ
vec3Tmp03 component vector for temp storage
vec4Tmp14 component vector for temp storage
vec4Tmp24 component vector for temp storage
Returns

Definition at line 803 of file aabbox3f.hpp.

◆ toString()

std::string jau::math::geom::AABBox3f::toString ( ) const
inlinenoexcept

Definition at line 840 of file aabbox3f.hpp.


The documentation for this class was generated from the following file: