cesium-native 0.43.0
Loading...
Searching...
No Matches
OrientedBoundingBox.h
1#pragma once
2
3#include "AxisAlignedBox.h"
4#include "BoundingSphere.h"
5#include "CullingResult.h"
6#include "Library.h"
7
8#include <glm/mat3x3.hpp>
9#include <glm/vec3.hpp>
10
11namespace CesiumGeometry {
12
13class Plane;
14
22class CESIUMGEOMETRY_API OrientedBoundingBox final {
23public:
35 const glm::dvec3& center,
36 const glm::dmat3& halfAxes) noexcept
37 : _center(center),
38 _halfAxes(halfAxes),
39 // TODO: what should we do if halfAxes is singular?
40 _inverseHalfAxes(glm::inverse(halfAxes)),
41 _lengths(
42 2.0 * glm::length(_halfAxes[0]),
43 2.0 * glm::length(_halfAxes[1]),
44 2.0 * glm::length(_halfAxes[2])) {}
45
49 constexpr const glm::dvec3& getCenter() const noexcept {
50 return this->_center;
51 }
52
58 constexpr const glm::dmat3& getHalfAxes() const noexcept {
59 return this->_halfAxes;
60 }
61
66 constexpr const glm::dmat3& getInverseHalfAxes() const noexcept {
67 return this->_inverseHalfAxes;
68 }
69
73 constexpr const glm::dvec3& getLengths() const noexcept {
74 return this->_lengths;
75 }
76
87 CullingResult intersectPlane(const Plane& plane) const noexcept;
88
99 double
100 computeDistanceSquaredToPosition(const glm::dvec3& position) const noexcept;
101
109 bool contains(const glm::dvec3& position) const noexcept;
110
119 transform(const glm::dmat4& transformation) const noexcept;
120
125
129 BoundingSphere toSphere() const noexcept;
130
136 fromAxisAligned(const AxisAlignedBox& axisAligned) noexcept;
137
141 static OrientedBoundingBox fromSphere(const BoundingSphere& sphere) noexcept;
142
143private:
144 glm::dvec3 _center;
145 glm::dmat3 _halfAxes;
146 glm::dmat3 _inverseHalfAxes;
147 glm::dvec3 _lengths;
148};
149
150} // namespace CesiumGeometry
A bounding sphere with a center and a radius.
A bounding volume defined as a closed and convex cuboid with any orientation.
double computeDistanceSquaredToPosition(const glm::dvec3 &position) const noexcept
Computes the distance squared from a given position to the closest point on this bounding volume....
OrientedBoundingBox transform(const glm::dmat4 &transformation) const noexcept
Transforms this bounding box to another coordinate system using a 4x4 matrix.
constexpr const glm::dmat3 & getHalfAxes() const noexcept
Gets the three orthogonal half-axes of the bounding box. Equivalently, the transformation matrix to r...
CullingResult intersectPlane(const Plane &plane) const noexcept
Determines on which side of a plane the bounding box is located.
AxisAlignedBox toAxisAligned() const noexcept
Converts this oriented bounding box to an axis-aligned bounding box.
OrientedBoundingBox(const glm::dvec3 &center, const glm::dmat3 &halfAxes) noexcept
Constructs a new instance.
constexpr const glm::dvec3 & getCenter() const noexcept
Gets the center of the box.
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.
bool contains(const glm::dvec3 &position) const noexcept
Computes whether the given position is contained within the bounding box.
A plane in Hessian Normal Format.
Definition Plane.h:12
Basic geometry classes for Cesium.
CullingResult
The result of culling an object.
An Axis-Aligned Bounding Box (AABB), where the axes of the box are aligned with the axes of the coord...