diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index f72a6c27..13aee868 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -35,11 +35,11 @@ jobs: - name: Configure (cmake --preset) shell: bash - run: cmake --preset linux-release -DOMATH_BUILD_TESTS=ON + run: cmake --preset linux-release -DOMATH_BUILD_TESTS=ON -DOMATH_BUILD_BENCHMARK=OFF - name: Build shell: bash - run: cmake --build cmake-build/build/linux-release --target all + run: cmake --build cmake-build/build/linux-release --target unit_tests omath - name: Run unit_tests shell: bash @@ -68,11 +68,11 @@ jobs: - name: Configure (cmake --preset) shell: bash - run: cmake --preset windows-release -DOMATH_BUILD_TESTS=ON + run: cmake --preset windows-release -DOMATH_BUILD_TESTS=ON -DOMATH_BUILD_BENCHMARK=OFF - name: Build shell: bash - run: cmake --build cmake-build/build/windows-release --target all + run: cmake --build cmake-build/build/windows-release --target unit_tests omath - name: Run unit_tests.exe shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cfc231c..09df994d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,9 +98,8 @@ endif () target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23) -if (OMATH_BUILD_TESTS OR OMATH_BUILD_BENCHMARK) - add_subdirectory(extlibs) -endif () +add_subdirectory(extlibs) + if (OMATH_BUILD_TESTS) add_subdirectory(tests) diff --git a/benchmark/benchmark_mat.cpp b/benchmark/benchmark_mat.cpp index f2eda9ac..2e543821 100644 --- a/benchmark/benchmark_mat.cpp +++ b/benchmark/benchmark_mat.cpp @@ -4,7 +4,6 @@ #include #include -#include using namespace omath; @@ -17,7 +16,7 @@ void mat_float_multiplication_col_major(benchmark::State& state) b.set(7.f); - for (auto _ : state) + for ([[maybe_unused]] const auto _ : state) std::ignore = a * b; } void mat_float_multiplication_row_major(benchmark::State& state) @@ -29,7 +28,7 @@ void mat_float_multiplication_row_major(benchmark::State& state) b.set(7.f); - for (auto _ : state) + for ([[maybe_unused]] const auto _ : state) std::ignore = a * b; } @@ -42,7 +41,7 @@ void mat_double_multiplication_row_major(benchmark::State& state) b.set(7.f); - for (auto _ : state) + for ([[maybe_unused]] const auto _ : state) std::ignore = a * b; } @@ -55,7 +54,7 @@ void mat_double_multiplication_col_major(benchmark::State& state) b.set(7.f); - for (auto _ : state) + for ([[maybe_unused]] const auto _ : state) std::ignore = a * b; } diff --git a/benchmark/benchmark_projectile_pred.cpp b/benchmark/benchmark_projectile_pred.cpp index 5cbfb350..a6337547 100644 --- a/benchmark/benchmark_projectile_pred.cpp +++ b/benchmark/benchmark_projectile_pred.cpp @@ -1,3 +1,23 @@ // // Created by Vlad on 9/18/2025. // +#include +#include +using namespace omath; + +using namespace omath::projectile_prediction; + +constexpr float simulation_time_step = 1.f / 1000.f; +constexpr float hit_distance_tolerance = 5.f; + +void source_engine_projectile_prediction(benchmark::State& state) +{ + constexpr Target target{.m_origin = {100, 0, 90}, .m_velocity = {0, 0, 0}, .m_is_airborne = false}; + constexpr Projectile projectile = {.m_origin = {3, 2, 1}, .m_launch_speed = 5000, .m_gravity_scale = 0.4}; + + for ([[maybe_unused]] const auto _: state) + std::ignore = ProjPredEngineLegacy(400, simulation_time_step, 50, hit_distance_tolerance) + .maybe_calculate_aim_point(projectile, target); +} + +BENCHMARK(source_engine_projectile_prediction)->Iterations(10'000); \ No newline at end of file diff --git a/extlibs/CMakeLists.txt b/extlibs/CMakeLists.txt index 54eda0ad..fbf19d32 100644 --- a/extlibs/CMakeLists.txt +++ b/extlibs/CMakeLists.txt @@ -1,2 +1,8 @@ -add_subdirectory(googletest) -add_subdirectory(benchmark) \ No newline at end of file + +if (OMATH_BUILD_TESTS) + add_subdirectory(googletest) +endif () + +if (OMATH_BUILD_BENCHMARK) +add_subdirectory(benchmark) +endif() \ No newline at end of file diff --git a/include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp b/include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp index 9c014ff8..ab2e607b 100644 --- a/include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp +++ b/include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp @@ -62,17 +62,15 @@ namespace omath::opengl_engine [[nodiscard]] static float calc_direct_pitch_angle(const Vector3& origin, const Vector3& view_to) noexcept { - const auto distance = origin.distance_to(view_to); - const auto delta = view_to - origin; - - return angles::radians_to_degrees(std::asin(delta.y / distance)); + const auto direction = (view_to - origin).normalized(); + return angles::radians_to_degrees(std::asin(direction.y)); } [[nodiscard]] static float calc_direct_yaw_angle(const Vector3& origin, const Vector3& view_to) noexcept { - const auto delta = view_to - origin; + const auto direction = (view_to - origin).normalized(); - return angles::radians_to_degrees(std::atan2(delta.z, delta.x)); + return angles::radians_to_degrees(-std::atan2(direction.x, -direction.z)); }; }; } // namespace omath::opengl_engine diff --git a/include/omath/engines/unity_engine/traits/pred_engine_trait.hpp b/include/omath/engines/unity_engine/traits/pred_engine_trait.hpp index 5851e4c6..dadcb7e0 100644 --- a/include/omath/engines/unity_engine/traits/pred_engine_trait.hpp +++ b/include/omath/engines/unity_engine/traits/pred_engine_trait.hpp @@ -62,17 +62,15 @@ namespace omath::unity_engine [[nodiscard]] static float calc_direct_pitch_angle(const Vector3& origin, const Vector3& view_to) noexcept { - const auto distance = origin.distance_to(view_to); - const auto delta = view_to - origin; - - return angles::radians_to_degrees(std::asin(delta.y / distance)); + const auto direction = (view_to - origin).normalized(); + return angles::radians_to_degrees(std::asin(direction.y)); } [[nodiscard]] static float calc_direct_yaw_angle(const Vector3& origin, const Vector3& view_to) noexcept { - const auto delta = view_to - origin; + const auto direction = (view_to - origin).normalized(); - return angles::radians_to_degrees(std::atan2(delta.z, delta.x)); + return angles::radians_to_degrees(std::atan2(direction.x, direction.z)); }; }; } // namespace omath::unity_engine diff --git a/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp b/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp index a57b8807..dbc04f05 100644 --- a/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp +++ b/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp @@ -62,17 +62,16 @@ namespace omath::unreal_engine [[nodiscard]] static float calc_direct_pitch_angle(const Vector3& origin, const Vector3& view_to) noexcept { - const auto distance = origin.distance_to(view_to); - const auto delta = view_to - origin; + const auto direction = (view_to - origin).normalized(); - return angles::radians_to_degrees(std::asin(delta.z / distance)); + return angles::radians_to_degrees(std::asin(direction.z)); } [[nodiscard]] static float calc_direct_yaw_angle(const Vector3& origin, const Vector3& view_to) noexcept { - const auto delta = view_to - origin; + const auto direction = (view_to - origin).normalized(); - return angles::radians_to_degrees(std::atan2(delta.y, delta.x)); + return angles::radians_to_degrees(std::atan2(direction.y, direction.x)); }; }; } // namespace omath::unreal_engine diff --git a/source/engines/unity_engine/traits/camera_trait.cpp b/source/engines/unity_engine/traits/camera_trait.cpp index e309cd7c..b981befd 100644 --- a/source/engines/unity_engine/traits/camera_trait.cpp +++ b/source/engines/unity_engine/traits/camera_trait.cpp @@ -8,11 +8,10 @@ namespace omath::unity_engine ViewAngles CameraTrait::calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept { - const auto distance = cam_origin.distance_to(look_at); - const auto delta = look_at - cam_origin; + const auto direction = (look_at - cam_origin).normalized(); - return {PitchAngle::from_radians(-std::asin(delta.y / distance)), - YawAngle::from_radians(std::atan2(delta.x, delta.z)), RollAngle::from_radians(0.f)}; + return {PitchAngle::from_radians(-std::asin(direction.y)), + YawAngle::from_radians(std::atan2(direction.x, direction.z)), RollAngle::from_radians(0.f)}; } Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 041e8f72..5fe8cc75 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,7 +7,7 @@ include(GoogleTest) file(GLOB_RECURSE UNIT_TESTS_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") add_executable(${PROJECT_NAME} ${UNIT_TESTS_SOURCES}) -set_target_properties(unit_tests PROPERTIES +set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"