I added this piece of code inside PrimitiveComponent.cpp because the default UPrimitiveComponent::ComputePenetration was giving me some troubles :
bool UPrimitiveComponent::ComputePenetrationCustom(FMTDResult & OutMTD, UPrimitiveComponent& CollisionPrimitive)
{
#if WITH_PHYSX
const PxRigidActor* PRigidBody0 = CollisionPrimitive.BodyInstance.GetPxRigidActor();
if (PRigidBody0 == NULL || PRigidBody0->getNbShapes() == 0)
{
return false;
}
const PxTransform PGlobalPose0 = PRigidBody0->getGlobalPose();
const PxRigidActor* PRigidBody1 = BodyInstance.GetPxRigidActor();
if (PRigidBody1 == NULL || PRigidBody1->getNbShapes() == 0)
{
return false;
}
const PxTransform PGlobalPose1 = PRigidBody1->getGlobalPose();
// Get all the shapes from the actors
// TODO: we should really pass the shape from the overlap info since doing it this way we do an overlap test twice
TArray<PxShape*> PShapes0;
PShapes0.AddZeroed(PRigidBody0->getNbShapes());
int32 NumTargetShapes0 = PRigidBody0->getShapes(PShapes0.GetData(), PShapes0.Num());
TArray<PxShape*> PShapes1;
PShapes1.AddZeroed(PRigidBody1->getNbShapes());
int32 NumTargetShapes1 = PRigidBody1->getShapes(PShapes1.GetData(), PShapes1.Num());
for (int32 PShapeIdx0 = 0; PShapeIdx0 < PShapes0.Num(); ++PShapeIdx0)
{
const PxShape * PShape0 = PShapes0[PShapeIdx0];
check(PShape0);
// Calc shape global pose
PxTransform PGeomPose0 = PGlobalPose0.transform(PShape0->getLocalPose());
GeometryFromShapeStorage GeomStorage0;
PxGeometry * PGeom0 = GetGeometryFromShape(GeomStorage0, PShape0, true);
if (PGeom0)
{
for (int32 PShapeIdx1 = 0; PShapeIdx1 < PShapes1.Num(); ++PShapeIdx1)
{
const PxShape * PShape1 = PShapes1[PShapeIdx1];
check(PShape1);
// Calc shape global pose
PxTransform PGeomPose1 = PGlobalPose1.transform(PShape1->getLocalPose());
GeometryFromShapeStorage GeomStorage1;
PxGeometry * PGeom1 = GetGeometryFromShape(GeomStorage1, PShape1, true);
if (PGeom1)
{
PxVec3 POutDirection;
bool bSuccess = PxGeometryQuery::computePenetration(POutDirection, OutMTD.Distance, *PGeom0, PGeomPose0, *PGeom1, PGeomPose1);
if (bSuccess)
{
if (POutDirection.isFinite())
{
OutMTD.Direction = P2UVector(POutDirection);
return true;
}
else
{
UE_LOG(LogPhysics, Warning, TEXT("UPrimitiveComponent::ComputePenetration: MTD returned NaN"));
return false;
}
}
}
}
}
}
#endif
return false;
}
The code works just fine, however compiling the engine myself is a lot of extra work and time, and also I have some problems with the compiled version of the engine that I don’t have with the binary version, so I would like to move this function to my game code (not as a UPrimitiveComponent member, of course).
I have followed this tutorial on the wiki, but the compiler still complains about some classes and functions like GeometryFromShapeStorage, GetGeometryFromShape or P2UVector.
Is there any way to include those classes into my project ?