mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 09:35:25 +00:00
Add OverlapConvex utility function
This commit is contained in:
parent
682039dd8b
commit
83f0125cf8
45
Source/StevesUEHelpers/Private/StevesMathHelpers.cpp
Normal file
45
Source/StevesUEHelpers/Private/StevesMathHelpers.cpp
Normal 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;
|
||||
}
|
@ -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);
|
||||
};
|
@ -37,7 +37,9 @@ public class StevesUEHelpers : ModuleRules
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"RenderCore"
|
||||
"RenderCore",
|
||||
"PhysicsCore",
|
||||
"Chaos"
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user