bool physx::Gu::computeCapsule_CapsuleMTD(const Capsule& capsule0, const Capsule& capsule1, PxSweepHit& hit) { using namespace Ps::aos; PxReal s,t; distanceSegmentSegmentSquared2(capsule0, capsule1, &s, &t); const PxReal radiusSum = capsule0.radius + capsule1.radius; const PxVec3 pointAtCapsule0 = capsule0.getPointAt(s); const PxVec3 pointAtCapsule1 = capsule1.getPointAt(t); const PxVec3 normal = pointAtCapsule0 - pointAtCapsule1; const PxReal lenSq = normal.magnitudeSquared(); const PxF32 len = PxSqrt(lenSq); hit.normal = normal / len; hit.distance = len - radiusSum; hit.position = pointAtCapsule1 + hit.normal * capsule1.radius; return true; }
bool physx::Gu::computeSphere_CapsuleMTD( const Sphere& sphere, const Capsule& capsule, PxSweepHit& hit) { const PxReal radiusSum = sphere.radius + capsule.radius; PxReal u; distancePointSegmentSquared(capsule, sphere.center, &u); const PxVec3 normal = capsule.getPointAt(u) - sphere.center; const PxReal lenSq = normal.magnitudeSquared(); const PxF32 d = PxSqrt(lenSq); hit.normal = normal / d; hit.distance = d - radiusSum; hit.position = sphere.center + hit.normal * sphere.radius; return true; }