From 9005c02499cffbd9b735302399643239457cac48 Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 22 Sep 2025 02:08:58 +0300 Subject: [PATCH 1/8] opengl fix --- .../engines/opengl_engine/traits/pred_engine_trait.hpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 From 17eaddbc8c68f6bb094d48e54e8c5ffb7adda21e Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 22 Sep 2025 02:10:33 +0300 Subject: [PATCH 2/8] fix unity --- .../engines/unity_engine/traits/pred_engine_trait.hpp | 10 ++++------ source/engines/unity_engine/traits/camera_trait.cpp | 7 +++---- 2 files changed, 7 insertions(+), 10 deletions(-) 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/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 { From a4dcf8dc3b081847fb6db66d98b7128d672c36b6 Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 22 Sep 2025 02:12:20 +0300 Subject: [PATCH 3/8] unreal engine fix --- .../engines/unreal_engine/traits/pred_engine_trait.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 From 2bb0c82c30f792d97c54eecba9211db02e737dbd Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 22 Sep 2025 02:29:36 +0300 Subject: [PATCH 4/8] added source engine benchmark --- benchmark/benchmark_mat.cpp | 9 ++++----- benchmark/benchmark_projectile_pred.cpp | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) 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 From c4d10f88723361d2f7da88980d0996a4a27fbaea Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 22 Sep 2025 02:34:52 +0300 Subject: [PATCH 5/8] disable benchmark build for CI/CD --- .github/workflows/cmake-multi-platform.yml | 4 ++-- CMakeLists.txt | 5 ++--- extlibs/CMakeLists.txt | 10 ++++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index f72a6c27..a3696b4b 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -35,7 +35,7 @@ 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 @@ -68,7 +68,7 @@ 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 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/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 From ce40891e37d0a04d11b2e537b10254e43fe6531f Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 22 Sep 2025 02:38:25 +0300 Subject: [PATCH 6/8] added targets specification to ci cd build --- .github/workflows/cmake-multi-platform.yml | 4 ++-- tests/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index a3696b4b..1cc3c2b0 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -39,7 +39,7 @@ jobs: - name: Build shell: bash - run: cmake --build cmake-build/build/linux-release --target all + run: cmake --build cmake-build/build/linux-release --target unit_test omath - name: Run unit_tests shell: bash @@ -72,7 +72,7 @@ jobs: - name: Build shell: bash - run: cmake --build cmake-build/build/windows-release --target all + run: cmake --build cmake-build/build/windows-release --target unit_test omath - name: Run unit_tests.exe shell: bash diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 041e8f72..0e38c65d 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}" From ba7bce55021c4be66e233b2741d8c62489e92178 Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 22 Sep 2025 02:39:50 +0300 Subject: [PATCH 7/8] ooops --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0e38c65d..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((${PROJECT_NAME} 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}" From 380a9f0a16a2782db33f215b5b4db72cc2783a80 Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 22 Sep 2025 02:41:12 +0300 Subject: [PATCH 8/8] fix --- .github/workflows/cmake-multi-platform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 1cc3c2b0..13aee868 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -39,7 +39,7 @@ jobs: - name: Build shell: bash - run: cmake --build cmake-build/build/linux-release --target unit_test omath + run: cmake --build cmake-build/build/linux-release --target unit_tests omath - name: Run unit_tests shell: bash @@ -72,7 +72,7 @@ jobs: - name: Build shell: bash - run: cmake --build cmake-build/build/windows-release --target unit_test omath + run: cmake --build cmake-build/build/windows-release --target unit_tests omath - name: Run unit_tests.exe shell: bash