From 1f8212b0b34fe308b1515a15c1d99504f8bad5d2 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 27 Jan 2024 15:33:37 +0100 Subject: w --- editor/tests.cpp | 2 +- editor/tests/raycast-test.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/editor/tests.cpp b/editor/tests.cpp index f7d7565e..0d4be934 100644 --- a/editor/tests.cpp +++ b/editor/tests.cpp @@ -11,7 +11,7 @@ namespace floormat::tests { static_assert(arraySize(tests_data::fields) == (size_t)Test::COUNT); -void label_left(StringView label, float width) +void label_left(StringView label, float width) // copy-pasted from inspect.cpp { float x = ImGui::GetCursorPosX(); ImGui::TextEx(label.data(), label.data() + label.size()); diff --git a/editor/tests/raycast-test.cpp b/editor/tests/raycast-test.cpp index 549760c3..adabb0bf 100644 --- a/editor/tests/raycast-test.cpp +++ b/editor/tests/raycast-test.cpp @@ -10,7 +10,6 @@ namespace { struct aabb_result { Vector2 ts; - float tmin, tmax; bool result; }; @@ -22,8 +21,21 @@ std::array ray_aabb_signs(Vector2 ray_dir_inv_norm) return { signs[0], signs[1] }; } +Vector2 dir_to_inv_norm(Vector2 ray_dir) +{ + constexpr float eps = 1e-6f; + auto dir = ray_dir.normalized(); + Vector2 inv_dir{NoInit}; + for (unsigned i = 0; i < 2; i++) + if (Math::abs(dir[i]) < eps) + inv_dir[i] = 0; + else + inv_dir[i] = 1 / dir[i]; + return inv_dir; +} + // https://tavianator.com/2022/ray_box_boundary.html -// +// https://www.researchgate.net/figure/The-slab-method-for-ray-intersection-detection-15_fig3_283515372 aabb_result ray_aabb_intersection(Vector2 ray_origin, Vector2 ray_dir_inv_norm, std::array box_minmax, std::array signs) { @@ -46,7 +58,7 @@ aabb_result ray_aabb_intersection(Vector2 ray_origin, Vector2 ray_dir_inv_norm, tmax = min(dmax, tmax); } - return { {ts[0], ts[1] }, tmin, tmax, tmin < tmax }; + return { {ts[0], ts[1] }, tmin < tmax }; } } // namespace -- cgit v1.2.3