فهرست منبع

Partial undo of 5d382fc0f71411dacf0c1f6f93fe0d2612fed45e: Undid all changes except for the debugging code

Jorrit Rouwe 1 سال پیش
والد
کامیت
2fef04f026
2فایلهای تغییر یافته به همراه9 افزوده شده و 20 حذف شده
  1. 6 20
      Jolt/Geometry/EPAPenetrationDepth.h
  2. 3 0
      UnitTests/Physics/CollideShapeTests.cpp

+ 6 - 20
Jolt/Geometry/EPAPenetrationDepth.h

@@ -294,8 +294,7 @@ public:
 		float closest_dist_sq = FLT_MAX;
 		float closest_dist_sq = FLT_MAX;
 
 
 		// Remember last good triangle
 		// Remember last good triangle
-		Triangle *before_last = nullptr, *last = nullptr;
-		float before_last_dist_sq = FLT_MAX, last_dist_sq = FLT_MAX;
+		Triangle *last = nullptr;
 
 
 		// Loop until closest point found
 		// Loop until closest point found
 		do
 		do
@@ -324,6 +323,11 @@ public:
 			if (t->mClosestLenSq >= closest_dist_sq)
 			if (t->mClosestLenSq >= closest_dist_sq)
 				break;
 				break;
 
 
+			// Replace last good with this triangle
+			if (last != nullptr)
+				hull.FreeTriangle(last);
+			last = t;
+
 			// Add support point in direction of normal of the plane
 			// Add support point in direction of normal of the plane
 			// 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)
 			// 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)
 			// and this way we do less calculations and lose less precision
 			// and this way we do less calculations and lose less precision
@@ -341,14 +345,6 @@ public:
 			// Get the distance squared (along normal) to the support point
 			// Get the distance squared (along normal) to the support point
 			float dist_sq = Square(dot) / t->mNormal.LengthSq();
 			float dist_sq = Square(dot) / t->mNormal.LengthSq();
 
 
-			// Replace last good with this triangle and shift last good to before last
-			if (before_last != nullptr)
-				hull.FreeTriangle(before_last);
-			before_last = last;
-			last = t;
-			before_last_dist_sq = last_dist_sq;
-			last_dist_sq = dist_sq;
-
 #ifdef JPH_EPA_PENETRATION_DEPTH_DEBUG
 #ifdef JPH_EPA_PENETRATION_DEPTH_DEBUG
 			Trace("FindClosest: w = (%g, %g, %g), dot = %g, dist_sq = %g",
 			Trace("FindClosest: w = (%g, %g, %g), dot = %g, dist_sq = %g",
 				w.GetX(), w.GetY(), w.GetZ(),
 				w.GetX(), w.GetY(), w.GetZ(),
@@ -414,16 +410,6 @@ public:
 		if (last == nullptr)
 		if (last == nullptr)
 			return false;
 			return false;
 
 
-		// Fall back to before last triangle if the last triangle is significantly worse.
-		// This fixes an issue that when the hull becomes invalid due to numerical precision issues and we did one step too many.
-		// Note that when colliding curved surfaces the last triangle describes the surface better and results in a better contact point,
-		// that's why we only do this when the last triangle is significantly worse than the before last triangle.
-		if (before_last_dist_sq < 0.81f * last_dist_sq) // 10%
-		{
-			JPH_ASSERT(before_last != nullptr);
-			last = before_last;
-		}
-
 #ifdef JPH_EPA_CONVEX_BUILDER_DRAW
 #ifdef JPH_EPA_CONVEX_BUILDER_DRAW
 		hull.DrawLabel("Closest found");
 		hull.DrawLabel("Closest found");
 		hull.DrawWireTriangle(*last, Color::sWhite);
 		hull.DrawWireTriangle(*last, Color::sWhite);

+ 3 - 0
UnitTests/Physics/CollideShapeTests.cpp

@@ -378,6 +378,8 @@ TEST_SUITE("CollideShapeTests")
 		CHECK_APPROX_EQUAL(actual_penetration_depth, expected_penetration_depth);
 		CHECK_APPROX_EQUAL(actual_penetration_depth, expected_penetration_depth);
 	}
 	}
 
 
+	/*
+	// TODO: Re-enable after a better fix is found
 	// A test case of a box and a convex hull that are nearly touching and that should return a contact with correct normal because the collision settings specify a max separation distance. This was producing the wrong normal.
 	// A test case of a box and a convex hull that are nearly touching and that should return a contact with correct normal because the collision settings specify a max separation distance. This was producing the wrong normal.
 	TEST_CASE("BoxVsConvexHullNoConvexRadius")
 	TEST_CASE("BoxVsConvexHullNoConvexRadius")
 	{
 	{
@@ -430,4 +432,5 @@ TEST_SUITE("CollideShapeTests")
 
 
 		CHECK(angle >= 2.0f * JPH_PI);
 		CHECK(angle >= 2.0f * JPH_PI);
 	}
 	}
+	*/
 }
 }