13#ifdef JPH_INTERNAL_EDGE_REMOVING_COLLECTOR_DEBUG
26 static constexpr uint cMaxLocalDelayedResults = 32;
27 static constexpr uint cMaxLocalVoidedFeatures = 128;
30 inline bool IsVoided(
const SubShapeID &inSubShapeID,
Vec3 inV)
const
32 for (
const Voided &vf : mVoidedFeatures)
33 if (vf.mSubShapeID == inSubShapeID
48 mVoidedFeatures.push_back(vf);
59 mChainedCollector.AddHit(inResult);
69 VoidFeatures(inResult);
71 #ifdef JPH_INTERNAL_EDGE_REMOVING_COLLECTOR_DEBUG
80 #ifdef JPH_INTERNAL_EDGE_REMOVING_COLLECTOR_DEBUG
85 mChainedCollector(inChainedCollector)
86 #ifdef JPH_INTERNAL_EDGE_REMOVING_COLLECTOR_DEBUG
87 , mBaseOffset(inBaseOffset)
91 mVoidedFeatures.reserve(cMaxLocalVoidedFeatures);
92 mDelayedResults.reserve(cMaxLocalDelayedResults);
100 mChainedCollector.Reset();
102 mVoidedFeatures.clear();
103 mDelayedResults.clear();
110 mChainedCollector.OnBody(inBody);
118 return ChainAndVoid(inResult);
122 float triangle_normal_len = triangle_normal.
Length();
123 if (triangle_normal_len < 1e-6f)
124 return ChainAndVoid(inResult);
130 if (triangle_normal.
Dot(contact_normal) > 0.999848f * contact_normal_len * triangle_normal_len)
131 return ChainAndVoid(inResult);
134 mDelayedResults.push_back(inResult);
142 sorted_indices.
resize(mDelayedResults.size());
143 for (
uint i = 0; i <
uint(mDelayedResults.size()); ++i)
144 sorted_indices[i] = i;
145 QuickSort(sorted_indices.
begin(), sorted_indices.
end(), [
this](
uint inLHS,
uint inRHS) { return mDelayedResults[inLHS].mPenetrationDepth > mDelayedResults[inRHS].mPenetrationDepth; });
148 for (
uint i = 0; i <
uint(mDelayedResults.size()); ++i)
153 float best_dist_sq = FLT_MAX;
154 uint best_v1_idx = 0;
155 uint best_v2_idx = 0;
157 uint v1_idx = num_v - 1;
159 for (
uint v2_idx = 0; v2_idx < num_v; ++v2_idx)
162 Vec3 v1_v2 = v2 - v1;
163 float denominator = v1_v2.
LengthSq();
164 if (denominator <
Square(FLT_EPSILON))
167 float v1_len_sq = v1.LengthSq();
168 if (v1_len_sq < best_dist_sq)
170 best_dist_sq = v1_len_sq;
171 best_v1_idx = v1_idx;
172 best_v2_idx = v1_idx;
178 float fraction = -v1.Dot(v1_v2) / denominator;
179 if (fraction < 1.0e-6f)
182 float v1_len_sq = v1.LengthSq();
183 if (v1_len_sq < best_dist_sq)
185 best_dist_sq = v1_len_sq;
186 best_v1_idx = v1_idx;
187 best_v2_idx = v1_idx;
190 else if (fraction < 1.0f - 1.0e-6f)
193 Vec3 closest = v1 + fraction * v1_v2;
194 float closest_len_sq = closest.
LengthSq();
195 if (closest_len_sq < best_dist_sq)
197 best_dist_sq = closest_len_sq;
198 best_v1_idx = v1_idx;
199 best_v2_idx = v2_idx;
213 #ifdef JPH_INTERNAL_EDGE_REMOVING_COLLECTOR_DEBUG
231 mVoidedFeatures.clear();
232 mDelayedResults.clear();
239 mChainedCollector.OnBodyEnd();
243 static void sCollideShapeVsShape(
const Shape *inShape1,
const Shape *inShape2,
Vec3Arg inScale1,
Vec3Arg inScale2,
Mat44Arg inCenterOfMassTransform1,
Mat44Arg inCenterOfMassTransform2,
const SubShapeIDCreator &inSubShapeIDCreator1,
const SubShapeIDCreator &inSubShapeIDCreator2,
const CollideShapeSettings &inCollideShapeSettings,
CollideShapeCollector &ioCollector,
const ShapeFilter &inShapeFilter = { }
244#ifdef JPH_INTERNAL_EDGE_REMOVING_COLLECTOR_DEBUG
253 #ifdef JPH_INTERNAL_EDGE_REMOVING_COLLECTOR_DEBUG
257 CollisionDispatch::sCollideShapeVsShape(inShape1, inShape2, inScale1, inScale2, inCenterOfMassTransform1, inCenterOfMassTransform2, inSubShapeIDCreator1, inSubShapeIDCreator2, inCollideShapeSettings, wrapper, inShapeFilter);
268 SubShapeID mSubShapeID;
274#ifdef JPH_INTERNAL_EDGE_REMOVING_COLLECTOR_DEBUG
@ CollideWithAll
Collide with all edges. Use this when you're interested in all collisions.
Definition ActiveEdgeMode.h:14
@ CollectFaces
mShape1/2Face is desired
Definition CollectFacesMode.h:12
unsigned int uint
Definition Core.h:500
#define JPH_NAMESPACE_END
Definition Core.h:425
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
JPH_INLINE constexpr T Square(T inV)
Square a value.
Definition Math.h:55
const Vec3 Vec3Arg
Definition MathTypes.h:19
const Mat44 & Mat44Arg
Definition MathTypes.h:29
void QuickSort(Iterator inBegin, Iterator inEnd, Compare inCompare)
Implementation of the quick sort algorithm. The STL version implementation is not consistent across p...
Definition QuickSort.h:53
Vec3Arg RVec3Arg
Definition Real.h:30
Vec3 RVec3
Definition Real.h:29
@ Array
Used in attribute declaration, indicates that this is an array of objects.
Definition SerializableAttribute.h:23
CollisionCollector< CollideShapeResult, CollisionCollectorTraitsCollideShape > CollideShapeCollector
Definition Shape.h:47
void resize(size_type inNewSize)
Resize array to new length.
Definition Array.h:197
const_iterator begin() const
Iterators.
Definition Array.h:493
const_iterator end() const
Definition Array.h:498
ECollectFacesMode mCollectFacesMode
If colliding faces should be collected or only the collision point.
Definition CollideShape.h:80
JPH_OVERRIDE_NEW_DELETE EActiveEdgeMode mActiveEdgeMode
How active edges (edges that a moving object should bump into) are handled.
Definition CollideShape.h:77
Class that contains all information of two colliding shapes.
Definition CollideShape.h:19
SubShapeID mSubShapeID1
Sub shape ID that identifies the face on shape 1.
Definition CollideShape.h:63
Vec3 mContactPointOn2
Contact point on the surface of shape 2 (in world space or relative to base offset)....
Definition CollideShape.h:60
Vec3 mPenetrationAxis
Direction to move shape 2 out of collision along the shortest path (magnitude is meaningless,...
Definition CollideShape.h:61
float mPenetrationDepth
Penetration depth (move shape 2 by this distance to resolve the collision). If CollideShapeSettings::...
Definition CollideShape.h:62
Face mShape2Face
Colliding face on shape 2 (optional result, in world space or relative to base offset).
Definition CollideShape.h:67
Settings to be passed with a collision query.
Definition CollideShape.h:94
virtual void Reset()
Definition CollisionCollector.h:62
const TransformedShape * GetContext() const
Definition CollisionCollector.h:75
void UpdateEarlyOutFraction(float inFraction)
Definition CollisionCollector.h:84
static void sCollideShapeVsShape(const Shape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter={ })
Definition CollisionDispatch.h:33
Class that holds an RGBA color with 8-bits per component.
Definition Color.h:16
static const Color sGreen
Definition Color.h:71
static const Color sRed
Definition Color.h:69
static const Color sYellow
Definition Color.h:74
static DebugRenderer * sInstance
Singleton instance.
Definition DebugRenderer.h:179
Definition InternalEdgeRemovingCollector.h:25
virtual void OnBody(const Body &inBody) override
Definition InternalEdgeRemovingCollector.h:107
void Flush()
After all hits have been added, call this function to process the delayed results.
Definition InternalEdgeRemovingCollector.h:138
InternalEdgeRemovingCollector(CollideShapeCollector &inChainedCollector)
Constructor, configures a collector to be called with all the results that do not hit internal edges.
Definition InternalEdgeRemovingCollector.h:79
static void sCollideShapeVsShape(const Shape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter={ })
Version of CollisionDispatch::sCollideShapeVsShape that removes internal edges.
Definition InternalEdgeRemovingCollector.h:243
virtual void Reset() override
If you want to reuse this collector, call Reset().
Definition InternalEdgeRemovingCollector.h:96
virtual void AddHit(const CollideShapeResult &inResult) override
This function will be called for every hit found, it's up to the application to decide how to store t...
Definition InternalEdgeRemovingCollector.h:114
virtual void OnBodyEnd() override
When running a query through the NarrowPhaseQuery class, this will be called after all AddHit calls h...
Definition InternalEdgeRemovingCollector.h:236
static JPH_INLINE Mat44 sTranslation(Vec3Arg inV)
Get matrix that translates.
Definition Mat44.inl:144
Filter class.
Definition ShapeFilter.h:17
Base class for all shapes (collision volume of a body). Defines a virtual interface for collision det...
Definition Shape.h:186
size_type size() const
Returns amount of elements in the array.
Definition StaticArray.h:89
Definition SubShapeID.h:108
A sub shape id contains a path to an element (usually a triangle or other primitive type) of a compou...
Definition SubShapeID.h:23
JPH_INLINE bool IsClose(Vec3Arg inV2, float inMaxDistSq=1.0e-12f) const
Test if two vectors are close.
Definition Vec3.inl:347
JPH_INLINE float Dot(Vec3Arg inV2) const
Dot product.
Definition Vec3.inl:650
JPH_INLINE float Length() const
Length of vector.
Definition Vec3.inl:682
JPH_INLINE Vec3 NormalizedOr(Vec3Arg inZeroValue) const
Normalize vector or return inZeroValue if the length of the vector is zero.
Definition Vec3.inl:721
JPH_INLINE void StoreFloat3(Float3 *outV) const
Store 3 floats to memory.
Definition Vec3.inl:772
JPH_INLINE float LengthSq() const
Squared length of vector.
Definition Vec3.inl:666
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:103
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:135