Add OverlapConvex utility function

This commit is contained in:
Steve Streeting 2023-11-08 11:34:14 +00:00
parent 682039dd8b
commit 83f0125cf8
3 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,45 @@
#include "StevesMathHelpers.h"
#include "Chaos/CastingUtilities.h"
#include "Chaos/GeometryQueries.h"
bool StevesMathHelpers::OverlapConvex(const FKConvexElem& Convex,
const FTransform& ConvexTransform,
const FCollisionShape& Shape,
const FVector& ShapePos,
const FQuat& ShapeRot,
FMTDResult& OutResult)
{
const FPhysicsShapeAdapter ShapeAdapter(ShapeRot, Shape);
const TSharedPtr<Chaos::FConvex, ESPMode::ThreadSafe>& ChaosConvex = Convex.GetChaosConvexMesh();
if (!ChaosConvex.IsValid())
return false;
const Chaos::FImplicitObject& ShapeGeom = ShapeAdapter.GetGeometry();
const FTransform& ShapeGeomTransform = ShapeAdapter.GetGeomPose(ShapePos);
OutResult.Distance = 0;
bool bHasOverlap = false;
Chaos::FMTDInfo MTDInfo;
if (Chaos::Utilities::CastHelper(ShapeGeom,
ShapeGeomTransform,
[&](const auto& Downcast, const auto& FullGeomTransform)
{
return Chaos::OverlapQuery(*ChaosConvex.Get(),
ConvexTransform,
Downcast,
FullGeomTransform,
/*Thickness=*/
0,
&MTDInfo);
}))
{
bHasOverlap = true;
OutResult.Distance = MTDInfo.Penetration;
OutResult.Direction = MTDInfo.Normal;
}
return bHasOverlap;
}

View File

@ -1,5 +1,7 @@
#pragma once
struct FKConvexElem;
/// Helper maths routines that UE4 is missing, all static
class STEVESUEHELPERS_API StevesMathHelpers
{
@ -79,4 +81,21 @@ public:
}
return false;
}
/**
* Explicitly test the overlap of any collision shape with a convex element.
* @param Convex The convex element
* @param ConvexTransform The world transform of the convex element
* @param Shape The test shape
* @param ShapePos The test shape world position
* @param ShapeRot The test shape world rotation
* @param OutResult Details of the result if returning true
* @return Whether this shape overlaps the convex element
*/
static bool OverlapConvex(const FKConvexElem& Convex,
const FTransform& ConvexTransform,
const FCollisionShape& Shape,
const FVector& ShapePos,
const FQuat& ShapeRot,
FMTDResult& OutResult);
};

View File

@ -37,7 +37,9 @@ public class StevesUEHelpers : ModuleRules
PrivateDependencyModuleNames.AddRange(
new string[]
{
"RenderCore"
"RenderCore",
"PhysicsCore",
"Chaos"
}
);