21 AABox() : mMin(
Vec3::sReplicate(FLT_MAX)), mMax(
Vec3::sReplicate(-FLT_MAX)) { }
24 AABox(
Vec3Arg inCenter,
float inRadius) : mMin(inCenter -
Vec3::sReplicate(inRadius)), mMax(inCenter +
Vec3::sReplicate(inRadius)) { }
32 AABox box = sFromTwoPoints(
Vec3(inVertices[inTriangle.
mIdx[0]]),
Vec3(inVertices[inTriangle.
mIdx[1]]));
44 bool operator == (
const AABox &inRHS)
const {
return mMin == inRHS.
mMin && mMax == inRHS.
mMax; }
45 bool operator != (
const AABox &inRHS)
const {
return mMin != inRHS.
mMin || mMax != inRHS.
mMax; }
57 return mMin.GetX() <= mMax.GetX() && mMin.GetY() <= mMax.GetY() && mMin.GetZ() <= mMax.GetZ();
89 Encapsulate(
Vec3(inVertices[idx]));
115 return 0.5f * (mMin + mMax);
121 return 0.5f * (mMax - mMin);
133 Vec3 extent = mMax - mMin;
140 Vec3 extent = mMax - mMin;
159 return Contains(
Vec3(inOther));
173 float dist_min_normal = inPlane.
SignedDistance(GetSupport(-normal));
174 return dist_normal * dist_min_normal <= 0.0f;
180 mMin += inTranslation;
181 mMax += inTranslation;
187 mMin = (
DVec3(mMin) + inTranslation).ToVec3RoundDown();
188 mMax = (
DVec3(mMax) + inTranslation).ToVec3RoundUp();
195 Vec3 new_min, new_max;
199 for (
int c = 0; c < 3; ++c)
203 Vec3 a = col * mMin[c];
204 Vec3 b = col * mMax[c];
211 return AABox(new_min, new_max);
235 template <
class VERTEX_ARRAY>
238 outVertices.resize(4);
241 if (inDirection[axis] < 0.0f)
246 outVertices[0] =
Vec3(mMax.GetX(), mMin.GetY(), mMin.GetZ());
247 outVertices[1] =
Vec3(mMax.GetX(), mMax.GetY(), mMin.GetZ());
248 outVertices[2] =
Vec3(mMax.GetX(), mMax.GetY(), mMax.GetZ());
249 outVertices[3] =
Vec3(mMax.GetX(), mMin.GetY(), mMax.GetZ());
253 outVertices[0] =
Vec3(mMin.GetX(), mMax.GetY(), mMin.GetZ());
254 outVertices[1] =
Vec3(mMin.GetX(), mMax.GetY(), mMax.GetZ());
255 outVertices[2] =
Vec3(mMax.GetX(), mMax.GetY(), mMax.GetZ());
256 outVertices[3] =
Vec3(mMax.GetX(), mMax.GetY(), mMin.GetZ());
260 outVertices[0] =
Vec3(mMin.GetX(), mMin.GetY(), mMax.GetZ());
261 outVertices[1] =
Vec3(mMax.GetX(), mMin.GetY(), mMax.GetZ());
262 outVertices[2] =
Vec3(mMax.GetX(), mMax.GetY(), mMax.GetZ());
263 outVertices[3] =
Vec3(mMin.GetX(), mMax.GetY(), mMax.GetZ());
272 outVertices[0] =
Vec3(mMin.GetX(), mMin.GetY(), mMin.GetZ());
273 outVertices[1] =
Vec3(mMin.GetX(), mMin.GetY(), mMax.GetZ());
274 outVertices[2] =
Vec3(mMin.GetX(), mMax.GetY(), mMax.GetZ());
275 outVertices[3] =
Vec3(mMin.GetX(), mMax.GetY(), mMin.GetZ());
279 outVertices[0] =
Vec3(mMin.GetX(), mMin.GetY(), mMin.GetZ());
280 outVertices[1] =
Vec3(mMax.GetX(), mMin.GetY(), mMin.GetZ());
281 outVertices[2] =
Vec3(mMax.GetX(), mMin.GetY(), mMax.GetZ());
282 outVertices[3] =
Vec3(mMin.GetX(), mMin.GetY(), mMax.GetZ());
286 outVertices[0] =
Vec3(mMin.GetX(), mMin.GetY(), mMin.GetZ());
287 outVertices[1] =
Vec3(mMin.GetX(), mMax.GetY(), mMin.GetZ());
288 outVertices[2] =
Vec3(mMax.GetX(), mMax.GetY(), mMin.GetZ());
289 outVertices[3] =
Vec3(mMax.GetX(), mMin.GetY(), mMin.GetZ());
304 return (GetClosestPoint(inPoint) - inPoint).LengthSq();
#define JPH_NAMESPACE_END
Definition Core.h:379
std::uint32_t uint32
Definition Core.h:456
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:31
Axis aligned box.
Definition AABox.h:16
Vec3 GetExtent() const
Get extent of bounding box (half of the size)
Definition AABox.h:119
JPH_OVERRIDE_NEW_DELETE AABox()
Constructor.
Definition AABox.h:21
static AABox sBiggest()
Get bounding box of size 2 * FLT_MAX.
Definition AABox.h:38
static AABox sFromTriangle(const VertexList &inVertices, const IndexedTriangle &inTriangle)
Create box from indexed triangle.
Definition AABox.h:30
void Translate(DVec3Arg inTranslation)
Translate bounding box.
Definition AABox.h:185
AABox Scaled(Vec3Arg inScale) const
Scale this bounding box, can handle non-uniform and negative scaling.
Definition AABox.h:223
bool Contains(Vec3Arg inOther) const
Check if this box contains a point.
Definition AABox.h:151
Vec3 GetSize() const
Get size of bounding box.
Definition AABox.h:125
void EnsureMinimalEdgeLength(float inMinEdgeLength)
Make sure that each edge of the bounding box has a minimal length.
Definition AABox.h:99
Vec3 mMin
Bounding box min and max.
Definition AABox.h:308
void SetEmpty()
Reset the bounding box to an empty bounding box.
Definition AABox.h:48
AABox Intersect(const AABox &inOther) const
Intersect this bounding box with inOther, returns the intersection.
Definition AABox.h:93
void ExpandBy(Vec3Arg inVector)
Widen the box on both sides by inVector.
Definition AABox.h:106
static AABox sFromTwoPoints(Vec3Arg inP1, Vec3Arg inP2)
Create box from 2 points.
Definition AABox.h:27
void Encapsulate(const AABox &inRHS)
Encapsulate bounding box in bounding box.
Definition AABox.h:68
AABox(Vec3Arg inMin, Vec3Arg inMax)
Definition AABox.h:22
void Encapsulate(const VertexList &inVertices, const IndexedTriangle &inTriangle)
Encapsulate triangle in bounding box.
Definition AABox.h:86
AABox Transformed(DMat44Arg inMatrix) const
Transform bounding box.
Definition AABox.h:215
void GetSupportingFace(Vec3Arg inDirection, VERTEX_ARRAY &outVertices) const
Get the vertices of the face that faces inDirection the most.
Definition AABox.h:236
float GetSqDistanceTo(Vec3Arg inPoint) const
Get the squared distance between inPoint and this box (will be 0 if in Point is inside the box)
Definition AABox.h:302
AABox(Vec3Arg inCenter, float inRadius)
Definition AABox.h:24
float GetVolume() const
Get volume of bounding box.
Definition AABox.h:138
Vec3 GetClosestPoint(Vec3Arg inPoint) const
Get the closest point on or in this box to inPoint.
Definition AABox.h:296
Vec3 GetSupport(Vec3Arg inDirection) const
Calculate the support vector for this convex shape.
Definition AABox.h:229
AABox Transformed(Mat44Arg inMatrix) const
Transform bounding box.
Definition AABox.h:192
bool Overlaps(const Plane &inPlane) const
Check if this box overlaps with a plane.
Definition AABox.h:169
bool Overlaps(const AABox &inOther) const
Check if this box overlaps with another box.
Definition AABox.h:163
AABox(DVec3Arg inMin, DVec3Arg inMax)
Definition AABox.h:23
float GetSurfaceArea() const
Get surface area of bounding box.
Definition AABox.h:131
void Translate(Vec3Arg inTranslation)
Translate bounding box.
Definition AABox.h:178
bool IsValid() const
Check if the bounding box is valid (max >= min)
Definition AABox.h:55
void Encapsulate(Vec3Arg inPos)
Encapsulate point in bounding box.
Definition AABox.h:61
Vec3 GetCenter() const
Get center of bounding box.
Definition AABox.h:113
bool Contains(const AABox &inOther) const
Check if this box contains another box.
Definition AABox.h:145
bool Contains(DVec3Arg inOther) const
Check if this box contains a point.
Definition AABox.h:157
void Encapsulate(const Triangle &inRHS)
Encapsulate triangle in bounding box.
Definition AABox.h:75
Vec3 mMax
Definition AABox.h:309
Holds a 4x4 matrix of floats with the last column consisting of doubles.
Definition DMat44.h:13
JPH_INLINE DVec3 GetTranslation() const
Definition DMat44.h:111
JPH_INLINE Mat44 GetRotation() const
Get rotation part only (note: retains the first 3 values from the bottom row)
Definition DMat44.h:128
Triangle with 32-bit indices and material index.
Definition IndexedTriangle.h:73
uint32 mIdx[3]
Definition IndexedTriangle.h:68
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
JPH_INLINE Vec3 GetColumn3(uint inCol) const
Definition Mat44.h:158
JPH_INLINE Vec3 GetTranslation() const
Definition Mat44.h:152
An infinite plane described by the formula X . Normal + Constant = 0.
Definition Plane.h:11
Vec3 GetNormal() const
Definition Plane.h:30
float SignedDistance(Vec3Arg inPoint) const
Distance point to plane.
Definition Plane.h:54
A simple triangle and its material.
Definition Triangle.h:11
Float3 mV[3]
Vertices.
Definition Triangle.h:27
JPH_INLINE bool TestAnyXYZTrue() const
Test if any of X, Y or Z components are true (true is when highest bit of component is set)
Definition UVec4.inl:403
static JPH_INLINE UVec4 sAnd(UVec4Arg inV1, UVec4Arg inV2)
Logical and (component wise)
Definition UVec4.inl:202
static JPH_INLINE UVec4 sOr(UVec4Arg inV1, UVec4Arg inV2)
Logical or (component wise)
Definition UVec4.inl:174
JPH_INLINE bool TestAllXYZTrue() const
Test if X, Y and Z components are true (true is when highest bit of component is set)
Definition UVec4.inl:413
static JPH_INLINE Vec3 sMax(Vec3Arg inV1, Vec3Arg inV2)
Return the maximum of each of the components.
Definition Vec3.inl:159
static JPH_INLINE Vec3 sMin(Vec3Arg inV1, Vec3Arg inV2)
Return the minimum value of each of the components.
Definition Vec3.inl:146
JPH_INLINE float GetX() const
Get individual components.
Definition Vec3.h:124
static JPH_INLINE UVec4 sGreaterOrEqual(Vec3Arg inV1, Vec3Arg inV2)
Greater than or equal (component wise)
Definition Vec3.inl:237
static JPH_INLINE UVec4 sLessOrEqual(Vec3Arg inV1, Vec3Arg inV2)
Less than or equal (component wise)
Definition Vec3.inl:207
JPH_INLINE Vec3 Abs() const
Return the absolute value of each of the components.
Definition Vec3.inl:576
static JPH_INLINE UVec4 sGreater(Vec3Arg inV1, Vec3Arg inV2)
Greater than (component wise)
Definition Vec3.inl:222
JPH_INLINE float GetY() const
Definition Vec3.h:125
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:107
static JPH_INLINE UVec4 sLess(Vec3Arg inV1, Vec3Arg inV2)
Less than (component wise)
Definition Vec3.inl:192
static JPH_INLINE Vec3 sReplicate(float inV)
Replicate inV across all components.
Definition Vec3.inl:118
static JPH_INLINE Vec3 sSelect(Vec3Arg inNotSet, Vec3Arg inSet, UVec4Arg inControl)
Component wise select, returns inNotSet when highest bit of inControl = 0 and inSet when highest bit ...
Definition Vec3.inl:269
static JPH_INLINE Vec3 sLoadFloat3Unsafe(const Float3 &inV)
Load 3 floats from memory (reads 32 bits extra which it doesn't use)
Definition Vec3.inl:134
JPH_INLINE float GetZ() const
Definition Vec3.h:126
JPH_INLINE int GetHighestComponentIndex() const
Get index of component with highest value.
Definition Vec3.inl:571