cesium-native  0.41.0
CesiumGeometry::OrientedBoundingBox Class Referencefinal

A bounding volume defined as a closed and convex cuboid with any orientation. More...

#include <CesiumGeometry/OrientedBoundingBox.h>

Public Member Functions

 OrientedBoundingBox (const glm::dvec3 &center, const glm::dmat3 &halfAxes) noexcept
 Constructs a new instance. More...
 
constexpr const glm::dvec3 & getCenter () const noexcept
 Gets the center of the box.
 
constexpr const glm::dmat3 & getHalfAxes () const noexcept
 Gets the three orthogonal half-axes of the bounding box. Equivalently, the transformation matrix to rotate and scale a 2x2x2 cube centered at the origin.
 
constexpr const glm::dmat3 & getInverseHalfAxes () const noexcept
 Gets the inverse transformation matrix, to rotate from world space to local space relative to the box.
 
constexpr const glm::dvec3 & getLengths () const noexcept
 Gets the lengths of the box on each local axis respectively.
 
CullingResult intersectPlane (const Plane &plane) const noexcept
 Determines on which side of a plane the bounding box is located. More...
 
double computeDistanceSquaredToPosition (const glm::dvec3 &position) const noexcept
 Computes the distance squared from a given position to the closest point on this bounding volume. The bounding volume and the position must be expressed in the same coordinate system. More...
 
bool contains (const glm::dvec3 &position) const noexcept
 Computes whether the given position is contained within the bounding box. More...
 
OrientedBoundingBox transform (const glm::dmat4 &transformation) const noexcept
 Transforms this bounding box to another coordinate system using a 4x4 matrix. More...
 
AxisAlignedBox toAxisAligned () const noexcept
 Converts this oriented bounding box to an axis-aligned bounding box.
 
BoundingSphere toSphere () const noexcept
 Converts this oriented bounding box to a bounding sphere.
 

Static Public Member Functions

static OrientedBoundingBox fromAxisAligned (const AxisAlignedBox &axisAligned) noexcept
 Creates an oriented bounding box from the given axis-aligned bounding box.
 
static OrientedBoundingBox fromSphere (const BoundingSphere &sphere) noexcept
 Creates an oriented bounding box from the given bounding sphere.
 

Detailed Description

A bounding volume defined as a closed and convex cuboid with any orientation.

See also
BoundingSphere
BoundingRegion

Definition at line 22 of file OrientedBoundingBox.h.

Constructor & Destructor Documentation

◆ OrientedBoundingBox()

CesiumGeometry::OrientedBoundingBox::OrientedBoundingBox ( const glm::dvec3 &  center,
const glm::dmat3 &  halfAxes 
)
inlinenoexcept

Constructs a new instance.

Parameters
centerThe center of the box.
halfAxesThe three orthogonal half-axes of the bounding box. Equivalently, the transformation matrix to rotate and scale a 2x2x2 cube centered at the origin.
// Create an OrientedBoundingBox using a transformation matrix, a position
// where the box will be translated, and a scale.
glm::dvec3 center = glm::dvec3(1.0, 0.0, 0.0);
glm::dmat3 halfAxes = glm::dmat3(
glm::dvec3(1.0, 0.0, 0.0),
glm::dvec3(0.0, 3.0, 0.0),
glm::dvec3(0.0, 0.0, 2.0));
auto obb = OrientedBoundingBox(center, halfAxes);
OrientedBoundingBox(const glm::dvec3 &center, const glm::dmat3 &halfAxes) noexcept
Constructs a new instance.

Definition at line 34 of file OrientedBoundingBox.h.

Member Function Documentation

◆ computeDistanceSquaredToPosition()

double CesiumGeometry::OrientedBoundingBox::computeDistanceSquaredToPosition ( const glm::dvec3 &  position) const
noexcept

Computes the distance squared from a given position to the closest point on this bounding volume. The bounding volume and the position must be expressed in the same coordinate system.

Parameters
positionThe position
Returns
The estimated distance squared from the bounding box to the point.
// Sort bounding boxes from back to front
glm::dvec3 cameraPosition = anyOldCameraPosition();
std::vector<OrientedBoundingBox> boxes = anyOldBoxArray();
std::sort(boxes.begin(), boxes.end(), [&cameraPosition](auto& a, auto& b) {
return a.computeDistanceSquaredToPosition(cameraPosition) >
b.computeDistanceSquaredToPosition(cameraPosition);
});

◆ contains()

bool CesiumGeometry::OrientedBoundingBox::contains ( const glm::dvec3 &  position) const
noexcept

Computes whether the given position is contained within the bounding box.

Parameters
positionThe position.
Returns
Whether the position is contained within the bounding box.

◆ intersectPlane()

CullingResult CesiumGeometry::OrientedBoundingBox::intersectPlane ( const Plane plane) const
noexcept

Determines on which side of a plane the bounding box is located.

Parameters
planeThe plane to test against.
Returns
The CullingResult:
  • Inside if the entire box is on the side of the plane the normal is pointing.
  • Outside if the entire box is on the opposite side.
  • Intersecting if the box intersects the plane.

◆ transform()

OrientedBoundingBox CesiumGeometry::OrientedBoundingBox::transform ( const glm::dmat4 &  transformation) const
noexcept

Transforms this bounding box to another coordinate system using a 4x4 matrix.

Parameters
transformationThe transformation.
Returns
The oriented bounding box in the new coordinate system.

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