15#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
26#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
96#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
113 Block mTriangles[cMaxTriangles];
114 Block * mNextFree =
nullptr;
115 int mHighWatermark = 0;
129 if (mNextFree !=
nullptr)
132 t =
reinterpret_cast<Triangle *
>(&mNextFree->mTriangle);
133 mNextFree = mNextFree->mNextFree;
138 if (mHighWatermark >= cMaxTriangles)
140 t =
reinterpret_cast<Triangle *
>(&mTriangles[mHighWatermark].mTriangle);
160 Block *
tu =
reinterpret_cast<Block *
>(
inT);
161 tu->mNextFree = mNextFree;
187 return inT1->mClosestLenSq >
inT2->mClosestLenSq;
194 Triangles::push_back(
inT);
197 inT->mInQueue =
true;
200 std::push_heap(begin(), end(), sTriangleSorter);
213 std::pop_heap(begin(), end(), sTriangleSorter);
226#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
243 sLinkTriangle(
t1, 0,
t2, 2);
244 sLinkTriangle(
t1, 1,
t2, 1);
245 sLinkTriangle(
t1, 2,
t2, 0);
248 mTriangleQueue.push_back(
t1);
249 mTriangleQueue.push_back(
t2);
251#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
263 return !mTriangleQueue.empty();
269 return mTriangleQueue.PeekClosest();
275 return mTriangleQueue.PopClosest();
310#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
315#ifdef JPH_EPA_CONVEX_BUILDER_VALIDATE
337 ||
nt->mClosestLenSq < 0.0f)
338 mTriangleQueue.push_back(
nt);
348#ifdef JPH_EPA_CONVEX_BUILDER_VALIDATE
353#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
367#ifdef JPH_ENABLE_ASSERTS
370 for (
const Edge &e :
inT->mEdge)
374#if defined(JPH_EPA_CONVEX_BUILDER_VALIDATE) || defined(JPH_EPA_CONVEX_BUILDER_DRAW)
381 mFactory.FreeTriangle(
inT);
393#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
398#if defined(JPH_EPA_CONVEX_BUILDER_VALIDATE) || defined(JPH_EPA_CONVEX_BUILDER_DRAW)
400 mTriangles.push_back(
t);
423 e1.mNeighbourTriangle =
inT2;
425 e2.mNeighbourTriangle =
inT1;
433 for (
int i = 0;
i < 3; ++
i)
436 if (
edge.mNeighbourTriangle !=
nullptr)
446 edge.mNeighbourTriangle =
nullptr;
505 if (
n !=
nullptr && !
n->mRemoved)
545#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
564#ifdef JPH_EPA_CONVEX_BUILDER_VALIDATE
576 for (
int i = 0;
i < 3; ++
i)
611#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
642 for (
Vec3 p : mPositions)
657 mOffset +=
Vec3(5.0f, 0.0f, 0.0f);
695 TriangleFactory mFactory;
696 const Points & mPositions;
697 TriangleQueue mTriangleQueue;
699#if defined(JPH_EPA_CONVEX_BUILDER_VALIDATE) || defined(JPH_EPA_CONVEX_BUILDER_DRAW)
703#ifdef JPH_EPA_CONVEX_BUILDER_DRAW
717 mEdge[0].mStartIdx =
inIdx0;
718 mEdge[1].mStartIdx =
inIdx1;
719 mEdge[2].mStartIdx =
inIdx2;
722 mEdge[0].mNeighbourTriangle =
nullptr;
723 mEdge[1].mNeighbourTriangle =
nullptr;
724 mEdge[2].mNeighbourTriangle =
nullptr;
732 mCentroid = (
y0 +
y1 +
y2) / 3.0f;
758 float c_dot_n = mCentroid.Dot(mNormal);
786 mLambdaRelativeTo0 =
true;
792 mClosestPointInterior =
true;
806 float c_dot_n = mCentroid.Dot(mNormal);
832 mLambdaRelativeTo0 =
false;
836 mClosestPointInterior =
true;
std::uint8_t uint8
Definition Core.h:440
#define JPH_NAMESPACE_END
Definition Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition Core.h:361
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
AllocateFunction Allocate
Definition Memory.cpp:59
float Real
Definition Real.h:27
Class that holds an RGBA color with 8-bits per component.
Definition Color.h:16
static const Color sWhite
Definition Color.h:64
static Color sGetDistinctColor(int inIndex)
Get a visually distinct color.
Definition Color.cpp:31
static const Color sDarkGreen
Definition Color.h:53
static const Color sGrey
Definition Color.h:62
static const Color sYellow
Definition Color.h:57
virtual void DrawText3D(RVec3Arg inPosition, const string_view &inString, ColorArg inColor=Color::sWhite, float inHeight=0.5f)=0
Draw text.
void DrawMarker(RVec3Arg inPosition, ColorArg inColor, float inSize)
Draw a marker on a position.
Definition DebugRenderer.cpp:172
void DrawWireTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor)
Draw wireframe triangle.
Definition DebugRenderer.cpp:242
void DrawCoordinateSystem(RMat44Arg inTransform, float inSize=1.0f)
Draw coordinate system (3 arrows, x = red, y = green, z = blue)
Definition DebugRenderer.cpp:206
virtual void DrawGeometry(RMat44Arg inModelMatrix, const AABox &inWorldSpaceBounds, float inLODScaleSq, ColorArg inModelColor, const GeometryRef &inGeometry, ECullMode inCullMode=ECullMode::CullBackFace, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)=0
static DebugRenderer * sInstance
Singleton instance.
Definition DebugRenderer.h:168
void DrawArrow(RVec3Arg inFrom, RVec3Arg inTo, ColorArg inColor, float inSize)
Draw an arrow.
Definition DebugRenderer.cpp:184
virtual void DrawTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::Off)=0
Draw a single back face culled triangle.
Class that holds the information of an edge.
Definition EPAConvexHullBuilder.h:48
int mStartIdx
Vertex index in mPositions that indicates the start vertex of this edge.
Definition EPAConvexHullBuilder.h:54
Triangle * mNeighbourTriangle
Information about neighbouring triangle.
Definition EPAConvexHullBuilder.h:51
int mNeighbourEdge
Index in mEdge that specifies edge that this Edge is connected to.
Definition EPAConvexHullBuilder.h:52
Specialized points list that allows direct access to the size.
Definition EPAConvexHullBuilder.h:172
size_type & GetSizeRef()
Definition EPAConvexHullBuilder.h:174
Factory that creates triangles in a fixed size buffer.
Definition EPAConvexHullBuilder.h:103
Triangle * CreateTriangle(int inIdx0, int inIdx1, int inIdx2, const Vec3 *inPositions)
Allocate a new triangle with 3 indexes.
Definition EPAConvexHullBuilder.h:126
void FreeTriangle(Triangle *inT)
Free a triangle.
Definition EPAConvexHullBuilder.h:151
void Clear()
Return all triangles to the free pool.
Definition EPAConvexHullBuilder.h:119
Class that holds the information of one triangle.
Definition EPAConvexHullBuilder.h:62
Vec3 mCentroid
Center of the triangle.
Definition EPAConvexHullBuilder.h:89
bool mClosestPointInterior
Flag that indicates that the closest point from this triangle to the origin is an interior point.
Definition EPAConvexHullBuilder.h:93
bool IsFacing(Vec3Arg inPosition) const
Check if triangle is facing inPosition.
Definition EPAConvexHullBuilder.h:68
const Edge & GetNextEdge(int inIndex) const
Get the next edge of edge inIndex.
Definition EPAConvexHullBuilder.h:82
Vec3 mNormal
Normal of this triangle, length is 2 times area of triangle.
Definition EPAConvexHullBuilder.h:88
Edge mEdge[3]
3 edges of this triangle
Definition EPAConvexHullBuilder.h:87
bool IsFacingOrigin() const
Check if triangle is facing the origin.
Definition EPAConvexHullBuilder.h:75
float mClosestLenSq
Closest distance^2 from origin to triangle.
Definition EPAConvexHullBuilder.h:90
Triangle(int inIdx0, int inIdx1, int inIdx2, const Vec3 *inPositions)
Constructor.
Definition EPAConvexHullBuilder.h:713
bool mInQueue
Flag that indicates that this triangle was placed in the sorted heap (stays true after it is popped b...
Definition EPAConvexHullBuilder.h:95
float mLambda[2]
Barycentric coordinates of closest point to origin on triangle.
Definition EPAConvexHullBuilder.h:91
bool mLambdaRelativeTo0
How to calculate the closest point, true: y0 + l0 * (y1 - y0) + l1 * (y2 - y0), false: y1 + l0 * (y0 ...
Definition EPAConvexHullBuilder.h:92
bool mRemoved
Flag that indicates that triangle has been removed.
Definition EPAConvexHullBuilder.h:94
Specialized triangles list that keeps them sorted on closest distance to origin.
Definition EPAConvexHullBuilder.h:182
void push_back(Triangle *inT)
Add triangle to the list.
Definition EPAConvexHullBuilder.h:191
Triangle * PeekClosest()
Peek the next closest triangle without removing it.
Definition EPAConvexHullBuilder.h:204
Triangle * PopClosest()
Get next closest triangle.
Definition EPAConvexHullBuilder.h:210
static bool sTriangleSorter(const Triangle *inT1, const Triangle *inT2)
Function to sort triangles on closest distance to origin.
Definition EPAConvexHullBuilder.h:185
A convex hull builder specifically made for the EPA penetration depth calculation....
Definition EPAConvexHullBuilder.h:24
Triangle * PeekClosestTriangleInQueue()
Access to the next closest triangle to the origin (won't remove it from the queue).
Definition EPAConvexHullBuilder.h:267
bool HasNextTriangle() const
Check if there's another triangle to process from the queue.
Definition EPAConvexHullBuilder.h:261
static constexpr int cMaxTriangles
Max triangles in hull.
Definition EPAConvexHullBuilder.h:35
StaticArray< Edge, cMaxEdgeLength > Edges
Definition EPAConvexHullBuilder.h:57
static constexpr float cMinTriangleArea
Minimum area of a triangle before, if smaller than this it will not be added to the priority queue.
Definition EPAConvexHullBuilder.h:40
static constexpr float cBarycentricEpsilon
Epsilon value used to determine if a point is in the interior of a triangle.
Definition EPAConvexHullBuilder.h:41
static constexpr int cMaxPoints
Max number of points in hull.
Definition EPAConvexHullBuilder.h:36
Triangle * PopClosestTriangleFromQueue()
Access to the next closest triangle to the origin and remove it from the queue.
Definition EPAConvexHullBuilder.h:273
static constexpr int cMaxEdgeLength
Max number of edges in FindEdge.
Definition EPAConvexHullBuilder.h:39
void FreeTriangle(Triangle *inT)
Free a triangle.
Definition EPAConvexHullBuilder.h:365
Triangle * FindFacingTriangle(Vec3Arg inPosition, float &outBestDistSq)
Definition EPAConvexHullBuilder.h:280
void Initialize(int inIdx1, int inIdx2, int inIdx3)
Initialize the hull with 3 points.
Definition EPAConvexHullBuilder.h:233
bool AddPoint(Triangle *inFacingTriangle, int inIdx, float inClosestDistSq, NewTriangles &outTriangles)
Add a new point to the convex hull.
Definition EPAConvexHullBuilder.h:305
EPAConvexHullBuilder(const Points &inPositions)
Constructor.
Definition EPAConvexHullBuilder.h:223
StaticArray< Triangle *, cMaxTriangles > Triangles
Definition EPAConvexHullBuilder.h:168
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
static JPH_INLINE Mat44 sScale(float inScale)
Get matrix that scales uniformly.
Definition Mat44.inl:163
static JPH_INLINE Mat44 sTranslation(Vec3Arg inV)
Get matrix that translates.
Definition Mat44.inl:144
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
Simple variable length array backed by a fixed size buffer.
Definition StaticArray.h:12
T * iterator
Definition StaticArray.h:124
uint size_type
Definition StaticArray.h:16
size_type size() const
Returns amount of elements in the array.
Definition StaticArray.h:87
A simple triangle and its material.
Definition Triangle.h:11
JPH_INLINE float Dot(Vec3Arg inV2) const
Dot product.
Definition Vec3.inl:637
JPH_INLINE float Length() const
Length of vector.
Definition Vec3.inl:669
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:107
static JPH_INLINE Vec3 sReplicate(float inV)
Replicate inV across all components.
Definition Vec3.inl:118