3template <
typename Type>
6#if PL_ENABLED(PL_MATH_CHECK_FOR_NAN)
10 m_fSphereRadius = TypeNaN;
14template <
typename Type>
17 m_vCenter = rhs.m_vCenter;
18 m_fSphereRadius = rhs.m_fSphereRadius;
19 m_vBoxHalfExtends = rhs.m_vBoxHalfExtends;
22template <
typename Type>
25 m_vCenter = rhs.m_vCenter;
26 m_fSphereRadius = rhs.m_fSphereRadius;
27 m_vBoxHalfExtends = rhs.m_vBoxHalfExtends;
30template <
typename Type>
32 : m_vCenter(box.GetCenter())
35 m_fSphereRadius = m_vBoxHalfExtends.GetLength();
38template <
typename Type>
40 : m_vCenter(sphere.m_vCenter)
41 , m_fSphereRadius(sphere.m_fRadius)
43 m_vBoxHalfExtends.Set(m_fSphereRadius);
47template <
typename Type>
51 res.m_vCenter.SetZero();
52 res.m_fSphereRadius = 0;
53 res.m_vBoxHalfExtends.SetZero();
57template <
typename Type>
61 res.m_vCenter.SetZero();
62 res.m_fSphereRadius = -plMath::SmallEpsilon<Type>();
67template <
typename Type>
71 res.m_vCenter = vCenter;
72 res.m_fSphereRadius = fSphereRadius;
73 res.m_vBoxHalfExtends = vBoxHalfExtents;
77template <
typename Type>
89 res.m_fSphereRadius = sphere.m_fRadius;
93template <
typename Type>
99 res.m_fSphereRadius = res.m_vBoxHalfExtends.GetLength();
103template <
typename Type>
107 res.m_vCenter = sphere.m_vCenter;
108 res.m_fSphereRadius = sphere.m_fRadius;
109 res.m_vBoxHalfExtends.Set(res.m_fSphereRadius);
113template <
typename Type>
119 res.m_fSphereRadius =
plMath::Min(res.m_vBoxHalfExtends.GetLength(), (sphere.m_vCenter - res.m_vCenter).GetLength() + sphere.m_fRadius);
123template <
typename Type>
126 return (m_vCenter.IsValid() && m_fSphereRadius >= 0.0f && m_vBoxHalfExtends.IsValid() && (m_vBoxHalfExtends.x >= 0) && (m_vBoxHalfExtends.y >= 0) && (m_vBoxHalfExtends.z >= 0));
129template <
typename Type>
132 return (m_vCenter.IsNaN() || plMath::IsNaN(m_fSphereRadius) || m_vBoxHalfExtends.IsNaN());
135template <
typename Type>
141template <
typename Type>
147template <
typename Type>
151 box.m_vMin = m_vCenter - m_vBoxHalfExtends;
152 box.m_vMax = m_vCenter + m_vBoxHalfExtends;
157 const float fSphereRadiusA = (m_vCenter - result.m_vCenter).GetLength() + m_fSphereRadius;
158 const float fSphereRadiusB = (rhs.m_vCenter - result.m_vCenter).GetLength() + rhs.m_fSphereRadius;
160 m_vCenter = result.m_vCenter;
162 m_vBoxHalfExtends = result.m_vBoxHalfExtends;
165template <
typename Type>
170 m_fSphereRadius *=
plMath::Max(Scale.x, Scale.y, Scale.z);
173 for (plUInt32 i = 0; i < 9; ++i)
181template <
typename Type>
184 return lhs.m_vCenter == rhs.m_vCenter && lhs.m_vBoxHalfExtends == rhs.m_vBoxHalfExtends && lhs.m_fSphereRadius == rhs.m_fSphereRadius;
188template <
typename Type>
191 return !(lhs == rhs);
A combination of a bounding box and a bounding sphere with the same center.
Definition BoundingBoxSphere.h:12
plBoundingBoxSphereTemplate()
Default constructor does not initialize anything.
Definition BoundingBoxSphere_inl.h:4
bool IsNaN() const
Checks whether any component is NaN.
Definition BoundingBoxSphere_inl.h:130
bool IsValid() const
Checks whether the bounds is in an invalid state.
Definition BoundingBoxSphere_inl.h:124
static plBoundingBoxSphereTemplate< Type > MakeZero()
Creates an object with all zero values. These are valid bounds around the origin with no volume.
Definition BoundingBoxSphere_inl.h:48
static plBoundingBoxSphereTemplate< Type > MakeInvalid()
Creates an 'invalid' object, ie one with negative extents/radius. Invalid objects can be made valid t...
Definition BoundingBoxSphere_inl.h:58
void ExpandToInclude(const plBoundingBoxSphereTemplate &rhs)
Expands the bounds such that the given bounds are inside it.
Definition BoundingBoxSphere_inl.h:148
const plBoundingSphereTemplate< Type > GetSphere() const
Returns the bounding sphere.
Definition BoundingBoxSphere_inl.h:142
static plBoundingBoxSphereTemplate< Type > MakeFromSphere(const plBoundingSphereTemplate< Type > &sphere)
Creates an object from another bounding sphere.
Definition BoundingBoxSphere_inl.h:104
static plBoundingBoxSphereTemplate< Type > MakeFromCenterExtents(const plVec3Template< Type > &vCenter, const plVec3Template< Type > &vBoxHalfExtents, Type fSphereRadius)
Creates an object from the given center point and extents.
Definition BoundingBoxSphere_inl.h:68
const plBoundingBoxTemplate< Type > GetBox() const
Returns the bounding box.
Definition BoundingBoxSphere_inl.h:136
static plBoundingBoxSphereTemplate< Type > MakeFromBox(const plBoundingBoxTemplate< Type > &box)
Creates an object from another bounding box.
Definition BoundingBoxSphere_inl.h:94
static plBoundingBoxSphereTemplate< Type > MakeFromPoints(const plVec3Template< Type > *pPoints, plUInt32 uiNumPoints, plUInt32 uiStride=sizeof(plVec3Template< Type >))
Creates an object that contains all the provided points.
Definition BoundingBoxSphere_inl.h:78
static plBoundingBoxSphereTemplate< Type > MakeFromBoxAndSphere(const plBoundingBoxTemplate< Type > &box, const plBoundingSphereTemplate< Type > &sphere)
Creates an object from another bounding box and a sphere.
Definition BoundingBoxSphere_inl.h:114
void Transform(const plMat4Template< Type > &mTransform)
Transforms the bounds in its local space.
Definition BoundingBoxSphere_inl.h:166
An axis-aligned bounding box implementation.
Definition BoundingBox.h:12
const plVec3Template< Type > GetCenter() const
Returns the center position of the box.
Definition BoundingBox_inl.h:78
void ExpandToInclude(const plVec3Template< Type > &vPoint)
Expands the box such that the given point is inside it.
Definition BoundingBox_inl.h:108
static plBoundingBoxTemplate< Type > MakeFromPoints(const plVec3Template< Type > *pPoints, plUInt32 uiNumPoints, plUInt32 uiStride=sizeof(plVec3Template< Type >))
Creates a box around the given set of points. If uiNumPoints is zero, the returned box is invalid (sa...
Definition BoundingBox_inl.h:54
static plBoundingBoxTemplate< Type > MakeFromMinMax(const plVec3Template< Type > &vMin, const plVec3Template< Type > &vMax)
Creates a box with the given minimum and maximum values.
Definition BoundingBox_inl.h:42
const plVec3Template< Type > GetHalfExtents() const
Returns the half extents of the box along each axis.
Definition BoundingBox_inl.h:90
An implementation of a bounding sphere.
Definition BoundingSphere.h:11
static plBoundingSphereTemplate< Type > MakeFromCenterAndRadius(const plVec3Template< Type > &vCenter, Type fRadius)
Creates a sphere with the provided center and radius.
Definition BoundingSphere_inl.h:35
void ExpandToInclude(const plVec3Template< Type > &vPoint)
Increases the sphere's radius to include this point. Does NOT change its position,...
Definition BoundingSphere_inl.h:102
A 3x3 component matrix class.
Definition Mat3.h:9
const plVec3Template< Type > TransformDirection(const plVec3Template< Type > &v) const
Matrix-vector multiplication, assuming the 4th component of the vector is zero. So,...
Definition Mat3_inl.h:244
Type m_fElementsCM[9]
The matrix as a 9-element Type array (column-major)
Definition Mat3.h:22
A 4x4 component matrix class.
Definition Mat4.h:11
const plMat3Template< Type > GetRotationalPart() const
Returns the 3x3 rotational and scaling part of the matrix.
Definition Mat4_inl.h:458
const plVec3Template< Type > TransformPosition(const plVec3Template< Type > &v) const
Matrix-vector multiplication, assuming the 4th component of the vector is one (default behavior).
Definition Mat4_inl.h:347
const plVec3Template< Type > GetScalingFactors() const
Returns the 3 scaling factors that are encoded in the matrix.
Definition Mat4_inl.h:737
A 3-component vector class.
Definition Vec3.h:9
constexpr PL_ALWAYS_INLINE T Min(T f1, T f2)
Returns the smaller value, f1 or f2.
Definition Math_inl.h:27
constexpr TYPE MaxValue()
Returns the largest possible positive value (that is not infinity).
constexpr TYPE NaN()
Returns the value for NaN as the template type. Returns zero, if the type does not support NaN.
Definition Constants_inl.h:58
constexpr PL_ALWAYS_INLINE T Abs(T f)
Returns the absolute value of f.
Definition Math_inl.h:21
constexpr PL_ALWAYS_INLINE T Max(T f1, T f2)
Returns the greater value, f1 or f2.
Definition Math_inl.h:39