Path: blob/master/thirdparty/jolt_physics/Jolt/Geometry/EPAPenetrationDepth.h
9913 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Core/StaticArray.h>7#include <Jolt/Core/Profiler.h>8#include <Jolt/Geometry/GJKClosestPoint.h>9#include <Jolt/Geometry/EPAConvexHullBuilder.h>1011//#define JPH_EPA_PENETRATION_DEPTH_DEBUG1213JPH_NAMESPACE_BEGIN1415/// Implementation of Expanding Polytope Algorithm as described in:16///17/// Proximity Queries and Penetration Depth Computation on 3D Game Objects - Gino van den Bergen18///19/// The implementation of this algorithm does not completely follow the article, instead of splitting20/// triangles at each edge as in fig. 7 in the article, we build a convex hull (removing any triangles that21/// are facing the new point, thereby avoiding the problem of getting really oblong triangles as mentioned in22/// the article).23///24/// The algorithm roughly works like:25///26/// - Start with a simplex of the Minkowski sum (difference) of two objects that was calculated by GJK27/// - This simplex should contain the origin (or else GJK would have reported: no collision)28/// - In cases where the simplex consists of 1 - 3 points, find some extra support points (of the Minkowski sum) to get to at least 4 points29/// - Convert this into a convex hull with non-zero volume (which includes the origin)30/// - A: Calculate the closest point to the origin for all triangles of the hull and take the closest one31/// - Calculate a new support point (of the Minkowski sum) in this direction and add this point to the convex hull32/// - This will remove all faces that are facing the new point and will create new triangles to fill up the hole33/// - Loop to A until no closer point found34/// - The closest point indicates the position / direction of least penetration35class EPAPenetrationDepth36{37private:38// Typedefs39static constexpr int cMaxPoints = EPAConvexHullBuilder::cMaxPoints;40static constexpr int cMaxPointsToIncludeOriginInHull = 32;41static_assert(cMaxPointsToIncludeOriginInHull < cMaxPoints);4243using Triangle = EPAConvexHullBuilder::Triangle;44using Points = EPAConvexHullBuilder::Points;4546/// The GJK algorithm, used to start the EPA algorithm47GJKClosestPoint mGJK;4849#ifdef JPH_ENABLE_ASSERTS50/// Tolerance as passed to the GJK algorithm, used for asserting.51float mGJKTolerance = 0.0f;52#endif // JPH_ENABLE_ASSERTS5354/// A list of support points for the EPA algorithm55class SupportPoints56{57public:58/// List of support points59Points mY;60Vec3 mP[cMaxPoints];61Vec3 mQ[cMaxPoints];6263/// Calculate and add new support point to the list of points64template <typename A, typename B>65Vec3 Add(const A &inA, const B &inB, Vec3Arg inDirection, int &outIndex)66{67// Get support point of the minkowski sum A - B68Vec3 p = inA.GetSupport(inDirection);69Vec3 q = inB.GetSupport(-inDirection);70Vec3 w = p - q;7172// Store new point73outIndex = mY.size();74mY.push_back(w);75mP[outIndex] = p;76mQ[outIndex] = q;7778return w;79}80};8182public:83/// Return code for GetPenetrationDepthStepGJK84enum class EStatus85{86NotColliding, ///< Returned if the objects don't collide, in this case outPointA/outPointB are invalid87Colliding, ///< Returned if the objects penetrate88Indeterminate ///< Returned if the objects penetrate further than the convex radius. In this case you need to call GetPenetrationDepthStepEPA to get the actual penetration depth.89};9091/// Calculates penetration depth between two objects, first step of two (the GJK step)92///93/// @param inAExcludingConvexRadius Object A without convex radius.94/// @param inBExcludingConvexRadius Object B without convex radius.95/// @param inConvexRadiusA Convex radius for A.96/// @param inConvexRadiusB Convex radius for B.97/// @param ioV Pass in previously returned value or (1, 0, 0). On return this value is changed to direction to move B out of collision along the shortest path (magnitude is meaningless).98/// @param inTolerance Minimal distance before A and B are considered colliding.99/// @param outPointA Position on A that has the least amount of penetration.100/// @param outPointB Position on B that has the least amount of penetration.101/// Use |outPointB - outPointA| to get the distance of penetration.102template <typename AE, typename BE>103EStatus GetPenetrationDepthStepGJK(const AE &inAExcludingConvexRadius, float inConvexRadiusA, const BE &inBExcludingConvexRadius, float inConvexRadiusB, float inTolerance, Vec3 &ioV, Vec3 &outPointA, Vec3 &outPointB)104{105JPH_PROFILE_FUNCTION();106107JPH_IF_ENABLE_ASSERTS(mGJKTolerance = inTolerance;)108109// Don't supply a zero ioV, we only want to get points on the hull of the Minkowsky sum and not internal points.110//111// Note that if the assert below triggers, it is very likely that you have a MeshShape that contains a degenerate triangle (e.g. a sliver).112// Go up a couple of levels in the call stack to see if we're indeed testing a triangle and if it is degenerate.113// If this is the case then fix the triangles you supply to the MeshShape.114JPH_ASSERT(!ioV.IsNearZero());115116// Get closest points117float combined_radius = inConvexRadiusA + inConvexRadiusB;118float combined_radius_sq = combined_radius * combined_radius;119float closest_points_dist_sq = mGJK.GetClosestPoints(inAExcludingConvexRadius, inBExcludingConvexRadius, inTolerance, combined_radius_sq, ioV, outPointA, outPointB);120if (closest_points_dist_sq > combined_radius_sq)121{122// No collision123return EStatus::NotColliding;124}125if (closest_points_dist_sq > 0.0f)126{127// Collision within convex radius, adjust points for convex radius128float v_len = sqrt(closest_points_dist_sq); // GetClosestPoints function returns |ioV|^2 when return value < FLT_MAX129outPointA += ioV * (inConvexRadiusA / v_len);130outPointB -= ioV * (inConvexRadiusB / v_len);131return EStatus::Colliding;132}133134return EStatus::Indeterminate;135}136137/// Calculates penetration depth between two objects, second step (the EPA step)138///139/// @param inAIncludingConvexRadius Object A with convex radius140/// @param inBIncludingConvexRadius Object B with convex radius141/// @param inTolerance A factor that determines the accuracy of the result. If the change of the squared distance is less than inTolerance * current_penetration_depth^2 the algorithm will terminate. Should be bigger or equal to FLT_EPSILON.142/// @param outV Direction to move B out of collision along the shortest path (magnitude is meaningless)143/// @param outPointA Position on A that has the least amount of penetration144/// @param outPointB Position on B that has the least amount of penetration145/// Use |outPointB - outPointA| to get the distance of penetration146///147/// @return False if the objects don't collide, in this case outPointA/outPointB are invalid.148/// True if the objects penetrate149template <typename AI, typename BI>150bool GetPenetrationDepthStepEPA(const AI &inAIncludingConvexRadius, const BI &inBIncludingConvexRadius, float inTolerance, Vec3 &outV, Vec3 &outPointA, Vec3 &outPointB)151{152JPH_PROFILE_FUNCTION();153154// Check that the tolerance makes sense (smaller value than this will just result in needless iterations)155JPH_ASSERT(inTolerance >= FLT_EPSILON);156157// Fetch the simplex from GJK algorithm158SupportPoints support_points;159mGJK.GetClosestPointsSimplex(support_points.mY.data(), support_points.mP, support_points.mQ, support_points.mY.GetSizeRef());160161// Fill up the amount of support points to 4162switch (support_points.mY.size())163{164case 1:165{166// 1 vertex, which must be at the origin, which is useless for our purpose167JPH_ASSERT(support_points.mY[0].IsNearZero(Square(mGJKTolerance)));168support_points.mY.pop_back();169170// Add support points in 4 directions to form a tetrahedron around the origin171int p1, p2, p3, p4;172(void)support_points.Add(inAIncludingConvexRadius, inBIncludingConvexRadius, Vec3(0, 1, 0), p1);173(void)support_points.Add(inAIncludingConvexRadius, inBIncludingConvexRadius, Vec3(-1, -1, -1), p2);174(void)support_points.Add(inAIncludingConvexRadius, inBIncludingConvexRadius, Vec3(1, -1, -1), p3);175(void)support_points.Add(inAIncludingConvexRadius, inBIncludingConvexRadius, Vec3(0, -1, 1), p4);176JPH_ASSERT(p1 == 0);177JPH_ASSERT(p2 == 1);178JPH_ASSERT(p3 == 2);179JPH_ASSERT(p4 == 3);180break;181}182183case 2:184{185// Two vertices, create 3 extra by taking perpendicular axis and rotating it around in 120 degree increments186Vec3 axis = (support_points.mY[1] - support_points.mY[0]).Normalized();187Mat44 rotation = Mat44::sRotation(axis, DegreesToRadians(120.0f));188Vec3 dir1 = axis.GetNormalizedPerpendicular();189Vec3 dir2 = rotation * dir1;190Vec3 dir3 = rotation * dir2;191int p1, p2, p3;192(void)support_points.Add(inAIncludingConvexRadius, inBIncludingConvexRadius, dir1, p1);193(void)support_points.Add(inAIncludingConvexRadius, inBIncludingConvexRadius, dir2, p2);194(void)support_points.Add(inAIncludingConvexRadius, inBIncludingConvexRadius, dir3, p3);195JPH_ASSERT(p1 == 2);196JPH_ASSERT(p2 == 3);197JPH_ASSERT(p3 == 4);198break;199}200201case 3:202case 4:203// We already have enough points204break;205}206207// Create hull out of the initial points208JPH_ASSERT(support_points.mY.size() >= 3);209EPAConvexHullBuilder hull(support_points.mY);210#ifdef JPH_EPA_CONVEX_BUILDER_DRAW211hull.DrawLabel("Build initial hull");212#endif213#ifdef JPH_EPA_PENETRATION_DEPTH_DEBUG214Trace("Init: num_points = %u", (uint)support_points.mY.size());215#endif216hull.Initialize(0, 1, 2);217for (typename Points::size_type i = 3; i < support_points.mY.size(); ++i)218{219float dist_sq;220Triangle *t = hull.FindFacingTriangle(support_points.mY[i], dist_sq);221if (t != nullptr)222{223EPAConvexHullBuilder::NewTriangles new_triangles;224if (!hull.AddPoint(t, i, FLT_MAX, new_triangles))225{226// We can't recover from a failure to add a point to the hull because the old triangles have been unlinked already.227// Assume no collision. This can happen if the shapes touch in 1 point (or plane) in which case the hull is degenerate.228return false;229}230}231}232233#ifdef JPH_EPA_CONVEX_BUILDER_DRAW234hull.DrawLabel("Complete hull");235236// Generate the hull of the Minkowski difference for visualization237MinkowskiDifference diff(inAIncludingConvexRadius, inBIncludingConvexRadius);238DebugRenderer::GeometryRef geometry = DebugRenderer::sInstance->CreateTriangleGeometryForConvex([&diff](Vec3Arg inDirection) { return diff.GetSupport(inDirection); });239hull.DrawGeometry(geometry, Color::sYellow);240241hull.DrawLabel("Ensure origin in hull");242#endif243244// Loop until we are sure that the origin is inside the hull245for (;;)246{247// Get the next closest triangle248Triangle *t = hull.PeekClosestTriangleInQueue();249250// Don't process removed triangles, just free them (because they're in a heap we don't remove them earlier since we would have to rebuild the sorted heap)251if (t->mRemoved)252{253hull.PopClosestTriangleFromQueue();254255// If we run out of triangles, we couldn't include the origin in the hull so there must be very little penetration and we report no collision.256if (!hull.HasNextTriangle())257return false;258259hull.FreeTriangle(t);260continue;261}262263// If the closest to the triangle is zero or positive, the origin is in the hull and we can proceed to the main algorithm264if (t->mClosestLenSq >= 0.0f)265break;266267#ifdef JPH_EPA_CONVEX_BUILDER_DRAW268hull.DrawLabel("Next iteration");269#endif270#ifdef JPH_EPA_PENETRATION_DEPTH_DEBUG271Trace("EncapsulateOrigin: verts = (%d, %d, %d), closest_dist_sq = %g, centroid = (%g, %g, %g), normal = (%g, %g, %g)",272t->mEdge[0].mStartIdx, t->mEdge[1].mStartIdx, t->mEdge[2].mStartIdx,273t->mClosestLenSq,274t->mCentroid.GetX(), t->mCentroid.GetY(), t->mCentroid.GetZ(),275t->mNormal.GetX(), t->mNormal.GetY(), t->mNormal.GetZ());276#endif277278// Remove the triangle from the queue before we start adding new ones (which may result in a new closest triangle at the front of the queue)279hull.PopClosestTriangleFromQueue();280281// Add a support point to get the origin inside the hull282int new_index;283Vec3 w = support_points.Add(inAIncludingConvexRadius, inBIncludingConvexRadius, t->mNormal, new_index);284285#ifdef JPH_EPA_CONVEX_BUILDER_DRAW286// Draw the point that we're adding287hull.DrawMarker(w, Color::sRed, 1.0f);288hull.DrawWireTriangle(*t, Color::sRed);289hull.DrawState();290#endif291292// Add the point to the hull, if we fail we terminate and report no collision293EPAConvexHullBuilder::NewTriangles new_triangles;294if (!t->IsFacing(w) || !hull.AddPoint(t, new_index, FLT_MAX, new_triangles))295return false;296297// The triangle is facing the support point "w" and can now be safely removed298JPH_ASSERT(t->mRemoved);299hull.FreeTriangle(t);300301// If we run out of triangles or points, we couldn't include the origin in the hull so there must be very little penetration and we report no collision.302if (!hull.HasNextTriangle() || support_points.mY.size() >= cMaxPointsToIncludeOriginInHull)303return false;304}305306#ifdef JPH_EPA_CONVEX_BUILDER_DRAW307hull.DrawLabel("Main algorithm");308#endif309310// Current closest distance to origin311float closest_dist_sq = FLT_MAX;312313// Remember last good triangle314Triangle *last = nullptr;315316// If we want to flip the penetration depth317bool flip_v_sign = false;318319// Loop until closest point found320do321{322// Get closest triangle to the origin323Triangle *t = hull.PopClosestTriangleFromQueue();324325// Don't process removed triangles, just free them (because they're in a heap we don't remove them earlier since we would have to rebuild the sorted heap)326if (t->mRemoved)327{328hull.FreeTriangle(t);329continue;330}331332#ifdef JPH_EPA_CONVEX_BUILDER_DRAW333hull.DrawLabel("Next iteration");334#endif335#ifdef JPH_EPA_PENETRATION_DEPTH_DEBUG336Trace("FindClosest: verts = (%d, %d, %d), closest_len_sq = %g, centroid = (%g, %g, %g), normal = (%g, %g, %g)",337t->mEdge[0].mStartIdx, t->mEdge[1].mStartIdx, t->mEdge[2].mStartIdx,338t->mClosestLenSq,339t->mCentroid.GetX(), t->mCentroid.GetY(), t->mCentroid.GetZ(),340t->mNormal.GetX(), t->mNormal.GetY(), t->mNormal.GetZ());341#endif342// Check if next triangle is further away than closest point, we've found the closest point343if (t->mClosestLenSq >= closest_dist_sq)344break;345346// Replace last good with this triangle347if (last != nullptr)348hull.FreeTriangle(last);349last = t;350351// Add support point in direction of normal of the plane352// Note that the article uses the closest point between the origin and plane, but this always has the exact same direction as the normal (if the origin is behind the plane)353// and this way we do less calculations and lose less precision354int new_index;355Vec3 w = support_points.Add(inAIncludingConvexRadius, inBIncludingConvexRadius, t->mNormal, new_index);356357// Project w onto the triangle normal358float dot = t->mNormal.Dot(w);359360// Check if we just found a separating axis. This can happen if the shape shrunk by convex radius and then expanded by361// convex radius is bigger then the original shape due to inaccuracies in the shrinking process.362if (dot < 0.0f)363return false;364365// Get the distance squared (along normal) to the support point366float dist_sq = Square(dot) / t->mNormal.LengthSq();367368#ifdef JPH_EPA_PENETRATION_DEPTH_DEBUG369Trace("FindClosest: w = (%g, %g, %g), dot = %g, dist_sq = %g",370w.GetX(), w.GetY(), w.GetZ(),371dot, dist_sq);372#endif373#ifdef JPH_EPA_CONVEX_BUILDER_DRAW374// Draw the point that we're adding375hull.DrawMarker(w, Color::sPurple, 1.0f);376hull.DrawWireTriangle(*t, Color::sPurple);377hull.DrawState();378#endif379380// If the error became small enough, we've converged381if (dist_sq - t->mClosestLenSq < t->mClosestLenSq * inTolerance)382{383#ifdef JPH_EPA_PENETRATION_DEPTH_DEBUG384Trace("Converged");385#endif // JPH_EPA_PENETRATION_DEPTH_DEBUG386break;387}388389// Keep track of the minimum distance390closest_dist_sq = min(closest_dist_sq, dist_sq);391392// If the triangle thinks this point is not front facing, we've reached numerical precision and we're done393if (!t->IsFacing(w))394{395#ifdef JPH_EPA_PENETRATION_DEPTH_DEBUG396Trace("Not facing triangle");397#endif // JPH_EPA_PENETRATION_DEPTH_DEBUG398break;399}400401// Add point to hull402EPAConvexHullBuilder::NewTriangles new_triangles;403if (!hull.AddPoint(t, new_index, closest_dist_sq, new_triangles))404{405#ifdef JPH_EPA_PENETRATION_DEPTH_DEBUG406Trace("Could not add point");407#endif // JPH_EPA_PENETRATION_DEPTH_DEBUG408break;409}410411// If the hull is starting to form defects then we're reaching numerical precision and we have to stop412bool has_defect = false;413for (const Triangle *nt : new_triangles)414if (nt->IsFacingOrigin())415{416has_defect = true;417break;418}419if (has_defect)420{421#ifdef JPH_EPA_PENETRATION_DEPTH_DEBUG422Trace("Has defect");423#endif // JPH_EPA_PENETRATION_DEPTH_DEBUG424// When the hull has defects it is possible that the origin has been classified on the wrong side of the triangle425// so we do an additional check to see if the penetration in the -triangle normal direction is smaller than426// the penetration in the triangle normal direction. If so we must flip the sign of the penetration depth.427Vec3 w2 = inAIncludingConvexRadius.GetSupport(-t->mNormal) - inBIncludingConvexRadius.GetSupport(t->mNormal);428float dot2 = -t->mNormal.Dot(w2);429if (dot2 < dot)430flip_v_sign = true;431break;432}433}434while (hull.HasNextTriangle() && support_points.mY.size() < cMaxPoints);435436// Determine closest points, if last == null it means the hull was a plane so there's no penetration437if (last == nullptr)438return false;439440#ifdef JPH_EPA_CONVEX_BUILDER_DRAW441hull.DrawLabel("Closest found");442hull.DrawWireTriangle(*last, Color::sWhite);443hull.DrawArrow(last->mCentroid, last->mCentroid + last->mNormal.NormalizedOr(Vec3::sZero()), Color::sWhite, 0.1f);444hull.DrawState();445#endif446447// Calculate penetration by getting the vector from the origin to the closest point on the triangle:448// distance = (centroid - origin) . normal / |normal|, closest = origin + distance * normal / |normal|449outV = (last->mCentroid.Dot(last->mNormal) / last->mNormal.LengthSq()) * last->mNormal;450451// If penetration is near zero, treat this as a non collision since we cannot find a good normal452if (outV.IsNearZero())453return false;454455// Check if we have to flip the sign of the penetration depth456if (flip_v_sign)457outV = -outV;458459// Use the barycentric coordinates for the closest point to the origin to find the contact points on A and B460Vec3 p0 = support_points.mP[last->mEdge[0].mStartIdx];461Vec3 p1 = support_points.mP[last->mEdge[1].mStartIdx];462Vec3 p2 = support_points.mP[last->mEdge[2].mStartIdx];463464Vec3 q0 = support_points.mQ[last->mEdge[0].mStartIdx];465Vec3 q1 = support_points.mQ[last->mEdge[1].mStartIdx];466Vec3 q2 = support_points.mQ[last->mEdge[2].mStartIdx];467468if (last->mLambdaRelativeTo0)469{470// y0 was the reference vertex471outPointA = p0 + last->mLambda[0] * (p1 - p0) + last->mLambda[1] * (p2 - p0);472outPointB = q0 + last->mLambda[0] * (q1 - q0) + last->mLambda[1] * (q2 - q0);473}474else475{476// y1 was the reference vertex477outPointA = p1 + last->mLambda[0] * (p0 - p1) + last->mLambda[1] * (p2 - p1);478outPointB = q1 + last->mLambda[0] * (q0 - q1) + last->mLambda[1] * (q2 - q1);479}480481return true;482}483484/// This function combines the GJK and EPA steps and is provided as a convenience function.485/// Note: less performant since you're providing all support functions in one go486/// Note 2: You need to initialize ioV, see documentation at GetPenetrationDepthStepGJK!487template <typename AE, typename AI, typename BE, typename BI>488bool GetPenetrationDepth(const AE &inAExcludingConvexRadius, const AI &inAIncludingConvexRadius, float inConvexRadiusA, const BE &inBExcludingConvexRadius, const BI &inBIncludingConvexRadius, float inConvexRadiusB, float inCollisionToleranceSq, float inPenetrationTolerance, Vec3 &ioV, Vec3 &outPointA, Vec3 &outPointB)489{490// Check result of collision detection491switch (GetPenetrationDepthStepGJK(inAExcludingConvexRadius, inConvexRadiusA, inBExcludingConvexRadius, inConvexRadiusB, inCollisionToleranceSq, ioV, outPointA, outPointB))492{493case EPAPenetrationDepth::EStatus::Colliding:494return true;495496case EPAPenetrationDepth::EStatus::NotColliding:497return false;498499case EPAPenetrationDepth::EStatus::Indeterminate:500return GetPenetrationDepthStepEPA(inAIncludingConvexRadius, inBIncludingConvexRadius, inPenetrationTolerance, ioV, outPointA, outPointB);501}502503JPH_ASSERT(false);504return false;505}506507/// Test if a cast shape inA moving from inStart to lambda * inStart.GetTranslation() + inDirection where lambda e [0, ioLambda> intersects inB508///509/// @param inStart Start position and orientation of the convex object510/// @param inDirection Direction of the sweep (ioLambda * inDirection determines length)511/// @param inCollisionTolerance The minimal distance between A and B before they are considered colliding512/// @param inPenetrationTolerance A factor that determines the accuracy of the result. If the change of the squared distance is less than inTolerance * current_penetration_depth^2 the algorithm will terminate. Should be bigger or equal to FLT_EPSILON.513/// @param inA The convex object A, must support the GetSupport(Vec3) function.514/// @param inB The convex object B, must support the GetSupport(Vec3) function.515/// @param inConvexRadiusA The convex radius of A, this will be added on all sides to pad A.516/// @param inConvexRadiusB The convex radius of B, this will be added on all sides to pad B.517/// @param inReturnDeepestPoint If the shapes are initially intersecting this determines if the EPA algorithm will run to find the deepest point518/// @param ioLambda The max fraction along the sweep, on output updated with the actual collision fraction.519/// @param outPointA is the contact point on A520/// @param outPointB is the contact point on B521/// @param outContactNormal is either the contact normal when the objects are touching or the penetration axis when the objects are penetrating at the start of the sweep (pointing from A to B, length will not be 1)522///523/// @return true if the a hit was found, in which case ioLambda, outPointA, outPointB and outSurfaceNormal are updated.524template <typename A, typename B>525bool CastShape(Mat44Arg inStart, Vec3Arg inDirection, float inCollisionTolerance, float inPenetrationTolerance, const A &inA, const B &inB, float inConvexRadiusA, float inConvexRadiusB, bool inReturnDeepestPoint, float &ioLambda, Vec3 &outPointA, Vec3 &outPointB, Vec3 &outContactNormal)526{527JPH_IF_ENABLE_ASSERTS(mGJKTolerance = inCollisionTolerance;)528529// First determine if there's a collision at all530if (!mGJK.CastShape(inStart, inDirection, inCollisionTolerance, inA, inB, inConvexRadiusA, inConvexRadiusB, ioLambda, outPointA, outPointB, outContactNormal))531return false;532533// When our contact normal is too small, we don't have an accurate result534bool contact_normal_invalid = outContactNormal.IsNearZero(Square(inCollisionTolerance));535536if (inReturnDeepestPoint537&& ioLambda == 0.0f // Only when lambda = 0 we can have the bodies overlap538&& (inConvexRadiusA + inConvexRadiusB == 0.0f // When no convex radius was provided we can never trust contact points at lambda = 0539|| contact_normal_invalid))540{541// If we're initially intersecting, we need to run the EPA algorithm in order to find the deepest contact point542AddConvexRadius add_convex_a(inA, inConvexRadiusA);543AddConvexRadius add_convex_b(inB, inConvexRadiusB);544TransformedConvexObject transformed_a(inStart, add_convex_a);545if (!GetPenetrationDepthStepEPA(transformed_a, add_convex_b, inPenetrationTolerance, outContactNormal, outPointA, outPointB))546return false;547}548else if (contact_normal_invalid)549{550// If we weren't able to calculate a contact normal, use the cast direction instead551outContactNormal = inDirection;552}553554return true;555}556};557558JPH_NAMESPACE_END559560561