diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp index b36736e..35bb1f0 100644 --- a/include/omath/projection/camera.hpp +++ b/include/omath/projection/camera.hpp @@ -242,16 +242,7 @@ namespace omath::projection template [[nodiscard]] constexpr static bool is_ndc_out_of_bounds(const Type& ndc) noexcept { - const auto& raw_array = ndc.raw_array(); - - if (raw_array[2] < 0.f || raw_array[2] > 1.f) - return true; - - for (std::size_t i = 0; i < 2; i++) - if (raw_array[i] < -1.f || raw_array[i] > 1.f) - return true; - - return false; + return std::ranges::any_of(ndc.raw_array(), [](const auto& val) { return val < -1 || val > 1; }); } // NDC REPRESENTATION: diff --git a/tests/engines/unit_test_unreal_engine.cpp b/tests/engines/unit_test_unreal_engine.cpp index 9fe0a60..6b2f499 100644 --- a/tests/engines/unit_test_unreal_engine.cpp +++ b/tests/engines/unit_test_unreal_engine.cpp @@ -82,6 +82,18 @@ TEST(unit_test_unreal_engine, ProjectTargetMovedFromCamera) EXPECT_NEAR(projected->y, 360, 0.00001f); } } +TEST(unit_test_unreal_engine, ProjectTargetMovedFromCameraBehind) +{ + constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f); + const auto cam = omath::unreal_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.01f, 10000.f); + + for (float distance = 0.02f; distance < 9000.f; distance += 100.f) + { + const auto projected = cam.world_to_screen({-distance, 0, 0}); + + EXPECT_FALSE(projected.has_value()); + } +} TEST(unit_test_unreal_engine, CameraSetAndGetFov) {