mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 15:03:27 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a097c0a2f4 | |||
| 20ae2b4dd1 | |||
| 115b5a3471 | |||
| 77893629f9 | |||
| afb27b1aa9 | |||
| 61006122ae | |||
| 4eb0f59fc0 | |||
| 3b4bf24a16 | |||
| 51d93c4464 |
@@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.26)
|
cmake_minimum_required(VERSION 3.26)
|
||||||
|
|
||||||
project(omath VERSION 3.2.1 LANGUAGES CXX)
|
project(omath VERSION 3.3.0 LANGUAGES CXX)
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
@@ -16,6 +16,16 @@ 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" ON)
|
option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" ON)
|
||||||
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" OFF)
|
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" OFF)
|
||||||
|
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Building on ${CMAKE_HOST_SYSTEM_NAME}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Warnings as errors ${OMATH_THREAT_WARNING_AS_ERROR}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Build unit tests ${OMATH_BUILD_TESTS}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: As dynamic library ${OMATH_BUILD_AS_SHARED_LIBRARY}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Static C++ runtime ${OMATH_STATIC_MSVC_RUNTIME_LIBRARY}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: CMake unity build ${OMATH_USE_UNITY_BUILD}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Example projects ${OMATH_BUILD_EXAMPLES}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: AVX2 feature status ${OMATH_USE_AVX2}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: ImGUI integration feature status ${OMATH_IMGUI_INTEGRATION}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Legacy features support ${OMATH_ENABLE_LEGACY}")
|
||||||
|
|
||||||
file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
|
file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
|
||||||
file(GLOB_RECURSE OMATH_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
|
file(GLOB_RECURSE OMATH_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
|
||||||
@@ -27,8 +37,6 @@ else ()
|
|||||||
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
message(STATUS "[OMATH]: Building on ${CMAKE_HOST_SYSTEM_NAME}")
|
|
||||||
|
|
||||||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||||
|
|
||||||
if (OMATH_IMGUI_INTEGRATION)
|
if (OMATH_IMGUI_INTEGRATION)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "omath/angles.hpp"
|
#include "omath/angles.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
@@ -149,3 +150,17 @@ namespace omath
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
template<class Type, Type min, Type max, omath::AngleFlags flags>
|
||||||
|
struct std::formatter<omath::Angle<Type, min, max, flags>> // NOLINT(*-dcl58-cpp)
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
static constexpr auto parse(std::format_parse_context& ctx)
|
||||||
|
{
|
||||||
|
return ctx.begin();
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static auto format(const omath::Angle<Type, min, max, flags>& deg, std::format_context& ctx)
|
||||||
|
{
|
||||||
|
return std::format_to(ctx.out(), "{}deg", deg.as_degrees());
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -167,3 +167,21 @@ namespace omath
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
template<>
|
||||||
|
struct std::formatter<omath::Color> // NOLINT(*-dcl58-cpp)
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
static constexpr auto parse(std::format_parse_context& ctx)
|
||||||
|
{
|
||||||
|
return ctx.begin();
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static auto format(const omath::Color& col, std::format_context& 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));
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -480,3 +480,19 @@ namespace omath
|
|||||||
{0.f, 0.f, -1.f, 0.f}};
|
{0.f, 0.f, -1.f, 0.f}};
|
||||||
}
|
}
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
|
||||||
|
template<size_t Rows, size_t Columns, class Type, omath::MatStoreType StoreType>
|
||||||
|
struct std::formatter<omath::Mat<Rows, Columns, Type, StoreType>> // NOLINT(*-dcl58-cpp)
|
||||||
|
{
|
||||||
|
using MatType = omath::Mat<Rows, Columns, Type, StoreType>;
|
||||||
|
[[nodiscard]]
|
||||||
|
static constexpr auto parse(std::format_parse_context& ctx)
|
||||||
|
{
|
||||||
|
return ctx.begin();
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static auto format(const MatType& mat, std::format_context& ctx)
|
||||||
|
{
|
||||||
|
return std::format_to(ctx.out(), "{}", mat.to_string());
|
||||||
|
}
|
||||||
|
};
|
||||||
84
include/omath/omath.hpp
Normal file
84
include/omath/omath.hpp
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
//
|
||||||
|
// omath.hpp - Main header file that includes all omath library components
|
||||||
|
// Created for the omath library
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Basic math utilities
|
||||||
|
#include "omath/angles.hpp"
|
||||||
|
#include "omath/angle.hpp"
|
||||||
|
|
||||||
|
// Vector classes (in dependency order)
|
||||||
|
#include "omath/vector2.hpp"
|
||||||
|
#include "omath/vector3.hpp"
|
||||||
|
#include "omath/vector4.hpp"
|
||||||
|
|
||||||
|
// Matrix classes
|
||||||
|
#include "omath/mat.hpp"
|
||||||
|
#include "omath/matrix.hpp"
|
||||||
|
|
||||||
|
// Color functionality
|
||||||
|
#include "omath/color.hpp"
|
||||||
|
|
||||||
|
// Geometric primitives
|
||||||
|
#include "omath/triangle.hpp"
|
||||||
|
#include "omath/view_angles.hpp"
|
||||||
|
|
||||||
|
// 3D primitives
|
||||||
|
#include "omath/3d_primitives/box.hpp"
|
||||||
|
|
||||||
|
// Collision detection
|
||||||
|
#include "omath/collision/line_tracer.hpp"
|
||||||
|
|
||||||
|
// Pathfinding algorithms
|
||||||
|
#include "omath/pathfinding/a_star.hpp"
|
||||||
|
#include "omath/pathfinding/navigation_mesh.hpp"
|
||||||
|
|
||||||
|
// Projectile prediction
|
||||||
|
#include "omath/projectile_prediction/projectile.hpp"
|
||||||
|
#include "omath/projectile_prediction/target.hpp"
|
||||||
|
#include "omath/projectile_prediction/proj_pred_engine.hpp"
|
||||||
|
#include "omath/projectile_prediction/proj_pred_engine_legacy.hpp"
|
||||||
|
#include "omath/projectile_prediction/proj_pred_engine_avx2.hpp"
|
||||||
|
|
||||||
|
// Projection functionality
|
||||||
|
#include "omath/projection/error_codes.hpp"
|
||||||
|
#include "omath/projection/camera.hpp"
|
||||||
|
|
||||||
|
// Engine-specific implementations
|
||||||
|
|
||||||
|
// IW Engine
|
||||||
|
#include "omath/engines/iw_engine/constants.hpp"
|
||||||
|
#include "omath/engines/iw_engine/formulas.hpp"
|
||||||
|
#include "omath/engines/iw_engine/camera.hpp"
|
||||||
|
#include "omath/engines/iw_engine/traits/camera_trait.hpp"
|
||||||
|
#include "omath/engines/iw_engine/traits/pred_engine_trait.hpp"
|
||||||
|
|
||||||
|
// OpenGL Engine
|
||||||
|
#include "omath/engines/opengl_engine/constants.hpp"
|
||||||
|
#include "omath/engines/opengl_engine/formulas.hpp"
|
||||||
|
#include "omath/engines/opengl_engine/camera.hpp"
|
||||||
|
#include "omath/engines/opengl_engine/traits/camera_trait.hpp"
|
||||||
|
#include "omath/engines/opengl_engine/traits/pred_engine_trait.hpp"
|
||||||
|
|
||||||
|
// Source Engine
|
||||||
|
#include "omath/engines/source_engine/constants.hpp"
|
||||||
|
#include "omath/engines/source_engine/formulas.hpp"
|
||||||
|
#include "omath/engines/source_engine/camera.hpp"
|
||||||
|
#include "omath/engines/source_engine/traits/camera_trait.hpp"
|
||||||
|
#include "omath/engines/source_engine/traits/pred_engine_trait.hpp"
|
||||||
|
|
||||||
|
// Unity Engine
|
||||||
|
#include "omath/engines/unity_engine/constants.hpp"
|
||||||
|
#include "omath/engines/unity_engine/formulas.hpp"
|
||||||
|
#include "omath/engines/unity_engine/camera.hpp"
|
||||||
|
#include "omath/engines/unity_engine/traits/camera_trait.hpp"
|
||||||
|
#include "omath/engines/unity_engine/traits/pred_engine_trait.hpp"
|
||||||
|
|
||||||
|
// Unreal Engine
|
||||||
|
#include "omath/engines/unreal_engine/constants.hpp"
|
||||||
|
#include "omath/engines/unreal_engine/formulas.hpp"
|
||||||
|
#include "omath/engines/unreal_engine/camera.hpp"
|
||||||
|
#include "omath/engines/unreal_engine/traits/camera_trait.hpp"
|
||||||
|
#include "omath/engines/unreal_engine/traits/pred_engine_trait.hpp"
|
||||||
@@ -20,11 +20,11 @@ namespace omath::projectile_prediction
|
|||||||
Vector3<float> v3, // by-value for calc_viewpoint_from_angles
|
Vector3<float> v3, // by-value for calc_viewpoint_from_angles
|
||||||
float pitch, float yaw, float time, float gravity, std::optional<float> maybe_pitch) {
|
float pitch, float yaw, float time, float gravity, std::optional<float> maybe_pitch) {
|
||||||
// Presence + return types
|
// Presence + return types
|
||||||
{ T::predict_projectile_position(projectile, pitch, yaw, time, gravity) } -> std::same_as<Vec3>;
|
{ T::predict_projectile_position(projectile, pitch, yaw, time, gravity) } -> std::same_as<Vector3<float>>;
|
||||||
{ T::predict_target_position(target, time, gravity) } -> std::same_as<Vec3>;
|
{ T::predict_target_position(target, time, gravity) } -> std::same_as<Vector3<float>>;
|
||||||
{ T::calc_vector_2d_distance(vec_a) } -> std::same_as<float>;
|
{ T::calc_vector_2d_distance(vec_a) } -> std::same_as<float>;
|
||||||
{ T::get_vector_height_coordinate(vec_b) } -> std::same_as<float>;
|
{ T::get_vector_height_coordinate(vec_b) } -> std::same_as<float>;
|
||||||
{ T::calc_viewpoint_from_angles(projectile, v3, maybe_pitch) } -> std::same_as<Vec3>;
|
{ T::calc_viewpoint_from_angles(projectile, v3, maybe_pitch) } -> std::same_as<Vector3<float>>;
|
||||||
{ T::calc_direct_pitch_angle(vec_a, vec_b) } -> std::same_as<float>;
|
{ T::calc_direct_pitch_angle(vec_a, vec_b) } -> std::same_as<float>;
|
||||||
{ T::calc_direct_yaw_angle(vec_a, vec_b) } -> std::same_as<float>;
|
{ T::calc_direct_yaw_angle(vec_a, vec_b) } -> std::same_as<float>;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "vector3.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <format>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
#ifdef OMATH_IMGUI_INTEGRATION
|
#ifdef OMATH_IMGUI_INTEGRATION
|
||||||
@@ -218,7 +220,6 @@ namespace omath
|
|||||||
{
|
{
|
||||||
return std::make_tuple(x, y);
|
return std::make_tuple(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OMATH_IMGUI_INTEGRATION
|
#ifdef OMATH_IMGUI_INTEGRATION
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ImVec2 to_im_vec2() const noexcept
|
ImVec2 to_im_vec2() const noexcept
|
||||||
@@ -233,3 +234,18 @@ namespace omath
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
struct std::formatter<omath::Vector2<Type>> // NOLINT(*-dcl58-cpp)
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
static constexpr auto parse(std::format_parse_context& ctx)
|
||||||
|
{
|
||||||
|
return ctx.begin();
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static auto format(const omath::Vector2<Type>& vec, std::format_context& ctx)
|
||||||
|
{
|
||||||
|
return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -159,9 +159,9 @@ namespace omath
|
|||||||
return Vector2<Type>::length();
|
return Vector2<Type>::length();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] Type distance_to(const Vector3& vOther) const noexcept
|
[[nodiscard]] Type distance_to(const Vector3& v_other) const noexcept
|
||||||
{
|
{
|
||||||
return (*this - vOther).length();
|
return (*this - v_other).length();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -279,21 +279,33 @@ namespace omath
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
// ReSharper disable once CppRedundantNamespaceDefinition
|
|
||||||
namespace std
|
template<> struct std::hash<omath::Vector3<float>>
|
||||||
{
|
{
|
||||||
template<> struct hash<omath::Vector3<float>>
|
std::size_t operator()(const omath::Vector3<float>& vec) const noexcept
|
||||||
{
|
{
|
||||||
std::size_t operator()(const omath::Vector3<float>& vec) const noexcept
|
std::size_t hash = 0;
|
||||||
{
|
constexpr std::hash<float> hasher;
|
||||||
std::size_t hash = 0;
|
|
||||||
constexpr std::hash<float> hasher;
|
|
||||||
|
|
||||||
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
hash ^= hasher(vec.z) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.z) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace std
|
|
||||||
|
template<class Type>
|
||||||
|
struct std::formatter<omath::Vector3<Type>> // NOLINT(*-dcl58-cpp)
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
static constexpr auto parse(std::format_parse_context& ctx)
|
||||||
|
{
|
||||||
|
return ctx.begin();
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static auto format(const omath::Vector3<Type>& vec, std::format_context& ctx)
|
||||||
|
{
|
||||||
|
return std::format_to(ctx.out(), "[{}, {}, {}]", vec.x, vec.y, vec.z);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -201,3 +201,18 @@ namespace omath
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
struct std::formatter<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
static constexpr auto parse(std::format_parse_context& ctx)
|
||||||
|
{
|
||||||
|
return ctx.begin();
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static auto format(const omath::Vector4<Type>& vec, std::format_context& ctx)
|
||||||
|
{
|
||||||
|
return std::format_to(ctx.out(), "[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
//
|
//
|
||||||
// Created by Vlad on 8/25/2025.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Created by Orange on 11/27/2024.
|
// Created by Orange on 11/27/2024.
|
||||||
//
|
//
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ TEST_F(UnitTestMat, Clear)
|
|||||||
|
|
||||||
TEST_F(UnitTestMat, ToString)
|
TEST_F(UnitTestMat, ToString)
|
||||||
{
|
{
|
||||||
const std::string str = m2.to_string();
|
const std::string str = std::format("{}", m2);
|
||||||
EXPECT_FALSE(str.empty());
|
EXPECT_FALSE(str.empty());
|
||||||
EXPECT_EQ(str, "[[ 1.000, 2.000]\n [ 3.000, 4.000]]");
|
EXPECT_EQ(str, "[[ 1.000, 2.000]\n [ 3.000, 4.000]]");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user