6 : m_CenterAndRadius(vCenter)
8 m_CenterAndRadius.SetW(fRadius);
21 res.m_CenterAndRadius.Set(0.0f, 0.0f, 0.0f, -plMath::SmallEpsilon<float>());
32 PL_ASSERT_DEBUG(pPoints !=
nullptr,
"The array must not be empty.");
33 PL_ASSERT_DEBUG(uiStride >=
sizeof(
plSimdVec4f),
"The data must not overlap.");
34 PL_ASSERT_DEBUG(uiNumPoints > 0,
"The array must contain at least one point.");
41 for (plUInt32 i = 0; i < uiNumPoints; ++i)
47 res.m_CenterAndRadius = vCenter /
plSimdFloat(uiNumPoints);
52 for (plUInt32 i = 0; i < uiNumPoints; ++i)
54 const plSimdFloat fDistSQR = (*pCur - res.m_CenterAndRadius).GetLengthSquared<3>();
55 fMaxDistSquare = fMaxDistSquare.Max(fDistSQR);
60 res.m_CenterAndRadius.SetW(fMaxDistSquare.GetSqrt());
67 m_CenterAndRadius.Set(0.0f, 0.0f, 0.0f, -plMath::SmallEpsilon<float>());
77 return m_CenterAndRadius.IsNaN<4>();
82 return m_CenterAndRadius;
87 return m_CenterAndRadius.w();
97 const plSimdFloat fDist = (vPoint - m_CenterAndRadius).GetLength<3>();
99 m_CenterAndRadius.SetW(fDist.Max(
GetRadius()));
104 PL_ASSERT_DEBUG(pPoints !=
nullptr,
"The array must not be empty.");
105 PL_ASSERT_DEBUG(uiStride >=
sizeof(
plSimdVec4f),
"The data must not overlap.");
111 for (plUInt32 i = 0; i < uiNumPoints; ++i)
113 const plSimdFloat fDistSQR = (*pCur - m_CenterAndRadius).GetLengthSquared<3>();
114 fMaxDistSquare = fMaxDistSquare.Max(fDistSQR);
119 m_CenterAndRadius.SetW(fMaxDistSquare.GetSqrt().Max(
GetRadius()));
124 const plSimdFloat fReqRadius = (rhs.m_CenterAndRadius - m_CenterAndRadius).GetLength<3>() + rhs.
GetRadius();
126 m_CenterAndRadius.SetW(fReqRadius.Max(
GetRadius()));
131 plSimdVec4f newCenterAndRadius = t.TransformPosition(m_CenterAndRadius);
134 m_CenterAndRadius = newCenterAndRadius;
142 plSimdFloat maxRadius = mMat.m_col0.Dot<3>(mMat.m_col0);
143 maxRadius = maxRadius.Max(mMat.m_col1.Dot<3>(mMat.m_col1));
144 maxRadius = maxRadius.Max(mMat.m_col2.Dot<3>(mMat.m_col2));
145 radius *= maxRadius.GetSqrt();
147 m_CenterAndRadius.SetW(radius);
152 return (vPoint - m_CenterAndRadius).GetLength<3>() -
GetRadius();
157 return (rhs.m_CenterAndRadius - m_CenterAndRadius).GetLength<3>() -
GetRadius() - rhs.
GetRadius();
163 return (vPoint - m_CenterAndRadius).GetLengthSquared<3>() <= (radius * radius);
168 return (rhs.m_CenterAndRadius - m_CenterAndRadius).GetLength<3>() + rhs.
GetRadius() <=
GetRadius();
173 plSimdFloat radius = (rhs.m_CenterAndRadius + m_CenterAndRadius).w();
174 return (rhs.m_CenterAndRadius - m_CenterAndRadius).GetLengthSquared<3>() < (radius * radius);
182 return m_CenterAndRadius + (vDir * fDist);
185PL_ALWAYS_INLINE
bool plSimdBSphere::operator==(
const plSimdBSphere& rhs)
const
187 return (m_CenterAndRadius == rhs.m_CenterAndRadius).AllSet();
190PL_ALWAYS_INLINE
bool plSimdBSphere::operator!=(
const plSimdBSphere& rhs)
const
192 return (m_CenterAndRadius != rhs.m_CenterAndRadius).AnySet();
static T * AddByteOffset(T *pPtr, std::ptrdiff_t offset)
Returns the address stored in ptr plus the given byte offset iOffset, cast to type T.
Definition SimdBSphere.h:6
plSimdFloat GetRadius() const
Returns the radius.
Definition SimdBSphere_inl.h:85
plSimdFloat GetDistanceTo(const plSimdVec4f &vPoint) const
Computes the distance of the point to the sphere's surface. Returns negative values for points inside...
Definition SimdBSphere_inl.h:150
static plSimdBSphere MakeFromPoints(const plSimdVec4f *pPoints, plUInt32 uiNumPoints, plUInt32 uiStride=sizeof(plSimdVec4f))
Creates a bounding sphere around the provided points.
Definition SimdBSphere_inl.h:30
plSimdBSphere()
Default constructor does not initialize any data.
void Transform(const plSimdTransform &t)
Transforms the sphere in its local space.
Definition SimdBSphere_inl.h:129
void ExpandToInclude(const plSimdVec4f &vPoint)
Increases the sphere's radius to include this point.
Definition SimdBSphere_inl.h:95
bool Contains(const plSimdVec4f &vPoint) const
Returns true if the given point is inside the sphere.
Definition SimdBSphere_inl.h:160
static plSimdBSphere MakeInvalid(const plSimdVec4f &vCenter=plSimdVec4f::MakeZero())
Creates an 'invalid' sphere, with its center at the given position and a negative radius.
Definition SimdBSphere_inl.h:18
void SetInvalid()
Sets the bounding sphere to invalid values.
Definition SimdBSphere_inl.h:65
bool Overlaps(const plSimdBSphere &rhs) const
Checks whether the two objects overlap.
Definition SimdBSphere_inl.h:171
plSimdVec4f GetClampedPoint(const plSimdVec4f &vPoint)
Clamps the given position to the volume of the sphere. The resulting point will always be inside the ...
Definition SimdBSphere_inl.h:177
plSimdVec4f GetCenter() const
Returns the center.
Definition SimdBSphere_inl.h:80
static plSimdBSphere MakeFromCenterAndRadius(const plSimdVec4f &vCenter, const plSimdFloat &fRadius)
Creates a sphere with the provided center and radius.
Definition SimdBSphere_inl.h:25
void SetFromPoints(const plSimdVec4f *pPoints, plUInt32 uiNumPoints, plUInt32 uiStride=sizeof(plSimdVec4f))
Initializes the sphere to be the bounding sphere of all the given points.
Definition SimdBSphere_inl.h:90
bool IsNaN() const
Returns whether any value is NaN.
Definition SimdBSphere_inl.h:75
bool IsValid() const
Returns whether the sphere has valid values.
Definition SimdBSphere_inl.h:70
static plSimdBSphere MakeZero()
Creates a sphere at the origin with radius zero.
Definition SimdBSphere_inl.h:11
static plSimdFloat MakeZero()
Creates an plSimdFloat that is initialized to zero.
Definition FPUFloat_inl.h:36
A 4x4 matrix class.
Definition SimdMat4f.h:7
plSimdVec4f TransformPosition(const plSimdVec4f &v) const
Matrix-vector multiplication, assuming the 4th component of the vector is one (default behavior).
Definition SimdMat4f_inl.h:141
A 4-component SIMD vector class.
Definition SimdVec4f.h:8
static plSimdVec4f MakeZero()
Creates an plSimdVec4f that is initialized to zero.
Definition SimdVec4f_inl.h:8