mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 23:13:26 +00:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 413cef4f23 | |||
| 867cee41c3 | |||
| 990fe78a33 | |||
| 1efdb50f73 | |||
|
|
86fea065e7 | ||
|
|
ac046aae6c | ||
|
|
9646054877 | ||
| 6334002639 | |||
| 72e0c0c90b | |||
| 2f2a5a00c4 | |||
| c394993418 | |||
| 476048583d | |||
| 76ae67c968 | |||
| d1d95d2f36 | |||
| 6409568334 | |||
| 83ba339eb5 | |||
| c49c93d542 | |||
| 92dab52d66 | |||
| dac3d8e43f | |||
| fb0b05d7ef | |||
| 993212e7ab | |||
| 380a9f0a16 | |||
| ba7bce5502 | |||
| ce40891e37 | |||
| c4d10f8872 | |||
| 2bb0c82c30 | |||
| a4dcf8dc3b | |||
| 17eaddbc8c | |||
| 9005c02499 |
8
.github/workflows/cmake-multi-platform.yml
vendored
8
.github/workflows/cmake-multi-platform.yml
vendored
@@ -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
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(omath VERSION 3.5.0 LANGUAGES CXX)
|
||||
project(omath VERSION 3.8.2 LANGUAGES CXX)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
if (MSVC)
|
||||
check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
|
||||
else ()
|
||||
check_cxx_compiler_flag("-mavx2" COMPILER_SUPPORTS_AVX2)
|
||||
endif ()
|
||||
|
||||
option(OMATH_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL})
|
||||
option(OMATH_BUILD_BENCHMARK "Build benchmarks" ${PROJECT_IS_TOP_LEVEL})
|
||||
option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON)
|
||||
option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
|
||||
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
|
||||
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ${COMPILER_SUPPORTS_AVX2})
|
||||
option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF)
|
||||
option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" OFF)
|
||||
option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OFF)
|
||||
@@ -17,6 +23,11 @@ option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build
|
||||
option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF)
|
||||
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" OFF)
|
||||
|
||||
if (OMATH_USE_AVX2 AND NOT COMPILER_SUPPORTS_AVX2)
|
||||
message(WARNING "OMATH_USE_AVX2 requested, but compiler/target does not support AVX2. Disabling.")
|
||||
set(OMATH_USE_AVX2 OFF CACHE BOOL "Omath will use AVX2 to boost performance" FORCE)
|
||||
endif ()
|
||||
|
||||
message(STATUS "[${PROJECT_NAME}]: Building on ${CMAKE_HOST_SYSTEM_NAME}, compiler ${CMAKE_CXX_COMPILER_ID}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Warnings as errors ${OMATH_THREAT_WARNING_AS_ERROR}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Build unit tests ${OMATH_BUILD_TESTS}")
|
||||
@@ -39,6 +50,7 @@ else ()
|
||||
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||
endif ()
|
||||
|
||||
|
||||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}")
|
||||
@@ -92,15 +104,20 @@ if (OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (OMATH_USE_AVX2 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC -mavx2 -mavx -mfma)
|
||||
endif ()
|
||||
if (OMATH_USE_AVX2)
|
||||
if (MSVC)
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC /arch:AVX2)
|
||||
elseif (EMSCRIPTEN)
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC -msimd128 -mavx2)
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC -mfma -mavx2)
|
||||
endif()
|
||||
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)
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
|
||||
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "cl.exe",
|
||||
"CMAKE_CXX_COMPILER": "cl.exe"
|
||||
},
|
||||
"condition": {
|
||||
@@ -40,7 +39,6 @@
|
||||
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
|
||||
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "clang",
|
||||
"CMAKE_CXX_COMPILER": "clang++"
|
||||
},
|
||||
"condition": {
|
||||
@@ -72,7 +70,6 @@
|
||||
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
|
||||
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "clang",
|
||||
"CMAKE_CXX_COMPILER": "clang++"
|
||||
},
|
||||
"condition": {
|
||||
|
||||
52
README.md
52
README.md
@@ -22,6 +22,7 @@ It provides the latest features, is highly customizable, has all for cheat devel
|
||||
|
||||
**[<kbd> <br> Install <br> </kbd>][INSTALL]**
|
||||
**[<kbd> <br> Examples <br> </kbd>][EXAMPLES]**
|
||||
**[<kbd> <br> Documentation <br> </kbd>][DOCUMENTATION]**
|
||||
**[<kbd> <br> Contribute <br> </kbd>][CONTRIBUTING]**
|
||||
**[<kbd> <br> Donate <br> </kbd>][SPONSOR]**
|
||||
|
||||
@@ -42,7 +43,7 @@ It provides the latest features, is highly customizable, has all for cheat devel
|
||||
</a>
|
||||
</div>
|
||||
|
||||
## 👁🗨 Features
|
||||
# Features
|
||||
- **Efficiency**: Optimized for performance, ensuring quick computations using AVX2.
|
||||
- **Versatility**: Includes a wide array of mathematical functions and algorithms.
|
||||
- **Ease of Use**: Simplified interface for convenient integration into various projects.
|
||||
@@ -51,7 +52,10 @@ It provides the latest features, is highly customizable, has all for cheat devel
|
||||
- **Collision Detection**: Production ready code to handle collision detection by using simple interfaces.
|
||||
- **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution
|
||||
- **Ready for meta-programming**: Omath use templates for common types like Vectors, Matrixes etc, to handle all types!
|
||||
|
||||
- **Engine support**: Supports coordinate systems of Source, Unity, Unreal, IWEngine and canonical OpenGL.
|
||||
- **Cross platform**: Supports Windows, MacOS and Linux.
|
||||
<div align = center>
|
||||
|
||||
# Gallery
|
||||
|
||||
<br>
|
||||
@@ -73,48 +77,9 @@ It provides the latest features, is highly customizable, has all for cheat devel
|
||||
<br>
|
||||
<br>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
## Supported Render Pipelines
|
||||
| ENGINE | SUPPORT |
|
||||
|----------|---------|
|
||||
| Source | ✅YES |
|
||||
| Unity | ✅YES |
|
||||
| IWEngine | ✅YES |
|
||||
| OpenGL | ✅YES |
|
||||
| Unreal | ✅YES |
|
||||
|
||||
## Supported Operating Systems
|
||||
|
||||
| OS | SUPPORT |
|
||||
|----------------|---------|
|
||||
| Windows 10/11 | ✅YES |
|
||||
| Linux | ✅YES |
|
||||
| Darwin (MacOS) | ✅YES |
|
||||
|
||||
## ❔ Usage
|
||||
ESP example
|
||||
```c++
|
||||
omath::source_engine::Camera cam{localPlayer.GetCameraOrigin(),
|
||||
localPlayer.GetAimPunch(),
|
||||
{1920.f, 1080.f},
|
||||
localPlayer.GetFieldOfView(),
|
||||
0.01.f, 30000.f};
|
||||
|
||||
for (auto ent: apex_sdk::EntityList::GetAllEntities())
|
||||
{
|
||||
const auto bottom = cam.world_to_screen(ent.GetOrigin());
|
||||
const auto top = cam.world_to_screen(ent.GetBonePosition(8) + omath::Vector3<float>{0, 0, 10});
|
||||
|
||||
const auto ent_health = ent.GetHealth();
|
||||
|
||||
if (!top || !bottom || ent_health <= 0)
|
||||
continue;
|
||||
// esp rendering...
|
||||
}
|
||||
```
|
||||
|
||||
## 💘 Acknowledgments
|
||||
# 💘 Acknowledgments
|
||||
- [All contributors](https://github.com/orange-cpp/omath/graphs/contributors)
|
||||
|
||||
<!----------------------------------{ Images }--------------------------------->
|
||||
@@ -124,6 +89,7 @@ for (auto ent: apex_sdk::EntityList::GetAllEntities())
|
||||
|
||||
<!----------------------------------{ Buttons }--------------------------------->
|
||||
[INSTALL]: INSTALL.md
|
||||
[DOCUMENTATION]: http://libomath.org
|
||||
[CONTRIBUTING]: CONTRIBUTING.md
|
||||
[EXAMPLES]: examples
|
||||
[SPONSOR]: https://boosty.to/orangecpp/purchase/3568644?ssource=DIRECT&share=subscription_link
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
#include <omath/omath.hpp>
|
||||
#include <chrono>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
@@ -1,2 +1,9 @@
|
||||
add_subdirectory(googletest)
|
||||
add_subdirectory(benchmark)
|
||||
|
||||
if (OMATH_BUILD_TESTS)
|
||||
add_subdirectory(googletest)
|
||||
endif ()
|
||||
|
||||
if (OMATH_BUILD_BENCHMARK)
|
||||
set(BENCHMARK_ENABLE_TESTING OFF)
|
||||
add_subdirectory(benchmark)
|
||||
endif ()
|
||||
@@ -162,6 +162,7 @@ struct std::formatter<omath::Angle<T, MinV, MaxV, F>, char> // NOLINT(*-dcl58-cp
|
||||
}
|
||||
|
||||
template<class FormatContext>
|
||||
[[nodiscard]]
|
||||
auto format(const AngleT& a, FormatContext& ctx) const
|
||||
{
|
||||
static_assert(std::is_same_v<typename FormatContext::char_type, char>);
|
||||
@@ -181,9 +182,30 @@ struct std::formatter<omath::Angle<T, MinV, MaxV, F>, wchar_t> // NOLINT(*-dcl58
|
||||
}
|
||||
|
||||
template<class FormatContext>
|
||||
[[nodiscard]]
|
||||
auto format(const AngleT& a, FormatContext& ctx) const
|
||||
{
|
||||
static_assert(std::is_same_v<typename FormatContext::char_type, wchar_t>);
|
||||
return std::format_to(ctx.out(), L"{}deg", a.as_degrees());
|
||||
}
|
||||
};
|
||||
|
||||
// wchar_t formatter
|
||||
template<class T, T MinV, T MaxV, omath::AngleFlags F>
|
||||
struct std::formatter<omath::Angle<T, MinV, MaxV, F>, char8_t> // NOLINT(*-dcl58-cpp)
|
||||
{
|
||||
using AngleT = omath::Angle<T, MinV, MaxV, F>;
|
||||
|
||||
static constexpr auto parse(std::wformat_parse_context& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<class FormatContext>
|
||||
[[nodiscard]]
|
||||
auto format(const AngleT& a, FormatContext& ctx) const
|
||||
{
|
||||
static_assert(std::is_same_v<typename FormatContext::char_type, char8_t>);
|
||||
return std::format_to(ctx.out(), u8"{}deg", a.as_degrees());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -164,6 +164,26 @@ namespace omath
|
||||
return {to_im_vec4()};
|
||||
}
|
||||
#endif
|
||||
[[nodiscard]] std::string to_string() const noexcept
|
||||
{
|
||||
return std::format("[r:{}, g:{}, b:{}, a:{}]",
|
||||
static_cast<int>(x * 255.f),
|
||||
static_cast<int>(y * 255.f),
|
||||
static_cast<int>(z * 255.f),
|
||||
static_cast<int>(w * 255.f));
|
||||
}
|
||||
[[nodiscard]] std::wstring to_wstring() const noexcept
|
||||
{
|
||||
const auto ascii_string = to_string();
|
||||
return {ascii_string.cbegin(), ascii_string.cend()};
|
||||
}
|
||||
|
||||
// ReSharper disable once CppInconsistentNaming
|
||||
[[nodiscard]] std::u8string to_u8string() const noexcept
|
||||
{
|
||||
const auto ascii_string = to_string();
|
||||
return {ascii_string.cbegin(), ascii_string.cend()};
|
||||
}
|
||||
};
|
||||
} // namespace omath
|
||||
template<>
|
||||
@@ -174,13 +194,19 @@ struct std::formatter<omath::Color> // NOLINT(*-dcl58-cpp)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<class FormatContext>
|
||||
[[nodiscard]]
|
||||
static auto format(const omath::Color& col, std::format_context& ctx)
|
||||
static auto format(const omath::Color& col, FormatContext& ctx)
|
||||
{
|
||||
return std::format_to(ctx.out(), "[r:{}, g:{}, b:{}, a:{}]",
|
||||
static_cast<int>(col.x * 255.f),
|
||||
static_cast<int>(col.y * 255.f),
|
||||
static_cast<int>(col.z * 255.f),
|
||||
static_cast<int>(col.w * 255.f));
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||
return std::format_to(ctx.out(), "{}", col.to_string());
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
|
||||
return std::format_to(ctx.out(), L"{}", col.to_wstring());
|
||||
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
|
||||
return std::format_to(ctx.out(), u8"{}", col.to_u8string());
|
||||
|
||||
return std::unreachable();
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -328,6 +328,21 @@ namespace omath
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::wstring to_wstring() const noexcept
|
||||
{
|
||||
const auto ascii_string = to_string();
|
||||
return {ascii_string.cbegin(), ascii_string.cend()};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// ReSharper disable once CppInconsistentNaming
|
||||
std::u8string to_u8string() const noexcept
|
||||
{
|
||||
const auto ascii_string = to_string();
|
||||
return {ascii_string.cbegin(), ascii_string.cend()};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator==(const Mat& mat) const
|
||||
{
|
||||
@@ -425,7 +440,7 @@ namespace omath
|
||||
for (std::size_t k = 0; k < Columns; ++k)
|
||||
{
|
||||
const float bkj = reinterpret_cast<const float*>(other_mat_data)[k + j * Columns];
|
||||
__m256 bkjv = _mm256_set1_ps(bkj);
|
||||
const __m256 bkj_vec = _mm256_set1_ps(bkj);
|
||||
|
||||
const auto* a_col_k = reinterpret_cast<const float*>(this_mat_data + k * Rows);
|
||||
|
||||
@@ -433,8 +448,8 @@ namespace omath
|
||||
for (; i + vector_size <= Rows; i += vector_size)
|
||||
{
|
||||
__m256 cvec = _mm256_loadu_ps(c_col + i);
|
||||
__m256 avec = _mm256_loadu_ps(a_col_k + i);
|
||||
cvec = _mm256_fmadd_ps(avec, bkjv, cvec);
|
||||
const __m256 a_vec = _mm256_loadu_ps(a_col_k + i);
|
||||
cvec = _mm256_fmadd_ps(a_vec, bkj_vec, cvec);
|
||||
_mm256_storeu_ps(c_col + i, cvec);
|
||||
}
|
||||
for (; i < Rows; ++i)
|
||||
@@ -452,7 +467,7 @@ namespace omath
|
||||
for (std::size_t k = 0; k < Columns; ++k)
|
||||
{
|
||||
const double bkj = reinterpret_cast<const double*>(other_mat_data)[k + j * Columns];
|
||||
__m256d bkjv = _mm256_set1_pd(bkj);
|
||||
const __m256d bkj_vec = _mm256_set1_pd(bkj);
|
||||
|
||||
const auto* a_col_k = reinterpret_cast<const double*>(this_mat_data + k * Rows);
|
||||
|
||||
@@ -460,8 +475,8 @@ namespace omath
|
||||
for (; i + vector_size <= Rows; i += vector_size)
|
||||
{
|
||||
__m256d cvec = _mm256_loadu_pd(c_col + i);
|
||||
__m256d avec = _mm256_loadu_pd(a_col_k + i);
|
||||
cvec = _mm256_fmadd_pd(avec, bkjv, cvec);
|
||||
const __m256d a_vec = _mm256_loadu_pd(a_col_k + i);
|
||||
cvec = _mm256_fmadd_pd(a_vec, bkj_vec, cvec);
|
||||
_mm256_storeu_pd(c_col + i, cvec);
|
||||
}
|
||||
for (; i < Rows; ++i)
|
||||
@@ -495,15 +510,15 @@ namespace omath
|
||||
for (std::size_t k = 0; k < Columns; ++k)
|
||||
{
|
||||
const auto aik = static_cast<float>(this_mat_data[i * Columns + k]);
|
||||
__m256 aikv = _mm256_set1_ps(aik);
|
||||
const __m256 aik_vec = _mm256_set1_ps(aik);
|
||||
const auto* b_row = reinterpret_cast<const float*>(other_mat_data + k * OtherColumns);
|
||||
|
||||
std::size_t j = 0;
|
||||
for (; j + vector_size <= OtherColumns; j += vector_size)
|
||||
{
|
||||
__m256 cvec = _mm256_loadu_ps(c_row + j);
|
||||
__m256 bvec = _mm256_loadu_ps(b_row + j);
|
||||
cvec = _mm256_fmadd_ps(bvec, aikv, cvec);
|
||||
const __m256 b_vec = _mm256_loadu_ps(b_row + j);
|
||||
cvec = _mm256_fmadd_ps(b_vec, aik_vec, cvec);
|
||||
|
||||
_mm256_storeu_ps(c_row + j, cvec);
|
||||
}
|
||||
@@ -522,15 +537,15 @@ namespace omath
|
||||
for (std::size_t k = 0; k < Columns; ++k)
|
||||
{
|
||||
const auto aik = static_cast<double>(this_mat_data[i * Columns + k]);
|
||||
__m256d aikv = _mm256_set1_pd(aik);
|
||||
const __m256d aik_vec = _mm256_set1_pd(aik);
|
||||
const auto* b_row = reinterpret_cast<const double*>(other_mat_data + k * OtherColumns);
|
||||
|
||||
std::size_t j = 0;
|
||||
for (; j + vector_size <= OtherColumns; j += vector_size)
|
||||
{
|
||||
__m256d cvec = _mm256_loadu_pd(c_row + j);
|
||||
__m256d bvec = _mm256_loadu_pd(b_row + j);
|
||||
cvec = _mm256_fmadd_pd(bvec, aikv, cvec);
|
||||
const __m256d b_vec = _mm256_loadu_pd(b_row + j);
|
||||
cvec = _mm256_fmadd_pd(b_vec, aik_vec, cvec);
|
||||
|
||||
_mm256_storeu_pd(c_row + j, cvec);
|
||||
}
|
||||
@@ -706,9 +721,18 @@ struct std::formatter<omath::Mat<Rows, Columns, Type, StoreType>> // NOLINT(*-dc
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<class FormatContext>
|
||||
[[nodiscard]]
|
||||
static auto format(const MatType& mat, std::format_context& ctx)
|
||||
static auto format(const MatType& mat, FormatContext& ctx)
|
||||
{
|
||||
return std::format_to(ctx.out(), "{}", mat.to_string());
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||
return std::format_to(ctx.out(), "{}", mat.to_string());
|
||||
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
|
||||
return std::format_to(ctx.out(), L"{}", mat.to_wstring());
|
||||
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
|
||||
return std::format_to(ctx.out(), u8"{}", mat.to_u8string());
|
||||
}
|
||||
};
|
||||
@@ -242,9 +242,18 @@ struct std::formatter<omath::Vector2<Type>> // NOLINT(*-dcl58-cpp)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<class FormatContext>
|
||||
[[nodiscard]]
|
||||
static auto format(const omath::Vector2<Type>& vec, std::format_context& ctx)
|
||||
static auto format(const omath::Vector2<Type>& vec, FormatContext& ctx)
|
||||
{
|
||||
return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y);
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||
return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y);
|
||||
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
|
||||
return std::format_to(ctx.out(), L"[{}, {}]", vec.x, vec.y);
|
||||
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
|
||||
return std::format_to(ctx.out(), u8"[{}, {}]", vec.x, vec.y);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -303,9 +303,18 @@ struct std::formatter<omath::Vector3<Type>> // NOLINT(*-dcl58-cpp)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<class FormatContext>
|
||||
[[nodiscard]]
|
||||
static auto format(const omath::Vector3<Type>& vec, std::format_context& ctx)
|
||||
static auto format(const omath::Vector3<Type>& vec, FormatContext& ctx)
|
||||
{
|
||||
return std::format_to(ctx.out(), "[{}, {}, {}]", vec.x, vec.y, vec.z);
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||
return std::format_to(ctx.out(), "[{}, {}, {}]", vec.x, vec.y, vec.z);
|
||||
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
|
||||
return std::format_to(ctx.out(), L"[{}, {}, {}]", vec.x, vec.y, vec.z);
|
||||
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
|
||||
return std::format_to(ctx.out(), u8"[{}, {}, {}]", vec.x, vec.y, vec.z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -210,9 +210,17 @@ struct std::formatter<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
template<class FormatContext>
|
||||
[[nodiscard]]
|
||||
static auto format(const omath::Vector4<Type>& vec, std::format_context& ctx)
|
||||
static auto format(const omath::Vector4<Type>& vec, FormatContext& ctx)
|
||||
{
|
||||
return std::format_to(ctx.out(), "[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||
return std::format_to(ctx.out(), "[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
|
||||
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
|
||||
return std::format_to(ctx.out(), L"[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
|
||||
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
|
||||
return std::format_to(ctx.out(), u8"[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
|
||||
}
|
||||
};
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
// 3D primitives
|
||||
#include "omath/3d_primitives/box.hpp"
|
||||
#include "omath/3d_primitives/plane.hpp"
|
||||
|
||||
// Collision detection
|
||||
#include "omath/collision/line_tracer.hpp"
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include "omath/engines/source_engine/traits/pred_engine_trait.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include "omath/projectile_prediction/proj_pred_engine.hpp"
|
||||
#include "omath/projectile_prediction/projectile.hpp"
|
||||
#include "omath/projectile_prediction/target.hpp"
|
||||
@@ -20,7 +20,9 @@ namespace omath::projectile_prediction
|
||||
Vector3<float> v3, // by-value for calc_viewpoint_from_angles
|
||||
float pitch, float yaw, float time, float gravity, std::optional<float> maybe_pitch) {
|
||||
// Presence + return types
|
||||
{ T::predict_projectile_position(projectile, pitch, yaw, time, gravity) } -> std::same_as<Vector3<float>>;
|
||||
{
|
||||
T::predict_projectile_position(projectile, pitch, yaw, time, gravity)
|
||||
} -> std::same_as<Vector3<float>>;
|
||||
{ T::predict_target_position(target, time, gravity) } -> std::same_as<Vector3<float>>;
|
||||
{ T::calc_vector_2d_distance(vec_a) } -> std::same_as<float>;
|
||||
{ T::get_vector_height_coordinate(vec_b) } -> std::same_as<float>;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user