From 981363ec663be6cde175e5aa631bf0b7d131db21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=BCttner?= Date: Thu, 9 Nov 2023 16:09:41 +0100 Subject: [PATCH 1/5] enforce MustIncludeC --- Jolt/Geometry/ClosestPoint.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Jolt/Geometry/ClosestPoint.h b/Jolt/Geometry/ClosestPoint.h index e0f339471..6cd2d01f7 100644 --- a/Jolt/Geometry/ClosestPoint.h +++ b/Jolt/Geometry/ClosestPoint.h @@ -205,15 +205,16 @@ namespace ClosestPoint } // Edge AB + ab = inB - inA; float ab_len_sq = ab.LengthSq(); if (ab_len_sq > Square(FLT_EPSILON)) { - float v = Clamp(-a.Dot(ab) / ab_len_sq, 0.0f, 1.0f); - Vec3 q = a + v * ab; + float v = Clamp(-inA.Dot(ab) / ab_len_sq, 0.0f, 1.0f); + Vec3 q = inA + v * ab; float dist_sq = q.LengthSq(); if (dist_sq < best_dist_sq) { - closest_set = swap_ac.GetX()? 0b0110 : 0b0011; + closest_set = 0b0011; closest_point = q; best_dist_sq = dist_sq; } @@ -236,7 +237,7 @@ namespace ClosestPoint } // Edge BC - Vec3 bc = c - inB; + Vec3 bc = inC - inB; float bc_len_sq = bc.LengthSq(); if (bc_len_sq > Square(FLT_EPSILON)) { @@ -245,7 +246,7 @@ namespace ClosestPoint float dist_sq = q.LengthSq(); if (dist_sq < best_dist_sq) { - closest_set = swap_ac.GetX()? 0b0011 : 0b0110; + closest_set = 0b0110; closest_point = q; best_dist_sq = dist_sq; } From 5309eae5ddbd62a5dcfa274d82a6cfe58e602023 Mon Sep 17 00:00:00 2001 From: Jorrit Rouwe Date: Thu, 9 Nov 2023 21:20:53 +0100 Subject: [PATCH 2/5] Updating hash for determinism check --- .github/workflows/determinism_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/determinism_check.yml b/.github/workflows/determinism_check.yml index d6e2aaa41..5198b0095 100644 --- a/.github/workflows/determinism_check.yml +++ b/.github/workflows/determinism_check.yml @@ -2,7 +2,7 @@ name: Determinism Check env: CONVEX_VS_MESH_HASH: '0x10139effe747511' - RAGDOLL_HASH: '0xeb0afdf14f49c318' + RAGDOLL_HASH: '0xfb18854efbb36f83' on: push: From 8f785abde112a16c22e068e62ef022a385c48c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=BCttner?= Date: Thu, 9 Nov 2023 21:38:26 +0100 Subject: [PATCH 3/5] adjusted testing order of edges --- Jolt/Geometry/ClosestPoint.h | 62 ++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/Jolt/Geometry/ClosestPoint.h b/Jolt/Geometry/ClosestPoint.h index 6cd2d01f7..724a05f3f 100644 --- a/Jolt/Geometry/ClosestPoint.h +++ b/Jolt/Geometry/ClosestPoint.h @@ -183,6 +183,37 @@ namespace ClosestPoint Vec3 closest_point = inC; float best_dist_sq = inC.LengthSq(); + // Edge AC + float ac_len_sq = ac.LengthSq(); + if (ac_len_sq > Square(FLT_EPSILON)) + { + float v = Clamp(-a.Dot(ac) / ac_len_sq, 0.0f, 1.0f); + Vec3 q = a + v * ac; + float dist_sq = q.LengthSq(); + if (dist_sq < best_dist_sq) + { + closest_set = 0b0101; + closest_point = q; + best_dist_sq = dist_sq; + } + } + + // Edge BC + Vec3 bc = inC - inB; + float bc_len_sq = bc.LengthSq(); + if (bc_len_sq > Square(FLT_EPSILON)) + { + float v = Clamp(-inB.Dot(bc) / bc_len_sq, 0.0f, 1.0f); + Vec3 q = inB + v * bc; + float dist_sq = q.LengthSq(); + if (dist_sq < best_dist_sq) + { + closest_set = 0b0110; + closest_point = q; + best_dist_sq = dist_sq; + } + } + // If the closest point must include C then A or B cannot be closest if constexpr (!MustIncludeC) { @@ -221,37 +252,6 @@ namespace ClosestPoint } } - // Edge AC - float ac_len_sq = ac.LengthSq(); - if (ac_len_sq > Square(FLT_EPSILON)) - { - float v = Clamp(-a.Dot(ac) / ac_len_sq, 0.0f, 1.0f); - Vec3 q = a + v * ac; - float dist_sq = q.LengthSq(); - if (dist_sq < best_dist_sq) - { - closest_set = 0b0101; - closest_point = q; - best_dist_sq = dist_sq; - } - } - - // Edge BC - Vec3 bc = inC - inB; - float bc_len_sq = bc.LengthSq(); - if (bc_len_sq > Square(FLT_EPSILON)) - { - float v = Clamp(-inB.Dot(bc) / bc_len_sq, 0.0f, 1.0f); - Vec3 q = inB + v * bc; - float dist_sq = q.LengthSq(); - if (dist_sq < best_dist_sq) - { - closest_set = 0b0110; - closest_point = q; - best_dist_sq = dist_sq; - } - } - outSet = closest_set; return closest_point; } From 6212960b76ff8d0d543dcea0cadaae269298da47 Mon Sep 17 00:00:00 2001 From: Jorrit Rouwe Date: Fri, 10 Nov 2023 13:32:48 +0100 Subject: [PATCH 4/5] Updating hash --- .github/workflows/determinism_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/determinism_check.yml b/.github/workflows/determinism_check.yml index 5198b0095..e8e1d0a60 100644 --- a/.github/workflows/determinism_check.yml +++ b/.github/workflows/determinism_check.yml @@ -2,7 +2,7 @@ name: Determinism Check env: CONVEX_VS_MESH_HASH: '0x10139effe747511' - RAGDOLL_HASH: '0xfb18854efbb36f83' + RAGDOLL_HASH: '0xf6e41ad9d35ffa7f' on: push: From c48b2c2cc067381b57d630d2b457fa058c7e7bd4 Mon Sep 17 00:00:00 2001 From: Jorrit Rouwe Date: Sat, 11 Nov 2023 17:46:22 +0100 Subject: [PATCH 5/5] Preferring vertices over edges --- .github/workflows/determinism_check.yml | 2 +- Jolt/Geometry/ClosestPoint.h | 43 ++++++++++++++----------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/.github/workflows/determinism_check.yml b/.github/workflows/determinism_check.yml index e8e1d0a60..96c9b6bd9 100644 --- a/.github/workflows/determinism_check.yml +++ b/.github/workflows/determinism_check.yml @@ -2,7 +2,7 @@ name: Determinism Check env: CONVEX_VS_MESH_HASH: '0x10139effe747511' - RAGDOLL_HASH: '0xf6e41ad9d35ffa7f' + RAGDOLL_HASH: '0xcdcbb4da185d1a13' on: push: diff --git a/Jolt/Geometry/ClosestPoint.h b/Jolt/Geometry/ClosestPoint.h index 724a05f3f..8c646bc32 100644 --- a/Jolt/Geometry/ClosestPoint.h +++ b/Jolt/Geometry/ClosestPoint.h @@ -183,6 +183,29 @@ namespace ClosestPoint Vec3 closest_point = inC; float best_dist_sq = inC.LengthSq(); + // If the closest point must include C then A or B cannot be closest + // Note that we test vertices first because we want to prefer a closest vertex over a closest edge (this results in an outSet with fewer bits set) + if constexpr (!MustIncludeC) + { + // Try vertex A + float a_len_sq = inA.LengthSq(); + if (a_len_sq < best_dist_sq) + { + closest_set = 0b0001; + closest_point = inA; + best_dist_sq = a_len_sq; + } + + // Try vertex B + float b_len_sq = inB.LengthSq(); + if (b_len_sq < best_dist_sq) + { + closest_set = 0b0010; + closest_point = inB; + best_dist_sq = b_len_sq; + } + } + // Edge AC float ac_len_sq = ac.LengthSq(); if (ac_len_sq > Square(FLT_EPSILON)) @@ -214,27 +237,9 @@ namespace ClosestPoint } } - // If the closest point must include C then A or B cannot be closest + // If the closest point must include C then AB cannot be closest if constexpr (!MustIncludeC) { - // Try vertex A - float a_len_sq = inA.LengthSq(); - if (a_len_sq < best_dist_sq) - { - closest_set = 0b0001; - closest_point = inA; - best_dist_sq = a_len_sq; - } - - // Try vertex B - float b_len_sq = inB.LengthSq(); - if (b_len_sq < best_dist_sq) - { - closest_set = 0b0010; - closest_point = inB; - best_dist_sq = b_len_sq; - } - // Edge AB ab = inB - inA; float ab_len_sq = ab.LengthSq();