-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
355 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
CesiumGeometry/include/CesiumGeometry/BoundingCylinder.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#pragma once | ||
|
||
#include "CullingResult.h" | ||
#include "Library.h" | ||
#include "OrientedBoundingBox.h" | ||
|
||
namespace CesiumGeometry { | ||
|
||
class Plane; | ||
|
||
/** | ||
* @brief A bounding volume defined as a closed and convex cylinder with any | ||
* orientation. | ||
* | ||
* NOTE: This uses a {@link OrientedBoundingBox} underneath the hood to | ||
* approximate the result, similar to the way CesiumJS approximates cylinders. | ||
* The output will not be accurate to the actual cylinder itself. | ||
* | ||
* TODO: Update this to more accurately represent a cylinder, and thus return | ||
* more accurate results. | ||
* | ||
* @see OrientedBoundingBox | ||
*/ | ||
class CESIUMGEOMETRY_API BoundingCylinder final { | ||
public: | ||
/** | ||
* @brief Construct a new instance. | ||
* | ||
* @param center The center of the cylinder. | ||
* @param halfAxes The three orthogonal half-axes of the bounding cylinder. | ||
* Equivalently, the transformation matrix to rotate and scale a cylinder with | ||
* a radius and height of 1 that is centered at the origin. | ||
* | ||
* @snippet TestBoundingCylinder.cpp Constructor | ||
*/ | ||
BoundingCylinder( | ||
const glm::dvec3& center, | ||
const glm::dmat3& halfAxes) noexcept | ||
: _box(center, halfAxes), | ||
_radius(glm::length(halfAxes[0])), | ||
_height(2.0 * glm::length(halfAxes[2])) {} | ||
|
||
/** | ||
* @brief Gets the center of the cylinder. | ||
*/ | ||
constexpr const glm::dvec3& getCenter() const noexcept { | ||
return this->_box.getCenter(); | ||
} | ||
|
||
/** | ||
* @brief Gets the three orthogonal half-axes of the cylinder. | ||
* Equivalently, the transformation matrix to rotate and scale a cylinder with | ||
* a radius and height of 1 that is centered at the origin. | ||
*/ | ||
constexpr const glm::dmat3& getHalfAxes() const noexcept { | ||
return this->_box.getHalfAxes(); | ||
} | ||
|
||
/** | ||
* @brief Gets the radius of the cylinder. | ||
*/ | ||
constexpr double getRadius() const noexcept { return this->_radius; } | ||
|
||
/** | ||
* @brief Gets the height of the cylinder. | ||
*/ | ||
constexpr double getHeight() const noexcept { return this->_height; } | ||
|
||
/** | ||
* @brief Gets the inverse transformation matrix, to rotate from world space | ||
* to local space relative to the cylinder. | ||
*/ | ||
constexpr const glm::dmat3& getInverseHalfAxes() const noexcept { | ||
return this->_box.getInverseHalfAxes(); | ||
} | ||
|
||
/** | ||
* @brief Determines on which side of a plane the bounding cylinder is | ||
* located. | ||
* | ||
* @param plane The plane to test against. | ||
* @return The {@link CullingResult}: | ||
* * `Inside` if the entire cylinder is on the side of the plane the normal | ||
* is pointing. | ||
* * `Outside` if the entire cylinder is on the opposite side. | ||
* * `Intersecting` if the cylinder intersects the plane. | ||
*/ | ||
CullingResult intersectPlane(const Plane& plane) const noexcept; | ||
|
||
/** | ||
* @brief Computes the distance squared from a given position to the closest | ||
* point on the bounding volume. The bounding volume and the position must be | ||
* expressed in the same coordinate system. | ||
* | ||
* @param position The position | ||
* @return The estimated distance squared from the bounding box to the point. | ||
*/ | ||
double | ||
computeDistanceSquaredToPosition(const glm::dvec3& position) const noexcept; | ||
|
||
/** | ||
* @brief Computes whether the given position is contained within the bounding | ||
* cylinder. | ||
* | ||
* @param position The position. | ||
* @return Whether the position is contained within the bounding cylinder. | ||
*/ | ||
bool contains(const glm::dvec3& position) const noexcept; | ||
|
||
/** | ||
* @brief Transforms this bounding cylinder to another coordinate system using | ||
* a 4x4 matrix. | ||
* | ||
* @param transformation The transformation. | ||
* @return The bounding cylinder in the new coordinate system. | ||
*/ | ||
BoundingCylinder transform(const glm::dmat4& transformation) const noexcept; | ||
|
||
private: | ||
OrientedBoundingBox _box; | ||
double _radius; | ||
double _height; | ||
}; | ||
|
||
} // namespace CesiumGeometry |
Oops, something went wrong.