diff options
| author | Mel <einebeere@gmail.com> | 2024-01-25 11:25:29 +0100 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2024-01-25 11:25:29 +0100 |
| commit | 66e436d0f2cf3c33105d8a5bce43bf64d5e72255 (patch) | |
| tree | 3ee36001907453336cf96a57d8ec0154a9ae3135 /src/Math/Ray.hpp | |
| parent | efd17623627607a26f33dac8f7ef1a1ddc931907 (diff) | |
| download | meowcraft-66e436d0f2cf3c33105d8a5bce43bf64d5e72255.tar.zst meowcraft-66e436d0f2cf3c33105d8a5bce43bf64d5e72255.zip | |
Mostly functioning world collisions
Diffstat (limited to 'src/Math/Ray.hpp')
| -rw-r--r-- | src/Math/Ray.hpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/Math/Ray.hpp b/src/Math/Ray.hpp index c2c2274..db37ac2 100644 --- a/src/Math/Ray.hpp +++ b/src/Math/Ray.hpp @@ -36,9 +36,12 @@ struct Ray { // by the ray at the biggest smaller `t` value. // Since a plane always has two normals, we know which one to pick by looking // at the direction of the ray. - hit.normal = smaller_t_values.zip(direction, [=](Real t, Real d) { - return Math::floats_equal(t, biggest_min_t) ? Math::sign(d) : 0; - }); + for (U8 a = 0; a < 3; a++) { + if (Math::floats_equal(smaller_t_values[a], biggest_min_t)) { + hit.normal[a] = Math::sign(direction[a]); + break; + } + } // If the smallest `t` is negative, the ray is pointing away from the AABB. // If the biggest `t` is smaller than the smallest `t`, the ray is missing the AABB, |
