3#include <Foundation/Math/BoundingBox.h>
4#include <Foundation/Math/BoundingSphere.h>
5#include <Foundation/Math/Mat3.h>
6#include <Foundation/Math/Mat4.h>
7#include <Foundation/Math/Plane.h>
9template <
typename Type>
15template <
typename Type>
19 return sphere.
Contains(GetClampedPoint(sphere.m_vCenter));
22template <
typename Type>
25 return (GetClampedPoint(sphere.m_vCenter) - sphere.m_vCenter).GetLength() - sphere.m_fRadius;
28template <
typename Type>
34template <
typename Type>
38 const plVec3 vDiffMax = rhs.m_vMax - m_vCenter;
39 const plVec3 vDiffMin = rhs.m_vMin - m_vCenter;
46 const plVec3 vMostDistantPoint = vDiffMinAbs.
CompMax(vDiffMaxAbs);
54template <
typename Type>
59 return GetDistanceTo(vPointOnBox);
62template <
typename Type>
66 const plVec3 vDiffMax = rhs.m_vMax - m_vCenter;
67 const plVec3 vDiffMin = rhs.m_vMin - m_vCenter;
74 const plVec3 vMostDistantPoint = vDiffMinAbs.
CompMax(vDiffMaxAbs);
81template <
typename Type>
87template <
typename Type>
94template <
typename Type>
97 const Type fDist = GetDistanceTo(sphere.m_vCenter);
99 if (fDist >= sphere.m_fRadius)
102 if (-fDist >= sphere.m_fRadius)
108template <
typename Type>
114 if (m_vNormal.x >= (Type)0)
116 vPos.x = box.m_vMax.x;
117 vNeg.x = box.m_vMin.x;
120 if (m_vNormal.y >= (Type)0)
122 vPos.y = box.m_vMax.y;
123 vNeg.y = box.m_vMin.y;
126 if (m_vNormal.z >= (Type)0)
128 vPos.z = box.m_vMax.z;
129 vNeg.z = box.m_vMin.z;
132 if (GetDistanceTo(vPos) <= (Type)0)
135 if (GetDistanceTo(vNeg) >= (Type)0)
141template <
typename Type>
146 if (m_vNormal.x >= (Type)0)
148 vNeg.x = box.m_vMin.x;
151 if (m_vNormal.y >= (Type)0)
153 vNeg.y = box.m_vMin.y;
156 if (m_vNormal.z >= (Type)0)
158 vNeg.z = box.m_vMin.z;
161 return GetDistanceTo(vNeg);
164template <
typename Type>
169 if (m_vNormal.x >= (Type)0)
171 vPos.x = box.m_vMax.x;
174 if (m_vNormal.y >= (Type)0)
176 vPos.y = box.m_vMax.y;
179 if (m_vNormal.z >= (Type)0)
181 vPos.z = box.m_vMax.z;
184 return GetDistanceTo(vPos);
188template <
typename Type>
191 PL_ASSERT_DEBUG(vAxis.
IsNormalized(0.1f),
"vAxis must be normalized.");
195 const Type oneminuscos = (Type)1 - cos;
197 const Type xy = vAxis.x * vAxis.y;
198 const Type xz = vAxis.x * vAxis.z;
199 const Type yz = vAxis.y * vAxis.z;
201 const Type xsin = vAxis.x * sin;
202 const Type ysin = vAxis.y * sin;
203 const Type zsin = vAxis.z * sin;
205 const Type onecos_xy = oneminuscos * xy;
206 const Type onecos_xz = oneminuscos * xz;
207 const Type onecos_yz = oneminuscos * yz;
212 res.Element(0, 0) = cos + (oneminuscos * (vAxis.x * vAxis.x));
213 res.Element(0, 1) = onecos_xy + zsin;
214 res.Element(0, 2) = onecos_xz - ysin;
217 res.Element(1, 0) = onecos_xy - zsin;
218 res.Element(1, 1) = cos + (oneminuscos * (vAxis.y * vAxis.y));
219 res.Element(1, 2) = onecos_yz + xsin;
222 res.Element(2, 0) = onecos_xz + ysin;
223 res.Element(2, 1) = onecos_yz - xsin;
224 res.Element(2, 2) = cos + (oneminuscos * (vAxis.z * vAxis.z));
229template <
typename Type>
232 const Type fDet = Element(0, 0) * (Element(2, 2) * Element(1, 1) - Element(1, 2) * Element(2, 1)) -
233 Element(0, 1) * (Element(2, 2) * Element(1, 0) - Element(1, 2) * Element(2, 0)) +
234 Element(0, 2) * (Element(2, 1) * Element(1, 0) - Element(1, 1) * Element(2, 0));
239 const Type fOneDivDet = (Type)1 / fDet;
243 Inverse.Element(0, 0) = (Element(2, 2) * Element(1, 1) - Element(1, 2) * Element(2, 1));
244 Inverse.Element(0, 1) = -(Element(2, 2) * Element(0, 1) - Element(0, 2) * Element(2, 1));
245 Inverse.Element(0, 2) = (Element(1, 2) * Element(0, 1) - Element(0, 2) * Element(1, 1));
247 Inverse.Element(1, 0) = -(Element(2, 2) * Element(1, 0) - Element(1, 2) * Element(2, 0));
248 Inverse.Element(1, 1) = (Element(2, 2) * Element(0, 0) - Element(0, 2) * Element(2, 0));
249 Inverse.Element(1, 2) = -(Element(1, 2) * Element(0, 0) - Element(0, 2) * Element(1, 0));
251 Inverse.Element(2, 0) = (Element(2, 1) * Element(1, 0) - Element(1, 1) * Element(2, 0));
252 Inverse.Element(2, 1) = -(Element(2, 1) * Element(0, 0) - Element(0, 1) * Element(2, 0));
253 Inverse.Element(2, 2) = (Element(1, 1) * Element(0, 0) - Element(0, 1) * Element(1, 0));
255 *
this = Inverse * fOneDivDet;
259template <
typename Type>
262 PL_ASSERT_DEBUG(vAxis.
IsNormalized(),
"vAxis must be normalized.");
266 const Type oneminuscos = (Type)1 - cos;
268 const Type xy = vAxis.x * vAxis.y;
269 const Type xz = vAxis.x * vAxis.z;
270 const Type yz = vAxis.y * vAxis.z;
272 const Type xsin = vAxis.x * sin;
273 const Type ysin = vAxis.y * sin;
274 const Type zsin = vAxis.z * sin;
276 const Type onecos_xy = oneminuscos * xy;
277 const Type onecos_xz = oneminuscos * xz;
278 const Type onecos_yz = oneminuscos * yz;
283 res.Element(0, 0) = cos + (oneminuscos * (vAxis.x * vAxis.x));
284 res.Element(0, 1) = onecos_xy + zsin;
285 res.Element(0, 2) = onecos_xz - ysin;
286 res.Element(0, 3) = 0;
289 res.Element(1, 0) = onecos_xy - zsin;
290 res.Element(1, 1) = cos + (oneminuscos * (vAxis.y * vAxis.y));
291 res.Element(1, 2) = onecos_yz + xsin;
292 res.Element(1, 3) = 0;
295 res.Element(2, 0) = onecos_xz + ysin;
296 res.Element(2, 1) = onecos_yz - xsin;
297 res.Element(2, 2) = cos + (oneminuscos * (vAxis.z * vAxis.z));
298 res.Element(2, 3) = 0;
301 res.Element(3, 0) = 0;
302 res.Element(3, 1) = 0;
303 res.Element(3, 2) = 0;
304 res.Element(3, 3) = 1;
309template <
typename Type>
314 const Type fDet = GetDeterminantOf4x4Matrix(*
this);
321 for (plInt32 i = 0; i < 4; ++i)
324 Inverse.Element(i, 0) = GetDeterminantOf3x3SubMatrix(*
this, i, 0) * fOneDivDet;
325 fOneDivDet = -fOneDivDet;
326 Inverse.Element(i, 1) = GetDeterminantOf3x3SubMatrix(*
this, i, 1) * fOneDivDet;
327 fOneDivDet = -fOneDivDet;
328 Inverse.Element(i, 2) = GetDeterminantOf3x3SubMatrix(*
this, i, 2) * fOneDivDet;
329 fOneDivDet = -fOneDivDet;
330 Inverse.Element(i, 3) = GetDeterminantOf3x3SubMatrix(*
this, i, 3) * fOneDivDet;
345 case plComparisonOperator::Equal:
347 case plComparisonOperator::NotEqual:
349 case plComparisonOperator::Less:
351 case plComparisonOperator::LessEqual:
353 case plComparisonOperator::Greater:
355 case plComparisonOperator::GreaterEqual:
358 PL_DEFAULT_CASE_NOT_IMPLEMENTED;
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
An axis-aligned bounding box implementation.
Definition BoundingBox.h:12
Type GetDistanceTo(const plVec3Template< Type > &vPoint) const
Returns the minimum distance from the box's surface to the point. Zero if the point is inside the box...
Definition BoundingBox_inl.h:324
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 > GetClampedPoint(const plVec3Template< Type > &vPoint) const
The given point is clamped to the volume of the box, i.e. it will be either inside the box or on its ...
Definition BoundingBox_inl.h:318
bool Contains(const plVec3Template< Type > &vPoint) const
Checks whether the given point is inside the box.
Definition BoundingBox_inl.h:162
bool Overlaps(const plBoundingBoxTemplate &rhs) const
Checks whether this box overlaps with the given box.
Definition BoundingBox_inl.h:197
const plBoundingSphereTemplate< Type > GetBoundingSphere() const
Returns a bounding sphere that encloses this box.
Definition AllClasses_inl.h:29
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
Type GetDistanceTo(const plVec3Template< Type > &vPoint) const
Computes the distance of the point to the sphere's surface. Returns negative values for points inside...
Definition BoundingSphere_inl.h:201
bool Overlaps(const plVec3Template< Type > *pPoints, plUInt32 uiNumPoints, plUInt32 uiStride=sizeof(plVec3Template< Type >)) const
Checks whether any of the given points is inside the sphere.
Definition BoundingSphere_inl.h:270
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
bool Contains(const plVec3Template< Type > &vPoint) const
Returns true if the given point is inside the sphere.
Definition BoundingSphere_inl.h:213
const plBoundingBoxTemplate< Type > GetBoundingBox() const
Returns a bounding box that encloses this sphere.
Definition AllClasses_inl.h:88
A 3x3 component matrix class.
Definition Mat3.h:9
static plMat3Template< Type > MakeAxisRotation(const plVec3Template< Type > &vAxis, plAngle angle)
Creates a matrix that is a rotation matrix around the given axis.
Definition AllClasses_inl.h:189
plResult Invert(Type fEpsilon=plMath::SmallEpsilon< Type >())
Inverts this matrix. Return value indicates whether the matrix could be Inverted.
Definition AllClasses_inl.h:230
A 4x4 component matrix class.
Definition Mat4.h:11
static plMat4Template< Type > MakeAxisRotation(const plVec3Template< Type > &vAxis, plAngle angle)
Creates a matrix that is a rotation matrix around the given axis.
Definition AllClasses_inl.h:260
plResult Invert(Type fEpsilon=plMath::SmallEpsilon< Type >())
Inverts this matrix. Return value indicates whether the matrix could be inverted.
Definition AllClasses_inl.h:310
PL_DECLARE_IF_FLOAT_TYPE bool IsNormalized(Type fEpsilon=plMath::HugeEpsilon< Type >()) const
Returns, whether the squared length of this vector is between 0.999f and 1.001f.
Definition Vec3_inl.h:121
Type GetLengthSquared() const
Returns the squared length. Faster, since no square-root is taken. Useful, if one only wants to compa...
Definition Vec3_inl.h:70
const plVec3Template< Type > CompMax(const plVec3Template< Type > &rhs) const
Returns the component-wise maximum of *this and rhs.
Definition Vec3_inl.h:326
constexpr PL_ALWAYS_INLINE T Square(T f)
Returns f * f.
Definition Math_inl.h:8
PL_ALWAYS_INLINE float Sin(plAngle a)
***** Trigonometric Functions *****
Definition MathFloat_inl.h:62
constexpr Type Invert(Type f)
Returns 1 / f.
Definition Math_inl.h:63
PL_ALWAYS_INLINE double Sqrt(double f)
Returns the square root of f.
Definition MathDouble_inl.h:99
bool IsZero(Type f, Type fEpsilon)
Checks whether the given number is close to zero.
Definition Math_inl.h:288
constexpr PL_ALWAYS_INLINE T Abs(T f)
Returns the absolute value of f.
Definition Math_inl.h:21
PL_ALWAYS_INLINE float Cos(plAngle a)
Takes an angle, returns its cosine.
Definition MathFloat_inl.h:67
static bool Compare(plComparisonOperator::Enum cmp, const T &a, const T &b)
Compares a to b with the given operator. This function only needs the == and < operator for T.
Definition AllClasses_inl.h:341
plPositionOnPlane::Enum GetObjectPosition(const plVec3Template< Type > *const pPoints, plUInt32 uiVertices) const
Returns on which side of the plane the set of points lies. Might be on both sides.
Definition Plane_inl.h:305
Type GetMaximumDistanceTo(const plBoundingBoxTemplate< Type > &box) const
Returns the maximum distance between given box and a plane.
Definition AllClasses_inl.h:165
Type GetMinimumDistanceTo(const plVec3Template< Type > *pPoints, plUInt32 uiNumPoints, plUInt32 uiStride=sizeof(plVec3Template< Type >)) const
Returns the minimum distance that any of the given points had to the plane.
Definition Plane_inl.h:431
Enum
Definition Plane.h:10
@ Spanning
Something is spanning a plane, i.e. some points are on the front and some on the back.
Definition Plane.h:14
@ Back
Something is completely on the back side of a plane.
Definition Plane.h:11
@ Front
Something is completely in front of a plane.
Definition Plane.h:12
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54