| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "Prerequisites/BsPrerequisitesUtil.h" |
| 6 | #include "Math/BsVector3.h" |
| 7 | #include "Math/BsLineSegment3.h" |
| 8 | |
| 9 | namespace bs |
| 10 | { |
| 11 | /** @addtogroup Math |
| 12 | * @{ |
| 13 | */ |
| 14 | |
| 15 | /** Represents a capsule with a line segment and a radius. */ |
| 16 | class BS_UTILITY_EXPORT Capsule |
| 17 | { |
| 18 | public: |
| 19 | Capsule() = default; |
| 20 | Capsule(const LineSegment3& segment, float radius); |
| 21 | |
| 22 | /** |
| 23 | * Ray/capsule intersection. |
| 24 | * |
| 25 | * @return Boolean result and distance to the nearest intersection point. |
| 26 | */ |
| 27 | std::pair<bool, float> intersects(const Ray& ray) const; |
| 28 | |
| 29 | /** |
| 30 | * Returns the line segment along which the capsule lies. All capsule points are at equal distance from this |
| 31 | * segment. |
| 32 | */ |
| 33 | const LineSegment3& getSegment() const { return mSegment; } |
| 34 | |
| 35 | /** Returns the radius of the capsule. It defines the distance of the capsule from its line segment. */ |
| 36 | float getRadius() const { return mRadius; } |
| 37 | |
| 38 | /** |
| 39 | * Returns the height of the capsule. The height is the distance between centers of the hemispheres that form the |
| 40 | * capsule's ends. |
| 41 | */ |
| 42 | float getHeight() const { return mSegment.getLength(); } |
| 43 | |
| 44 | /** Returns the center point of the capsule. */ |
| 45 | Vector3 getCenter() const { return mSegment.getCenter(); } |
| 46 | |
| 47 | private: |
| 48 | LineSegment3 mSegment; |
| 49 | float mRadius = 0.0f; |
| 50 | }; |
| 51 | |
| 52 | /** @} */ |
| 53 | } |
| 54 | |