From bcdb20d4f3eae41c52ee171fd9e8a5720f84e28a Mon Sep 17 00:00:00 2001 From: Matty Date: Fri, 29 Mar 2024 09:10:23 -0400 Subject: [PATCH] Fix `Triangle2d`/`Triangle3d` interior sampling to correctly follow triangle (#12766) # Objective When I wrote #12747 I neglected to translate random samples from triangles back to the point where they originated, so they would be sampled near the origin instead of at the actual triangle location. ## Solution Translate by the first vertex location so that the samples follow the actual triangle. --- crates/bevy_math/src/shape_sampling.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_math/src/shape_sampling.rs b/crates/bevy_math/src/shape_sampling.rs index 1479aa7209..3728034413 100644 --- a/crates/bevy_math/src/shape_sampling.rs +++ b/crates/bevy_math/src/shape_sampling.rs @@ -159,9 +159,9 @@ fn sample_triangle_interior( if u + v > 1. { let u1 = 1. - v; let v1 = 1. - u; - ab * u1 + ac * v1 + a + (ab * u1 + ac * v1) } else { - ab * u + ac * v + a + (ab * u + ac * v) } }