Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions benchmark/benchmark_mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <benchmark/benchmark.h>

#include <omath/omath.hpp>
#include <chrono>
using namespace omath;


Expand All @@ -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)
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
20 changes: 20 additions & 0 deletions benchmark/benchmark_projectile_pred.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
//
// Created by Vlad on 9/18/2025.
//
#include <benchmark/benchmark.h>
#include <omath/omath.hpp>
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);
10 changes: 8 additions & 2 deletions extlibs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
add_subdirectory(googletest)
add_subdirectory(benchmark)

if (OMATH_BUILD_TESTS)
add_subdirectory(googletest)
endif ()

if (OMATH_BUILD_BENCHMARK)
add_subdirectory(benchmark)
endif()
10 changes: 4 additions & 6 deletions include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@ namespace omath::opengl_engine
[[nodiscard]]
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& 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<float>& origin, const Vector3<float>& 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
10 changes: 4 additions & 6 deletions include/omath/engines/unity_engine/traits/pred_engine_trait.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@ namespace omath::unity_engine
[[nodiscard]]
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& 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<float>& origin, const Vector3<float>& 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
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,16 @@ namespace omath::unreal_engine
[[nodiscard]]
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& 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<float>& origin, const Vector3<float>& 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
7 changes: 3 additions & 4 deletions source/engines/unity_engine/traits/camera_trait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ namespace omath::unity_engine

ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& 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<float>& cam_origin) noexcept
{
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Loading