mirror of
https://github.com/orange-cpp/omath.git
synced 2026-06-15 03:34:35 +00:00
removed gcem as dep
This commit is contained in:
@@ -33,7 +33,6 @@ option(OMATH_ENABLE_FORCE_INLINE
|
||||
option(OMATH_ENABLE_LUA
|
||||
"omath bindings for lua" OFF)
|
||||
option(OMATH_ENABLE_HOOKING "omath will HooksManager that can hook DirectX/OpenGL automatically" OFF)
|
||||
option(OMATH_USE_GCEM "omath will use gcem library to make more functions/methods constexpr" OFF)
|
||||
option(OMATH_ENABLE_MODULES "Build omath C++ module interface" OFF)
|
||||
|
||||
if(VCPKG_MANIFEST_FEATURES)
|
||||
@@ -52,8 +51,6 @@ if(VCPKG_MANIFEST_FEATURES)
|
||||
set(OMATH_ENABLE_LUA ON)
|
||||
elseif(omath_feature STREQUAL "hooking")
|
||||
set(OMATH_ENABLE_HOOKING ON)
|
||||
elseif (omath_feature STREQUAL "gcem")
|
||||
set(OMATH_USE_GCEM ON)
|
||||
endif()
|
||||
|
||||
endforeach()
|
||||
@@ -84,7 +81,6 @@ if(${PROJECT_IS_TOP_LEVEL})
|
||||
message(STATUS "[${PROJECT_NAME}]: Coverage feature status ${OMATH_ENABLE_COVERAGE}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Valgrind feature status ${OMATH_ENABLE_VALGRIND}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Lua feature status ${OMATH_ENABLE_LUA}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Gcem feature status ${OMATH_USE_GCEM}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Modules feature status ${OMATH_ENABLE_MODULES}")
|
||||
endif()
|
||||
|
||||
@@ -141,11 +137,6 @@ if (OMATH_ENABLE_HOOKING)
|
||||
endif ()
|
||||
|
||||
|
||||
if (OMATH_USE_GCEM)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_USE_GCEM)
|
||||
find_package(gcem CONFIG REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC gcem)
|
||||
endif ()
|
||||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}")
|
||||
|
||||
+2
-2
@@ -57,7 +57,7 @@
|
||||
"inherits": ["windows-base", "vcpkg-base"],
|
||||
"cacheVariables": {
|
||||
"VCPKG_TARGET_TRIPLET": "x64-windows-static",
|
||||
"VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2;examples;hooking;gcem",
|
||||
"VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2;examples;hooking",
|
||||
"OMATH_STATIC_MSVC_RUNTIME_LIBRARY": "ON"
|
||||
}
|
||||
},
|
||||
@@ -239,7 +239,7 @@
|
||||
"hidden": true,
|
||||
"inherits": ["darwin-base", "vcpkg-base"],
|
||||
"cacheVariables": {
|
||||
"VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2;examples;lua;gcem"
|
||||
"VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2;examples;lua"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ Thanks to everyone who made this possible, including:
|
||||
|
||||
- Saikari aka luadebug for VCPKG port and awesome new initial logo design.
|
||||
- Billy O'Neal aka BillyONeal for fixing compilation issues due to C math library compatibility.
|
||||
- Alex2772 for reference of AUI declarative interface design for omath::hud
|
||||
|
||||
- Alex2772 for reference of AUI declarative interface design for omath::hud.
|
||||
- Keith O'Hara aka kthohr for a C++ generalized constant expression-based math library that was used as reference.
|
||||
And a big hand to everyone else who has contributed over the past!
|
||||
|
||||
THANKS! <3
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace omath::cry_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.roll)
|
||||
@@ -16,7 +16,7 @@ namespace omath::cry_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace omath::cry_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace omath::cry_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
@@ -40,26 +40,26 @@ namespace omath::cry_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
inline constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
|
||||
up_vector(angles), cam_origin);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_origin(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_scale(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
inline constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
{
|
||||
const auto angles = mat_extract_rotation_zyx(mat);
|
||||
return {
|
||||
@@ -69,9 +69,10 @@ namespace omath::cry_engine
|
||||
};
|
||||
}
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
|
||||
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range = NDCDepthRange::ZERO_TO_ONE) noexcept
|
||||
inline constexpr Mat4X4
|
||||
calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near_plane,
|
||||
const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range = NDCDepthRange::ZERO_TO_ONE) noexcept
|
||||
{
|
||||
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/cry_engine/formulas.hpp"
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
namespace omath::cry_engine
|
||||
{
|
||||
@@ -12,8 +12,8 @@ namespace omath::cry_engine
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
return {PitchAngle::from_radians(internal::asin(direction.z)),
|
||||
@@ -21,16 +21,15 @@ namespace omath::cry_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return cry_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4
|
||||
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near_plane,
|
||||
const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
|
||||
ndc_depth_range);
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
namespace omath::frostbite_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace omath::frostbite_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace omath::frostbite_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
@@ -35,15 +35,14 @@ namespace omath::frostbite_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
inline constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
|
||||
up_vector(angles), cam_origin);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll)
|
||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||
@@ -51,19 +50,19 @@ namespace omath::frostbite_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_origin(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_scale(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
inline constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
{
|
||||
const auto angles = mat_extract_rotation_zyx(mat);
|
||||
return {
|
||||
@@ -74,7 +73,7 @@ namespace omath::frostbite_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
|
||||
inline constexpr Mat4X4 calc_perspective_projection_matrix(
|
||||
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/frostbite_engine/formulas.hpp"
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::frostbite_engine
|
||||
@@ -13,8 +13,8 @@ namespace omath::frostbite_engine
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
@@ -23,20 +23,19 @@ namespace omath::frostbite_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return frostbite_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4
|
||||
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near_plane,
|
||||
const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
|
||||
ndc_depth_range);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace omath::unreal_engine
|
||||
} // namespace omath::frostbite_engine
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace omath::iw_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace omath::iw_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
@@ -35,25 +35,25 @@ namespace omath::iw_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_origin(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_scale(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
inline constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
{
|
||||
const auto angles = mat_extract_rotation_zyx(mat);
|
||||
return {
|
||||
@@ -64,14 +64,13 @@ namespace omath::iw_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
inline constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
|
||||
inline constexpr Mat4X4 calc_perspective_projection_matrix(
|
||||
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/iw_engine/formulas.hpp"
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::iw_engine
|
||||
@@ -13,8 +13,8 @@ namespace omath::iw_engine
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
@@ -23,16 +23,15 @@ namespace omath::iw_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return iw_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4
|
||||
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near_plane,
|
||||
const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
|
||||
ndc_depth_range);
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec =
|
||||
rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_forward);
|
||||
@@ -19,7 +19,7 @@ namespace omath::opengl_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec =
|
||||
rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_right);
|
||||
@@ -28,7 +28,7 @@ namespace omath::opengl_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_up);
|
||||
|
||||
@@ -36,14 +36,13 @@ namespace omath::opengl_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
inline constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_look_at_right_handed(cam_origin, cam_origin + forward_vector(angles), up_vector(angles));
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_z<float, MatStoreType::COLUMN_MAJOR>(angles.roll)
|
||||
* mat_rotation_axis_y<float, MatStoreType::COLUMN_MAJOR>(angles.yaw)
|
||||
@@ -51,19 +50,19 @@ namespace omath::opengl_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_origin(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_scale(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
inline constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
{
|
||||
const auto angles = mat_extract_rotation_zyx(mat);
|
||||
return {
|
||||
@@ -74,19 +73,19 @@ namespace omath::opengl_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
|
||||
inline constexpr Mat4X4 calc_perspective_projection_matrix(
|
||||
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
|
||||
{
|
||||
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return mat_perspective_right_handed_vertical_fov<
|
||||
float, MatStoreType::COLUMN_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
return mat_perspective_right_handed_vertical_fov<float, MatStoreType::COLUMN_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near_plane, far_plane);
|
||||
|
||||
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||
return mat_perspective_right_handed_vertical_fov<
|
||||
float, MatStoreType::COLUMN_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near_plane, far_plane);
|
||||
return mat_perspective_right_handed_vertical_fov<float, MatStoreType::COLUMN_MAJOR,
|
||||
NDCDepthRange::ZERO_TO_ONE>(field_of_view, aspect_ratio,
|
||||
near_plane, far_plane);
|
||||
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/opengl_engine/formulas.hpp"
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::opengl_engine
|
||||
@@ -13,27 +13,25 @@ namespace omath::opengl_engine
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
return {PitchAngle::from_radians(internal::asin(direction.y)),
|
||||
YawAngle::from_radians(-internal::atan2(direction.x, -direction.z)),
|
||||
RollAngle::from_radians(0.f)};
|
||||
YawAngle::from_radians(-internal::atan2(direction.x, -direction.z)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return opengl_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4
|
||||
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near_plane,
|
||||
const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
|
||||
ndc_depth_range);
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
namespace omath::rage_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace omath::rage_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace omath::rage_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
@@ -36,15 +36,14 @@ namespace omath::rage_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
inline constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
|
||||
up_vector(angles), cam_origin);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.roll)
|
||||
@@ -52,19 +51,19 @@ namespace omath::rage_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_origin(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_scale(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
inline constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
{
|
||||
const auto angles = mat_extract_rotation_zyx(mat);
|
||||
return {
|
||||
@@ -75,9 +74,10 @@ namespace omath::rage_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
|
||||
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range = NDCDepthRange::ZERO_TO_ONE) noexcept
|
||||
inline constexpr Mat4X4
|
||||
calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near_plane,
|
||||
const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range = NDCDepthRange::ZERO_TO_ONE) noexcept
|
||||
{
|
||||
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/rage_engine/formulas.hpp"
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::rage_engine
|
||||
@@ -13,8 +13,8 @@ namespace omath::rage_engine
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
@@ -23,16 +23,15 @@ namespace omath::rage_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return rage_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4
|
||||
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near_plane,
|
||||
const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
|
||||
ndc_depth_range);
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
namespace omath::source_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
@@ -18,25 +18,25 @@ namespace omath::source_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_origin(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_scale(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
inline constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
{
|
||||
const auto angles = mat_extract_rotation_zyx(mat);
|
||||
return {
|
||||
@@ -47,7 +47,7 @@ namespace omath::source_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace omath::source_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
@@ -63,14 +63,13 @@ namespace omath::source_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
inline constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
|
||||
inline constexpr Mat4X4 calc_perspective_projection_matrix(
|
||||
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/source_engine/formulas.hpp"
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::source_engine
|
||||
@@ -13,8 +13,8 @@ namespace omath::source_engine
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
@@ -23,16 +23,15 @@ namespace omath::source_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return source_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4
|
||||
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near_plane,
|
||||
const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
|
||||
ndc_depth_range);
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace omath::unity_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace omath::unity_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
@@ -35,15 +35,14 @@ namespace omath::unity_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
inline constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(-forward_vector(angles), right_vector(angles),
|
||||
up_vector(angles), cam_origin);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll)
|
||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||
@@ -51,19 +50,19 @@ namespace omath::unity_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_origin(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_scale(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
inline constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
{
|
||||
const auto angles = mat_extract_rotation_zyx(mat);
|
||||
return {
|
||||
@@ -74,17 +73,17 @@ namespace omath::unity_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
|
||||
inline constexpr Mat4X4 calc_perspective_projection_matrix(
|
||||
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
|
||||
{
|
||||
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||
return omath::mat_perspective_right_handed_vertical_fov<
|
||||
float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
return omath::mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::ZERO_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near_plane, far_plane);
|
||||
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return omath::mat_perspective_right_handed_vertical_fov<
|
||||
float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
return omath::mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near_plane, far_plane);
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/unity_engine/formulas.hpp"
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::unity_engine
|
||||
@@ -13,8 +13,8 @@ namespace omath::unity_engine
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
|
||||
const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
@@ -23,16 +23,15 @@ namespace omath::unity_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<float>& cam_origin) noexcept
|
||||
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return unity_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4
|
||||
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
const float near_plane, const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near_plane,
|
||||
const float far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
|
||||
ndc_depth_range);
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
namespace omath::unreal_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<double> forward_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<double> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace omath::unreal_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<double> right_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<double> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace omath::unreal_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<double> up_vector(const ViewAngles& angles) noexcept
|
||||
inline constexpr Vector3<double> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
@@ -35,15 +35,14 @@ namespace omath::unreal_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<double>& cam_origin) noexcept
|
||||
inline constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<double>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view<double, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
|
||||
up_vector(angles), cam_origin);
|
||||
up_vector(angles), cam_origin);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_z<double, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||
* mat_rotation_axis_y<double, MatStoreType::ROW_MAJOR>(-angles.pitch)
|
||||
@@ -51,19 +50,19 @@ namespace omath::unreal_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<double> extract_origin(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<double> extract_origin(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_origin(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Vector3<double> extract_scale(const Mat4X4& mat) noexcept
|
||||
inline constexpr Vector3<double> extract_scale(const Mat4X4& mat) noexcept
|
||||
{
|
||||
return mat_extract_scale(mat);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
inline constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
|
||||
{
|
||||
const auto angles = mat_extract_rotation_zyx(mat);
|
||||
return {
|
||||
@@ -74,17 +73,17 @@ namespace omath::unreal_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
|
||||
inline constexpr Mat4X4 calc_perspective_projection_matrix(
|
||||
const double field_of_view, const double aspect_ratio, const double near_plane, const double far_plane,
|
||||
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
|
||||
{
|
||||
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||
return mat_perspective_left_handed_horizontal_fov<
|
||||
double, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near_plane, far_plane);
|
||||
return mat_perspective_left_handed_horizontal_fov<double, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::ZERO_TO_ONE>(field_of_view, aspect_ratio,
|
||||
near_plane, far_plane);
|
||||
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return mat_perspective_left_handed_horizontal_fov<
|
||||
double, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
return mat_perspective_left_handed_horizontal_fov<double, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near_plane, far_plane);
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/unreal_engine/formulas.hpp"
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::unreal_engine
|
||||
@@ -13,8 +13,8 @@ namespace omath::unreal_engine
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static ViewAngles calc_look_at_angle(const Vector3<double>& cam_origin,
|
||||
const Vector3<double>& look_at) noexcept
|
||||
constexpr static ViewAngles calc_look_at_angle(const Vector3<double>& cam_origin,
|
||||
const Vector3<double>& look_at) noexcept
|
||||
{
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
@@ -23,16 +23,15 @@ namespace omath::unreal_engine
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4 calc_view_matrix(const ViewAngles& angles,
|
||||
const Vector3<double>& cam_origin) noexcept
|
||||
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<double>& cam_origin) noexcept
|
||||
{
|
||||
return unreal_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR static Mat4X4
|
||||
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
const double near_plane, const double far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const double near_plane,
|
||||
const double far_plane,
|
||||
const NDCDepthRange ndc_depth_range) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
|
||||
ndc_depth_range);
|
||||
|
||||
@@ -0,0 +1,707 @@
|
||||
//
|
||||
// Created by orange on 6/11/2026.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
#include <type_traits>
|
||||
|
||||
namespace omath::internal
|
||||
{
|
||||
// Embedded subset of GCE-Math 1.18.0.
|
||||
//
|
||||
// Original project:
|
||||
// GCE-Math: A C++ generalized constant expression-based math library
|
||||
// Copyright 2016-2024 Keith O'Hara
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
namespace math_detail
|
||||
{
|
||||
using uint_t = unsigned int;
|
||||
using llint_t = long long int;
|
||||
using ullint_t = unsigned long long int;
|
||||
|
||||
template<class Type>
|
||||
using limits = std::numeric_limits<Type>;
|
||||
|
||||
template<class Type>
|
||||
constexpr Type pi = std::numbers::pi_v<Type>;
|
||||
|
||||
template<class Type>
|
||||
constexpr Type half_pi = std::numbers::pi_v<Type> / static_cast<Type>(2);
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type abs(const Type value) noexcept
|
||||
{
|
||||
return value == Type{0} ? Type{0} : value < Type{0} ? -value : value;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr int sgn(const Type value) noexcept
|
||||
{
|
||||
return value > Type{0} ? 1 : value < Type{0} ? -1 : 0;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool is_odd(const llint_t value) noexcept
|
||||
{
|
||||
return (value & 1U) != 0;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr bool is_nan(const Type value) noexcept
|
||||
{
|
||||
return value != value;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr bool is_neginf(const Type value) noexcept
|
||||
{
|
||||
return value == -limits<Type>::infinity();
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr bool is_posinf(const Type value) noexcept
|
||||
{
|
||||
return value == limits<Type>::infinity();
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr bool is_inf(const Type value) noexcept
|
||||
{
|
||||
return is_neginf(value) || is_posinf(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr bool is_finite(const Type value) noexcept
|
||||
{
|
||||
return !is_nan(value) && !is_inf(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr bool any_nan(const Type x, const Type y) noexcept
|
||||
{
|
||||
return is_nan(x) || is_nan(y);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr bool any_inf(const Type x, const Type y) noexcept
|
||||
{
|
||||
return is_inf(x) || is_inf(y);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr bool all_finite(const Type x, const Type y) noexcept
|
||||
{
|
||||
return is_finite(x) && is_finite(y);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr bool signbit(const Type value) noexcept
|
||||
{
|
||||
if constexpr (std::is_same_v<Type, float>)
|
||||
return (std::bit_cast<std::uint32_t>(value) & 0x80000000U) != 0;
|
||||
else if constexpr (std::is_same_v<Type, double>)
|
||||
return (std::bit_cast<std::uint64_t>(value) & 0x8000000000000000ULL) != 0;
|
||||
else
|
||||
return value < Type{0};
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr bool neg_zero(const Type value) noexcept
|
||||
{
|
||||
return value == Type{0} && signbit(value);
|
||||
}
|
||||
|
||||
template<class Type, class ExpType>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type pow_integral_compute(const Type base, const ExpType exp_term) noexcept;
|
||||
|
||||
template<class Type, class ExpType>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type pow_integral_compute_recur(const Type base, const Type value, const ExpType exp_term) noexcept
|
||||
{
|
||||
return exp_term > ExpType{1}
|
||||
? is_odd(static_cast<llint_t>(exp_term))
|
||||
? pow_integral_compute_recur(base * base, value * base, exp_term / ExpType{2})
|
||||
: pow_integral_compute_recur(base * base, value, exp_term / ExpType{2})
|
||||
: exp_term == ExpType{1} ? value * base
|
||||
: value;
|
||||
}
|
||||
|
||||
template<class Type, class ExpType>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type pow_integral_sgn_check(const Type base, const ExpType exp_term) noexcept
|
||||
{
|
||||
if constexpr (std::is_signed_v<ExpType>)
|
||||
return exp_term < ExpType{0} ? Type{1} / pow_integral_compute(base, -exp_term)
|
||||
: pow_integral_compute_recur(base, Type{1}, exp_term);
|
||||
else
|
||||
return pow_integral_compute_recur(base, Type{1}, exp_term);
|
||||
}
|
||||
|
||||
template<class Type, class ExpType>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type pow_integral_compute(const Type base, const ExpType exp_term) noexcept
|
||||
{
|
||||
return exp_term == ExpType{3} ? base * base * base
|
||||
: exp_term == ExpType{2} ? base * base
|
||||
: exp_term == ExpType{1} ? base
|
||||
: exp_term == ExpType{0} ? Type{1}
|
||||
: exp_term == limits<ExpType>::min() ? Type{0}
|
||||
: exp_term == limits<ExpType>::max() ? limits<Type>::infinity()
|
||||
: pow_integral_sgn_check(base, exp_term);
|
||||
}
|
||||
|
||||
template<class Type, class ExpType>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type pow_integral(const Type base, const ExpType exp_term) noexcept
|
||||
{
|
||||
return pow_integral_compute(base, exp_term);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type sqrt_recur(const Type x, const Type xn, const int count) noexcept
|
||||
{
|
||||
return abs(xn - x / xn) / (Type{1} + xn) < limits<Type>::min() ? xn
|
||||
: count < 100 ? sqrt_recur(x, Type{0.5} * (xn + x / xn), count + 1)
|
||||
: xn;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type sqrt_simplify(const Type x, const Type m_val) noexcept
|
||||
{
|
||||
return x > Type{1e+08} ? sqrt_simplify(x / Type{1e+08}, Type{1e+04} * m_val)
|
||||
: x > Type{1e+06} ? sqrt_simplify(x / Type{1e+06}, Type{1e+03} * m_val)
|
||||
: x > Type{1e+04} ? sqrt_simplify(x / Type{1e+04}, Type{1e+02} * m_val)
|
||||
: x > Type{100} ? sqrt_simplify(x / Type{100}, Type{10} * m_val)
|
||||
: x > Type{4} ? sqrt_simplify(x / Type{4}, Type{2} * m_val)
|
||||
: m_val * sqrt_recur(x, x / Type{2}, 0);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type sqrt(const Type x) noexcept
|
||||
{
|
||||
return is_nan(x) ? limits<Type>::quiet_NaN()
|
||||
: x < Type{0} ? limits<Type>::quiet_NaN()
|
||||
: is_posinf(x) ? x
|
||||
: limits<Type>::min() > abs(x) ? Type{0}
|
||||
: limits<Type>::min() > abs(Type{1} - x) ? x
|
||||
: sqrt_simplify(x, Type{1});
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type floor_int(const Type x, const Type x_whole) noexcept
|
||||
{
|
||||
return x_whole - static_cast<Type>((x < Type{0}) && (x < x_whole));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type floor_check_internal(const Type x) noexcept
|
||||
{
|
||||
if constexpr (std::is_same_v<Type, float>)
|
||||
return abs(x) >= 8388608.f ? x : floor_int(x, static_cast<float>(static_cast<int>(x)));
|
||||
else if constexpr (std::is_same_v<Type, double>)
|
||||
return abs(x) >= 4503599627370496. ? x : floor_int(x, static_cast<double>(static_cast<llint_t>(x)));
|
||||
else
|
||||
return abs(x) >= 9223372036854775808.l
|
||||
? x
|
||||
: static_cast<long double>(static_cast<ullint_t>(abs(x))) * sgn(x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type floor(const Type x) noexcept
|
||||
{
|
||||
return is_nan(x) ? limits<Type>::quiet_NaN()
|
||||
: !is_finite(x) ? x
|
||||
: limits<Type>::min() > abs(x) ? x
|
||||
: floor_check_internal(x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type trunc_int(const Type x) noexcept
|
||||
{
|
||||
return static_cast<Type>(static_cast<llint_t>(x));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type trunc_check_internal(const Type x) noexcept
|
||||
{
|
||||
if constexpr (std::is_same_v<Type, float>)
|
||||
return abs(x) >= 8388608.f ? x : trunc_int(x);
|
||||
else if constexpr (std::is_same_v<Type, double>)
|
||||
return abs(x) >= 4503599627370496. ? x : trunc_int(x);
|
||||
else
|
||||
return abs(x) >= 9223372036854775808.l
|
||||
? x
|
||||
: static_cast<long double>(static_cast<ullint_t>(abs(x))) * sgn(x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type trunc(const Type x) noexcept
|
||||
{
|
||||
return is_nan(x) ? limits<Type>::quiet_NaN()
|
||||
: !is_finite(x) ? x
|
||||
: limits<Type>::min() > abs(x) ? x
|
||||
: trunc_check_internal(x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type fmod(const Type x, const Type y) noexcept
|
||||
{
|
||||
return any_nan(x, y) || !all_finite(x, y) || limits<Type>::min() > abs(y) ? limits<Type>::quiet_NaN()
|
||||
: x - trunc(x / y) * y;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type tan_series_exp_long(const Type z) noexcept
|
||||
{
|
||||
return -Type{1} / z
|
||||
+ (z / Type{3}
|
||||
+ (pow_integral(z, 3) / Type{45}
|
||||
+ (Type{2} * pow_integral(z, 5) / Type{945} + pow_integral(z, 7) / Type{4725})));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type tan_series_exp(const Type x) noexcept
|
||||
{
|
||||
return limits<Type>::min() > abs(x - half_pi<Type>) ? Type{1.633124e+16}
|
||||
: tan_series_exp_long(x - half_pi<Type>);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type tan_cf_recur(const Type xx, const int max_depth) noexcept
|
||||
{
|
||||
Type result = static_cast<Type>(2 * max_depth - 1);
|
||||
for (int depth = max_depth - 1; depth >= 1; --depth)
|
||||
result = static_cast<Type>(2 * depth - 1) - xx / result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type tan_cf_main(const Type x) noexcept
|
||||
{
|
||||
return x > Type{1.55} && x < Type{1.60} ? tan_series_exp(x)
|
||||
: x > Type{1.4} ? x / tan_cf_recur(x * x, 45)
|
||||
: x > Type{1} ? x / tan_cf_recur(x * x, 35)
|
||||
: x / tan_cf_recur(x * x, 25);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type tan_begin(const Type x, const int count = 0) noexcept
|
||||
{
|
||||
return x > pi<Type> ? count > 1 ? limits<Type>::quiet_NaN()
|
||||
: tan_begin(x - pi<Type> * floor(x / pi<Type>), count + 1)
|
||||
: tan_cf_main(x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type tan(const Type x) noexcept
|
||||
{
|
||||
return is_nan(x) ? limits<Type>::quiet_NaN()
|
||||
: limits<Type>::min() > abs(x) ? Type{0}
|
||||
: x < Type{0} ? -tan_begin(-x)
|
||||
: tan_begin(x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type sin(const Type x) noexcept
|
||||
{
|
||||
return is_nan(x) ? limits<Type>::quiet_NaN()
|
||||
: limits<Type>::min() > abs(x) ? Type{0}
|
||||
: limits<Type>::min() > abs(x - half_pi<Type>) ? Type{1}
|
||||
: limits<Type>::min() > abs(x + half_pi<Type>) ? -Type{1}
|
||||
: limits<Type>::min() > abs(x - pi<Type>) ? Type{0}
|
||||
: limits<Type>::min() > abs(x + pi<Type>)
|
||||
? -Type{0}
|
||||
: (Type{2} * tan(x / Type{2})) / (Type{1} + tan(x / Type{2}) * tan(x / Type{2}));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type cos(const Type x) noexcept
|
||||
{
|
||||
return is_nan(x) ? limits<Type>::quiet_NaN()
|
||||
: limits<Type>::min() > abs(x) ? Type{1}
|
||||
: limits<Type>::min() > abs(x - half_pi<Type>) ? Type{0}
|
||||
: limits<Type>::min() > abs(x + half_pi<Type>) ? Type{0}
|
||||
: limits<Type>::min() > abs(x - pi<Type>) ? -Type{1}
|
||||
: limits<Type>::min() > abs(x + pi<Type>)
|
||||
? -Type{1}
|
||||
: (Type{1} - tan(x / Type{2}) * tan(x / Type{2}))
|
||||
/ (Type{1} + tan(x / Type{2}) * tan(x / Type{2}));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type atan_series_order_calc(const Type xx, const Type x_pow, const uint_t order) noexcept
|
||||
{
|
||||
return Type{1} / (static_cast<Type>((order - 1) * 4 - 1) * x_pow)
|
||||
- Type{1} / (static_cast<Type>((order - 1) * 4 + 1) * x_pow * xx);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type atan_series_order(const Type x, const uint_t order_begin, const uint_t max_order) noexcept
|
||||
{
|
||||
if (max_order == 1)
|
||||
return half_pi<Type> - Type{1} / x;
|
||||
|
||||
const Type xx = x * x;
|
||||
Type result = atan_series_order_calc(xx, pow_integral(x, 4 * max_order - 5), max_order);
|
||||
auto depth = max_order - 1;
|
||||
|
||||
while (depth > order_begin)
|
||||
{
|
||||
result += atan_series_order_calc(xx, pow_integral(x, 4 * depth - 5), depth);
|
||||
--depth;
|
||||
}
|
||||
|
||||
return result + half_pi<Type> - Type{1} / x;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type atan_series_main(const Type x) noexcept
|
||||
{
|
||||
return x < Type{3} ? atan_series_order(x, 1U, 10U)
|
||||
: x < Type{4} ? atan_series_order(x, 1U, 9U)
|
||||
: x < Type{5} ? atan_series_order(x, 1U, 8U)
|
||||
: x < Type{7} ? atan_series_order(x, 1U, 7U)
|
||||
: x < Type{11} ? atan_series_order(x, 1U, 6U)
|
||||
: x < Type{25} ? atan_series_order(x, 1U, 5U)
|
||||
: x < Type{100} ? atan_series_order(x, 1U, 4U)
|
||||
: x < Type{1000} ? atan_series_order(x, 1U, 3U)
|
||||
: atan_series_order(x, 1U, 2U);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type atan_cf_recur(const Type xx, const uint_t depth_begin, const uint_t max_depth) noexcept
|
||||
{
|
||||
auto depth = max_depth - 1;
|
||||
Type result = static_cast<Type>(2 * (depth + 1) - 1);
|
||||
|
||||
while (depth > depth_begin - 1)
|
||||
{
|
||||
result = static_cast<Type>(2 * depth - 1) + static_cast<Type>(depth * depth) * xx / result;
|
||||
--depth;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type atan_cf_main(const Type x) noexcept
|
||||
{
|
||||
return x < Type{0.5} ? x / atan_cf_recur(x * x, 1U, 15U)
|
||||
: x < Type{1} ? x / atan_cf_recur(x * x, 1U, 25U)
|
||||
: x < Type{1.5} ? x / atan_cf_recur(x * x, 1U, 35U)
|
||||
: x < Type{2} ? x / atan_cf_recur(x * x, 1U, 45U)
|
||||
: x / atan_cf_recur(x * x, 1U, 52U);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type atan_begin(const Type x) noexcept
|
||||
{
|
||||
return x > Type{2.5} ? atan_series_main(x) : atan_cf_main(x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type atan(const Type x) noexcept
|
||||
{
|
||||
return is_nan(x) ? limits<Type>::quiet_NaN()
|
||||
: limits<Type>::min() > abs(x) ? Type{0}
|
||||
: x < Type{0} ? -atan_begin(-x)
|
||||
: atan_begin(x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type atan2(const Type y, const Type x) noexcept
|
||||
{
|
||||
return any_nan(y, x) ? limits<Type>::quiet_NaN()
|
||||
: limits<Type>::min() > abs(x) ? limits<Type>::min() > abs(y)
|
||||
? neg_zero(y) ? neg_zero(x) ? -pi<Type> : -Type{0}
|
||||
: neg_zero(x) ? pi<Type>
|
||||
: Type{0}
|
||||
: y > Type{0} ? half_pi<Type>
|
||||
: -half_pi<Type>
|
||||
: x < Type{0} ? y < Type{0} ? atan(y / x) - pi<Type> : atan(y / x) + pi<Type>
|
||||
: atan(y / x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type asin_compute(const Type x) noexcept
|
||||
{
|
||||
return x > Type{1} ? limits<Type>::quiet_NaN()
|
||||
: limits<Type>::min() > abs(x - Type{1}) ? half_pi<Type>
|
||||
: limits<Type>::min() > abs(x) ? Type{0}
|
||||
: atan(x / sqrt(Type{1} - x * x));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type asin(const Type x) noexcept
|
||||
{
|
||||
return is_nan(x) ? limits<Type>::quiet_NaN() : x < Type{0} ? -asin_compute(-x) : asin_compute(x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type acos_compute(const Type x) noexcept
|
||||
{
|
||||
return abs(x) > Type{1} ? limits<Type>::quiet_NaN()
|
||||
: limits<Type>::min() > abs(x - Type{1}) ? Type{0}
|
||||
: limits<Type>::min() > abs(x) ? half_pi<Type>
|
||||
: atan(sqrt(Type{1} - x * x) / x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type acos(const Type x) noexcept
|
||||
{
|
||||
return is_nan(x) ? limits<Type>::quiet_NaN() : x > Type{0} ? acos_compute(x) : pi<Type> - acos_compute(-x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type hypot(const Type x, const Type y) noexcept
|
||||
{
|
||||
return any_nan(x, y) ? limits<Type>::quiet_NaN()
|
||||
: any_inf(x, y) ? limits<Type>::infinity()
|
||||
: limits<Type>::min() > abs(x) ? abs(y)
|
||||
: limits<Type>::min() > abs(y) ? abs(x)
|
||||
: abs(x) * sqrt(Type{1} + (y / x) * (y / x));
|
||||
}
|
||||
} // namespace math_detail
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type sin(const Type& value) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::sin(value);
|
||||
}
|
||||
return std::sin(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type cos(const Type& value) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::cos(value);
|
||||
}
|
||||
return std::cos(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type tan(const Type& value) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::tan(value);
|
||||
}
|
||||
return std::tan(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type atan(const Type& value) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::atan(value);
|
||||
}
|
||||
return std::atan(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type atan2(const Type& y, const Type& x) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::atan2(y, x);
|
||||
}
|
||||
return std::atan2(y, x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type asin(const Type& value) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::asin(value);
|
||||
}
|
||||
return std::asin(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type acos(const Type& value) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::acos(value);
|
||||
}
|
||||
return std::acos(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type sqrt(const Type& value) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::sqrt(value);
|
||||
}
|
||||
return std::sqrt(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type hypot(const Type& x, const Type& y) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::hypot(x, y);
|
||||
}
|
||||
return std::hypot(x, y);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type hypot(const Type& x, const Type& y, const Type& z) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
return std::hypot(x, y, z);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type abs(const Type& value) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::abs(value);
|
||||
}
|
||||
return std::abs(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
constexpr Type fmod(const Type& dividend, const Type& divisor) noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
return math_detail::fmod(dividend, divisor);
|
||||
}
|
||||
return std::fmod(dividend, divisor);
|
||||
}
|
||||
} // namespace omath::internal
|
||||
@@ -1,185 +0,0 @@
|
||||
//
|
||||
// Created by orange on 6/11/2026.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
#include <gcem.hpp>
|
||||
#define OMATH_CONSTEXPR constexpr
|
||||
#else
|
||||
#define OMATH_CONSTEXPR
|
||||
#endif
|
||||
|
||||
namespace omath::internal
|
||||
{
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type sin(const Type& value) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::sin(value);
|
||||
}
|
||||
#endif
|
||||
return std::sin(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type cos(const Type& value) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::cos(value);
|
||||
}
|
||||
#endif
|
||||
return std::cos(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type tan(const Type& value) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::tan(value);
|
||||
}
|
||||
#endif
|
||||
return std::tan(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type atan(const Type& value) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::atan(value);
|
||||
}
|
||||
#endif
|
||||
return std::atan(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type atan2(const Type& y, const Type& x) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::atan2(y, x);
|
||||
}
|
||||
#endif
|
||||
return std::atan2(y, x);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type asin(const Type& value) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::asin(value);
|
||||
}
|
||||
#endif
|
||||
return std::asin(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type acos(const Type& value) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::acos(value);
|
||||
}
|
||||
#endif
|
||||
return std::acos(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type sqrt(const Type& value) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::sqrt(value);
|
||||
}
|
||||
#endif
|
||||
return std::sqrt(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type hypot(const Type& x, const Type& y) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::hypot(x, y);
|
||||
}
|
||||
#endif
|
||||
return std::hypot(x, y);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type hypot(const Type& x, const Type& y, const Type& z) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
#endif
|
||||
return std::hypot(x, y, z);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type abs(const Type& value) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::abs(value);
|
||||
}
|
||||
#endif
|
||||
return std::abs(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type fmod(const Type& dividend, const Type& divisor) noexcept
|
||||
{
|
||||
#ifdef OMATH_USE_GCEM
|
||||
if consteval
|
||||
{
|
||||
return gcem::fmod(dividend, divisor);
|
||||
}
|
||||
#endif
|
||||
return std::fmod(dividend, divisor);
|
||||
}
|
||||
} // namespace omath::internal
|
||||
@@ -2,7 +2,7 @@
|
||||
// Created by vlad on 9/29/2024.
|
||||
//
|
||||
#pragma once
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "vector3.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -43,12 +43,12 @@ namespace omath
|
||||
enum class NDCDepthRange : uint8_t
|
||||
{
|
||||
NEGATIVE_ONE_TO_ONE = 0, // OpenGL: [-1.0, 1.0]
|
||||
ZERO_TO_ONE // DirectX / Vulkan: [0.0, 1.0]
|
||||
ZERO_TO_ONE // DirectX / Vulkan: [0.0, 1.0]
|
||||
};
|
||||
|
||||
template<typename M1, typename M2> concept MatTemplateEqual
|
||||
= (M1::rows == M2::rows) && (M1::columns == M2::columns)
|
||||
&& std::is_same_v<typename M1::value_type, typename M2::value_type> && (M1::store_type == M2::store_type);
|
||||
template<typename M1, typename M2> concept MatTemplateEqual =
|
||||
(M1::rows == M2::rows) && (M1::columns == M2::columns)
|
||||
&& std::is_same_v<typename M1::value_type, typename M2::value_type> && (M1::store_type == M2::store_type);
|
||||
|
||||
template<size_t Rows = 0, size_t Columns = 0, class Type = float, MatStoreType StoreType = MatStoreType::ROW_MAJOR>
|
||||
requires std::is_arithmetic_v<Type>
|
||||
@@ -202,7 +202,11 @@ namespace omath
|
||||
|
||||
constexpr Mat& operator*=(const Type& f) noexcept
|
||||
{
|
||||
std::ranges::for_each(m_data, [&f](auto& val) { val *= f; });
|
||||
std::ranges::for_each(m_data,
|
||||
[&f](auto& val)
|
||||
{
|
||||
val *= f;
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -222,7 +226,11 @@ namespace omath
|
||||
|
||||
constexpr Mat& operator/=(const Type& value) noexcept
|
||||
{
|
||||
std::ranges::for_each(m_data, [&value](auto& val) { val /= value; });
|
||||
std::ranges::for_each(m_data,
|
||||
[&value](auto& val)
|
||||
{
|
||||
val /= value;
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -603,8 +611,7 @@ namespace omath
|
||||
[[nodiscard("You must use translation matrix")]]
|
||||
constexpr Mat<4, 4, Type, St> mat_translation(const Vector3<Type>& diff) noexcept
|
||||
{
|
||||
return
|
||||
{
|
||||
return {
|
||||
{1, 0, 0, diff.x},
|
||||
{0, 1, 0, diff.y},
|
||||
{0, 0, 1, diff.z},
|
||||
@@ -632,9 +639,10 @@ namespace omath
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||
[[nodiscard("You must use extracted scale")]]
|
||||
OMATH_CONSTEXPR Vector3<Type> mat_extract_scale(const Mat<4, 4, Type, St>& mat) noexcept
|
||||
constexpr Vector3<Type> mat_extract_scale(const Mat<4, 4, Type, St>& mat) noexcept
|
||||
{
|
||||
auto column_length = [](const Type x, const Type y, const Type z) {
|
||||
auto column_length = [](const Type x, const Type y, const Type z)
|
||||
{
|
||||
return static_cast<Type>(internal::sqrt(x * x + y * y + z * z));
|
||||
};
|
||||
|
||||
@@ -672,96 +680,83 @@ namespace omath
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||
[[nodiscard("You must use rotation matrix")]]
|
||||
OMATH_CONSTEXPR Mat<4, 4, Type, St> mat_rotation_axis_x(const Angle& angle) noexcept
|
||||
constexpr Mat<4, 4, Type, St> mat_rotation_axis_x(const Angle& angle) noexcept
|
||||
{
|
||||
return
|
||||
{
|
||||
{1, 0, 0, 0},
|
||||
{0, angle.cos(), -angle.sin(), 0},
|
||||
{0, angle.sin(), angle.cos(), 0},
|
||||
{0, 0, 0, 1}
|
||||
};
|
||||
return {{1, 0, 0, 0}, {0, angle.cos(), -angle.sin(), 0}, {0, angle.sin(), angle.cos(), 0}, {0, 0, 0, 1}};
|
||||
}
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||
[[nodiscard("You must use rotation matrix")]]
|
||||
OMATH_CONSTEXPR Mat<4, 4, Type, St> mat_rotation_axis_y(const Angle& angle) noexcept
|
||||
constexpr Mat<4, 4, Type, St> mat_rotation_axis_y(const Angle& angle) noexcept
|
||||
{
|
||||
return
|
||||
{
|
||||
{angle.cos(), 0, angle.sin(), 0},
|
||||
{0 , 1, 0, 0},
|
||||
{-angle.sin(), 0, angle.cos(), 0},
|
||||
{0 , 0, 0, 1}
|
||||
};
|
||||
return {{angle.cos(), 0, angle.sin(), 0}, {0, 1, 0, 0}, {-angle.sin(), 0, angle.cos(), 0}, {0, 0, 0, 1}};
|
||||
}
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||
[[nodiscard("You must use rotation matrix")]]
|
||||
OMATH_CONSTEXPR Mat<4, 4, Type, St> mat_rotation_axis_z(const Angle& angle) noexcept
|
||||
constexpr Mat<4, 4, Type, St> mat_rotation_axis_z(const Angle& angle) noexcept
|
||||
{
|
||||
return
|
||||
{
|
||||
{angle.cos(), -angle.sin(), 0, 0},
|
||||
{angle.sin(), angle.cos(), 0, 0},
|
||||
{ 0, 0, 1, 0},
|
||||
{ 0, 0, 0, 1},
|
||||
return {
|
||||
{angle.cos(), -angle.sin(), 0, 0},
|
||||
{angle.sin(), angle.cos(), 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 0, 1},
|
||||
};
|
||||
}
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||
[[nodiscard("You must use camera view matrix")]]
|
||||
OMATH_CONSTEXPR Mat<4, 4, Type, St> mat_camera_view(const Vector3<Type>& forward, const Vector3<Type>& right,
|
||||
const Vector3<Type>& up, const Vector3<Type>& camera_origin) noexcept
|
||||
constexpr Mat<4, 4, Type, St> mat_camera_view(const Vector3<Type>& forward, const Vector3<Type>& right,
|
||||
const Vector3<Type>& up, const Vector3<Type>& camera_origin) noexcept
|
||||
{
|
||||
return Mat<4, 4, Type, St>
|
||||
{
|
||||
{right.x, right.y, right.z, 0},
|
||||
{up.x, up.y, up.z, 0},
|
||||
{forward.x, forward.y, forward.z, 0},
|
||||
{0, 0, 0, 1},
|
||||
} * mat_translation<Type, St>(-camera_origin);
|
||||
return Mat<4, 4, Type, St>{
|
||||
{right.x, right.y, right.z, 0},
|
||||
{up.x, up.y, up.z, 0},
|
||||
{forward.x, forward.y, forward.z, 0},
|
||||
{0, 0, 0, 1},
|
||||
}
|
||||
* mat_translation<Type, St>(-camera_origin);
|
||||
}
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||
[[nodiscard("You must use perspective matrix")]] OMATH_CONSTEXPR
|
||||
Mat<4, 4, Type, St> mat_perspective_left_handed_vertical_fov(const Type field_of_view, const Type aspect_ratio,
|
||||
const Type near, const Type far) noexcept
|
||||
[[nodiscard("You must use perspective matrix")]] constexpr Mat<4, 4, Type, St>
|
||||
mat_perspective_left_handed_vertical_fov(const Type field_of_view, const Type aspect_ratio, const Type near,
|
||||
const Type far) noexcept
|
||||
{
|
||||
const auto fov_half_tan = internal::tan(angles::degrees_to_radians(field_of_view) / Type{2});
|
||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, far / (far - near), -(near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, far / (far - near), -(near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, (far + near) / (far - near), -(Type{2} * near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, (far + near) / (far - near), -(Type{2} * near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||
[[nodiscard("You must use perspective matrix")]] OMATH_CONSTEXPR
|
||||
Mat<4, 4, Type, St> mat_perspective_right_handed_vertical_fov(const Type field_of_view, const Type aspect_ratio,
|
||||
const Type near, const Type far) noexcept
|
||||
[[nodiscard("You must use perspective matrix")]] constexpr Mat<4, 4, Type, St>
|
||||
mat_perspective_right_handed_vertical_fov(const Type field_of_view, const Type aspect_ratio, const Type near,
|
||||
const Type far) noexcept
|
||||
{
|
||||
const auto fov_half_tan = internal::tan(angles::degrees_to_radians(field_of_view) / Type{2});
|
||||
|
||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, -far / (far - near), -(near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, -far / (far - near), -(near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, -(far + near) / (far - near), -(Type{2} * near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, -(far + near) / (far - near), -(Type{2} * near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
@@ -771,35 +766,33 @@ namespace omath
|
||||
// X and Y scales derived as: X = 1 / tan(hfov/2), Y = aspect / tan(hfov/2).
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||
[[nodiscard("You must use perspective matrix")]] OMATH_CONSTEXPR
|
||||
Mat<4, 4, Type, St> mat_perspective_left_handed_horizontal_fov(const Type horizontal_fov,
|
||||
const Type aspect_ratio, const Type near,
|
||||
const Type far) noexcept
|
||||
[[nodiscard("You must use perspective matrix")]] constexpr Mat<4, 4, Type, St>
|
||||
mat_perspective_left_handed_horizontal_fov(const Type horizontal_fov, const Type aspect_ratio, const Type near,
|
||||
const Type far) noexcept
|
||||
{
|
||||
const auto inv_tan_half_hfov = Type{1} / internal::tan(angles::degrees_to_radians(horizontal_fov) / Type{2});
|
||||
const auto x_axis = inv_tan_half_hfov;
|
||||
const auto y_axis = inv_tan_half_hfov * aspect_ratio;
|
||||
|
||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, far / (far - near), -(near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, far / (far - near), -(near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, (far + near) / (far - near), -(Type{2} * near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||
[[nodiscard("You must use perspective matrix")]] OMATH_CONSTEXPR
|
||||
Mat<4, 4, Type, St> mat_perspective_right_handed_horizontal_fov(const Type horizontal_fov,
|
||||
const Type aspect_ratio, const Type near,
|
||||
const Type far) noexcept
|
||||
[[nodiscard("You must use perspective matrix")]] constexpr Mat<4, 4, Type, St>
|
||||
mat_perspective_right_handed_horizontal_fov(const Type horizontal_fov, const Type aspect_ratio, const Type near,
|
||||
const Type far) noexcept
|
||||
{
|
||||
const auto inv_tan_half_hfov = Type{1} / internal::tan(angles::degrees_to_radians(horizontal_fov) / Type{2});
|
||||
|
||||
@@ -807,70 +800,59 @@ namespace omath
|
||||
const auto y_axis = inv_tan_half_hfov * aspect_ratio;
|
||||
|
||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, -far / (far - near), -(near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||
{Type{0}, Type{0}, -(far + near) / (far - near), -(Type{2} * near * far) / (far - near)},
|
||||
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||
[[nodiscard("You must use ortho matrix")]] OMATH_CONSTEXPR
|
||||
Mat<4, 4, Type, St> mat_ortho_left_handed(const Type left, const Type right, const Type bottom, const Type top,
|
||||
const Type near, const Type far) noexcept
|
||||
[[nodiscard("You must use ortho matrix")]] constexpr Mat<4, 4, Type, St>
|
||||
mat_ortho_left_handed(const Type left, const Type right, const Type bottom, const Type top, const Type near,
|
||||
const Type far) noexcept
|
||||
{
|
||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||
return
|
||||
{
|
||||
{ static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
||||
{ 0.f, static_cast<Type>(2) / (top - bottom), 0.f, -(top + bottom) / (top - bottom)},
|
||||
{ 0.f, 0.f, static_cast<Type>(1) / (far - near), -near / (far - near) },
|
||||
{ 0.f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
return {{static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
||||
{0.f, static_cast<Type>(2) / (top - bottom), 0.f, -(top + bottom) / (top - bottom)},
|
||||
{0.f, 0.f, static_cast<Type>(1) / (far - near), -near / (far - near)},
|
||||
{0.f, 0.f, 0.f, 1.f}};
|
||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return
|
||||
{
|
||||
{ static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
||||
{ 0.f, static_cast<Type>(2) / (top - bottom), 0.f, -(top + bottom) / (top - bottom)},
|
||||
{ 0.f, 0.f, static_cast<Type>(2) / (far - near), -(far + near) / (far - near) },
|
||||
{ 0.f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
return {{static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
||||
{0.f, static_cast<Type>(2) / (top - bottom), 0.f, -(top + bottom) / (top - bottom)},
|
||||
{0.f, 0.f, static_cast<Type>(2) / (far - near), -(far + near) / (far - near)},
|
||||
{0.f, 0.f, 0.f, 1.f}};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||
[[nodiscard("You must use ortho matrix")]] OMATH_CONSTEXPR
|
||||
Mat<4, 4, Type, St> mat_ortho_right_handed(const Type left, const Type right, const Type bottom, const Type top,
|
||||
const Type near, const Type far) noexcept
|
||||
[[nodiscard("You must use ortho matrix")]] constexpr Mat<4, 4, Type, St>
|
||||
mat_ortho_right_handed(const Type left, const Type right, const Type bottom, const Type top, const Type near,
|
||||
const Type far) noexcept
|
||||
{
|
||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||
return
|
||||
{
|
||||
{ static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
||||
{ 0.f, static_cast<Type>(2) / (top - bottom), 0.f, -(top + bottom) / (top - bottom)},
|
||||
{ 0.f, 0.f, -static_cast<Type>(1) / (far - near), -near / (far - near) },
|
||||
{ 0.f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
return {{static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
||||
{0.f, static_cast<Type>(2) / (top - bottom), 0.f, -(top + bottom) / (top - bottom)},
|
||||
{0.f, 0.f, -static_cast<Type>(1) / (far - near), -near / (far - near)},
|
||||
{0.f, 0.f, 0.f, 1.f}};
|
||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return
|
||||
{
|
||||
{ static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
||||
{ 0.f, static_cast<Type>(2) / (top - bottom), 0.f, -(top + bottom) / (top - bottom)},
|
||||
{ 0.f, 0.f, -static_cast<Type>(2) / (far - near), -(far + near) / (far - near) },
|
||||
{ 0.f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
return {{static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
||||
{0.f, static_cast<Type>(2) / (top - bottom), 0.f, -(top + bottom) / (top - bottom)},
|
||||
{0.f, 0.f, -static_cast<Type>(2) / (far - near), -(far + near) / (far - near)},
|
||||
{0.f, 0.f, 0.f, 1.f}};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
template<class T = float, MatStoreType St = MatStoreType::COLUMN_MAJOR>
|
||||
OMATH_CONSTEXPR Mat<4, 4, T, St> mat_look_at_left_handed(const Vector3<T>& eye, const Vector3<T>& center, const Vector3<T>& up)
|
||||
constexpr Mat<4, 4, T, St> mat_look_at_left_handed(const Vector3<T>& eye, const Vector3<T>& center,
|
||||
const Vector3<T>& up)
|
||||
{
|
||||
const Vector3<T> f = (center - eye).normalized();
|
||||
const Vector3<T> s = f.cross(up).normalized();
|
||||
@@ -879,7 +861,8 @@ namespace omath
|
||||
}
|
||||
|
||||
template<class T = float, MatStoreType St = MatStoreType::COLUMN_MAJOR>
|
||||
OMATH_CONSTEXPR Mat<4, 4, T, St> mat_look_at_right_handed(const Vector3<T>& eye, const Vector3<T>& center, const Vector3<T>& up)
|
||||
constexpr Mat<4, 4, T, St> mat_look_at_right_handed(const Vector3<T>& eye, const Vector3<T>& center,
|
||||
const Vector3<T>& up)
|
||||
{
|
||||
const Vector3<T> f = (center - eye).normalized();
|
||||
const Vector3<T> s = f.cross(up).normalized();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Created by Orange on 11/13/2024.
|
||||
//
|
||||
#pragma once
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "vector3.hpp"
|
||||
namespace omath
|
||||
{
|
||||
@@ -40,13 +40,13 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Vector::ContainedType side_a_length() const
|
||||
constexpr Vector::ContainedType side_a_length() const
|
||||
{
|
||||
return m_vertex1.distance_to(m_vertex2);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Vector::ContainedType side_b_length() const
|
||||
constexpr Vector::ContainedType side_b_length() const
|
||||
{
|
||||
return m_vertex3.distance_to(m_vertex2);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include <cmath>
|
||||
#include <format>
|
||||
#include <tuple>
|
||||
@@ -117,7 +117,7 @@ namespace omath
|
||||
|
||||
// Basic vector operations
|
||||
[[nodiscard("You must use distance")]]
|
||||
OMATH_CONSTEXPR Type distance_to(const Vector2& other) const noexcept
|
||||
constexpr Type distance_to(const Vector2& other) const noexcept
|
||||
{
|
||||
return internal::sqrt(distance_to_sqr(other));
|
||||
}
|
||||
@@ -147,13 +147,13 @@ namespace omath
|
||||
}
|
||||
#else
|
||||
[[nodiscard("You must use length")]]
|
||||
OMATH_CONSTEXPR Type length() const noexcept
|
||||
constexpr Type length() const noexcept
|
||||
{
|
||||
return internal::hypot(x, y);
|
||||
}
|
||||
|
||||
[[nodiscard("You must use normalized vector")]]
|
||||
OMATH_CONSTEXPR Vector2 normalized() const noexcept
|
||||
constexpr Vector2 normalized() const noexcept
|
||||
{
|
||||
const Type len = length();
|
||||
return len > static_cast<Type>(0) ? *this / len : *this;
|
||||
@@ -217,24 +217,24 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard("You must use comparison result")]]
|
||||
OMATH_CONSTEXPR bool operator<(const Vector2& other) const noexcept
|
||||
constexpr bool operator<(const Vector2& other) const noexcept
|
||||
{
|
||||
return length() < other.length();
|
||||
}
|
||||
[[nodiscard("You must use comparison result")]]
|
||||
OMATH_CONSTEXPR bool operator>(const Vector2& other) const noexcept
|
||||
constexpr bool operator>(const Vector2& other) const noexcept
|
||||
{
|
||||
return length() > other.length();
|
||||
}
|
||||
|
||||
[[nodiscard("You must use comparison result")]]
|
||||
OMATH_CONSTEXPR bool operator<=(const Vector2& other) const noexcept
|
||||
constexpr bool operator<=(const Vector2& other) const noexcept
|
||||
{
|
||||
return length() <= other.length();
|
||||
}
|
||||
|
||||
[[nodiscard("You must use comparison result")]]
|
||||
OMATH_CONSTEXPR bool operator>=(const Vector2& other) const noexcept
|
||||
constexpr bool operator>=(const Vector2& other) const noexcept
|
||||
{
|
||||
return length() >= other.length();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/linear_algebra/vector2.hpp"
|
||||
#include "omath/trigonometry/angle.hpp"
|
||||
#include <cstdint>
|
||||
@@ -150,7 +150,7 @@ namespace omath
|
||||
{
|
||||
return Vector2<Type>::length();
|
||||
}
|
||||
[[nodiscard("You must use distance")]] OMATH_CONSTEXPR Type distance_to(const Vector3& other) const noexcept
|
||||
[[nodiscard("You must use distance")]] constexpr Type distance_to(const Vector3& other) const noexcept
|
||||
{
|
||||
return (*this - other).length();
|
||||
}
|
||||
@@ -162,13 +162,13 @@ namespace omath
|
||||
}
|
||||
#else
|
||||
[[nodiscard("You must use length")]]
|
||||
OMATH_CONSTEXPR Type length() const noexcept
|
||||
constexpr Type length() const noexcept
|
||||
{
|
||||
return internal::hypot(this->x, this->y, this->z);
|
||||
}
|
||||
|
||||
[[nodiscard("You must use normalized vector")]]
|
||||
OMATH_CONSTEXPR Vector3 normalized() const noexcept
|
||||
constexpr Vector3 normalized() const noexcept
|
||||
{
|
||||
const Type len = this->length();
|
||||
|
||||
@@ -176,13 +176,13 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard("You must use 2D length")]]
|
||||
OMATH_CONSTEXPR Type length_2d() const noexcept
|
||||
constexpr Type length_2d() const noexcept
|
||||
{
|
||||
return Vector2<Type>::length();
|
||||
}
|
||||
|
||||
[[nodiscard("You must use distance")]]
|
||||
OMATH_CONSTEXPR Type distance_to(const Vector3& v_other) const noexcept
|
||||
constexpr Type distance_to(const Vector3& v_other) const noexcept
|
||||
{
|
||||
return (*this - v_other).length();
|
||||
}
|
||||
@@ -250,12 +250,12 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard("You must use direction check result")]]
|
||||
OMATH_CONSTEXPR bool point_to_same_direction(const Vector3& other) const
|
||||
constexpr bool point_to_same_direction(const Vector3& other) const
|
||||
{
|
||||
return dot(other) > static_cast<Type>(0);
|
||||
}
|
||||
[[nodiscard("You must use angle between vectors")]]
|
||||
OMATH_CONSTEXPR std::expected<Angle<float, 0.f, 180.f, AngleFlags::Clamped>, Vector3Error>
|
||||
constexpr std::expected<Angle<float, 0.f, 180.f, AngleFlags::Clamped>, Vector3Error>
|
||||
angle_between(const Vector3& other) const noexcept
|
||||
{
|
||||
const auto bottom = length() * other.length();
|
||||
@@ -266,8 +266,7 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard("You must use perpendicularity check result")]]
|
||||
OMATH_CONSTEXPR bool is_perpendicular(const Vector3& other,
|
||||
Type epsilon = static_cast<Type>(0.0001)) const noexcept
|
||||
constexpr bool is_perpendicular(const Vector3& other, Type epsilon = static_cast<Type>(0.0001)) const noexcept
|
||||
{
|
||||
if (const auto angle = angle_between(other))
|
||||
return std::abs(angle->as_degrees() - static_cast<Type>(90)) <= epsilon;
|
||||
@@ -288,25 +287,25 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard("You must use comparison result")]]
|
||||
OMATH_CONSTEXPR bool operator<(const Vector3& other) const noexcept
|
||||
constexpr bool operator<(const Vector3& other) const noexcept
|
||||
{
|
||||
return length() < other.length();
|
||||
}
|
||||
|
||||
[[nodiscard("You must use comparison result")]]
|
||||
OMATH_CONSTEXPR bool operator>(const Vector3& other) const noexcept
|
||||
constexpr bool operator>(const Vector3& other) const noexcept
|
||||
{
|
||||
return length() > other.length();
|
||||
}
|
||||
|
||||
[[nodiscard("You must use comparison result")]]
|
||||
OMATH_CONSTEXPR bool operator<=(const Vector3& other) const noexcept
|
||||
constexpr bool operator<=(const Vector3& other) const noexcept
|
||||
{
|
||||
return length() <= other.length();
|
||||
}
|
||||
|
||||
[[nodiscard("You must use comparison result")]]
|
||||
OMATH_CONSTEXPR bool operator>=(const Vector3& other) const noexcept
|
||||
constexpr bool operator>=(const Vector3& other) const noexcept
|
||||
{
|
||||
return length() >= other.length();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "omath/3d_primitives/aabb.hpp"
|
||||
#include "omath/3d_primitives/obb.hpp"
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/linear_algebra/mat.hpp"
|
||||
#include "omath/linear_algebra/triangle.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
@@ -104,7 +104,7 @@ namespace omath::projection
|
||||
// NEGATIVE_ONE_TO_ONE) share the same m[0,0]/m[1,1] layout, so this works
|
||||
// regardless of the NDC depth range.
|
||||
[[nodiscard("You must use extracted projection params")]]
|
||||
OMATH_CONSTEXPR static ProjectionParams extract_projection_params(const Mat4X4Type& proj_matrix) noexcept
|
||||
constexpr static ProjectionParams extract_projection_params(const Mat4X4Type& proj_matrix) noexcept
|
||||
{
|
||||
// m[1,1] == 1 / tan(fov/2) => fov = 2 * atan(1 / m[1,1])
|
||||
const auto f = proj_matrix.at(1, 1);
|
||||
@@ -115,7 +115,7 @@ namespace omath::projection
|
||||
}
|
||||
|
||||
[[nodiscard("You must use calculated view angles")]]
|
||||
OMATH_CONSTEXPR static ViewAnglesType calc_view_angles_from_view_matrix(const Mat4X4Type& view_matrix) noexcept
|
||||
constexpr static ViewAnglesType calc_view_angles_from_view_matrix(const Mat4X4Type& view_matrix) noexcept
|
||||
{
|
||||
Vector3<NumericType> forward_vector = {view_matrix[2, 0], view_matrix[2, 1], view_matrix[2, 2]};
|
||||
if constexpr (axes.inverted_forward)
|
||||
@@ -138,20 +138,20 @@ namespace omath::projection
|
||||
};
|
||||
}
|
||||
|
||||
OMATH_CONSTEXPR void look_at(const Vector3<NumericType>& target)
|
||||
constexpr void look_at(const Vector3<NumericType>& target)
|
||||
{
|
||||
m_view_angles = TraitClass::calc_look_at_angle(m_origin, target);
|
||||
m_view_projection_matrix = std::nullopt;
|
||||
m_view_matrix = std::nullopt;
|
||||
}
|
||||
[[nodiscard("You must use calculated look-at angles")]]
|
||||
OMATH_CONSTEXPR ViewAnglesType calc_look_at_angles(const Vector3<NumericType>& look_to) const
|
||||
constexpr ViewAnglesType calc_look_at_angles(const Vector3<NumericType>& look_to) const
|
||||
{
|
||||
return TraitClass::calc_look_at_angle(m_origin, look_to);
|
||||
}
|
||||
|
||||
[[nodiscard("You must use forward vector")]]
|
||||
OMATH_CONSTEXPR Vector3<NumericType> get_forward() const noexcept
|
||||
constexpr Vector3<NumericType> get_forward() const noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
@@ -164,7 +164,7 @@ namespace omath::projection
|
||||
}
|
||||
|
||||
[[nodiscard("You must use right vector")]]
|
||||
OMATH_CONSTEXPR Vector3<NumericType> get_right() const noexcept
|
||||
constexpr Vector3<NumericType> get_right() const noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
@@ -177,7 +177,7 @@ namespace omath::projection
|
||||
}
|
||||
|
||||
[[nodiscard("You must use up vector")]]
|
||||
OMATH_CONSTEXPR Vector3<NumericType> get_up() const noexcept
|
||||
constexpr Vector3<NumericType> get_up() const noexcept
|
||||
{
|
||||
if consteval
|
||||
{
|
||||
@@ -189,7 +189,7 @@ namespace omath::projection
|
||||
return {view_matrix[1, 0], view_matrix[1, 1], view_matrix[1, 2]};
|
||||
}
|
||||
[[nodiscard("You must use absolute forward vector")]]
|
||||
OMATH_CONSTEXPR Vector3<NumericType> get_abs_forward() const noexcept
|
||||
constexpr Vector3<NumericType> get_abs_forward() const noexcept
|
||||
{
|
||||
if constexpr (axes.inverted_forward)
|
||||
return -get_forward();
|
||||
@@ -197,7 +197,7 @@ namespace omath::projection
|
||||
}
|
||||
|
||||
[[nodiscard("You must use absolute right vector")]]
|
||||
OMATH_CONSTEXPR Vector3<NumericType> get_abs_right() const noexcept
|
||||
constexpr Vector3<NumericType> get_abs_right() const noexcept
|
||||
{
|
||||
if constexpr (axes.inverted_right)
|
||||
return -get_right();
|
||||
@@ -205,32 +205,32 @@ namespace omath::projection
|
||||
}
|
||||
|
||||
[[nodiscard("You must use absolute up vector")]]
|
||||
OMATH_CONSTEXPR Vector3<NumericType> get_abs_up() const noexcept
|
||||
constexpr Vector3<NumericType> get_abs_up() const noexcept
|
||||
{
|
||||
return get_up();
|
||||
}
|
||||
|
||||
[[nodiscard("You must use calculated view-projection matrix")]]
|
||||
OMATH_CONSTEXPR Mat4X4Type calc_view_projection_matrix() const noexcept
|
||||
constexpr Mat4X4Type calc_view_projection_matrix() const noexcept
|
||||
{
|
||||
return calc_projection_matrix() * calc_view_matrix();
|
||||
}
|
||||
|
||||
[[nodiscard("You must use calculated view matrix")]]
|
||||
OMATH_CONSTEXPR Mat4X4Type calc_view_matrix() const noexcept
|
||||
constexpr Mat4X4Type calc_view_matrix() const noexcept
|
||||
{
|
||||
return TraitClass::calc_view_matrix(m_view_angles, m_origin);
|
||||
}
|
||||
|
||||
[[nodiscard("You must use calculated projection matrix")]]
|
||||
OMATH_CONSTEXPR Mat4X4Type calc_projection_matrix() const noexcept
|
||||
constexpr Mat4X4Type calc_projection_matrix() const noexcept
|
||||
{
|
||||
return TraitClass::calc_projection_matrix(
|
||||
m_field_of_view, m_view_port, m_near_plane_distance, m_far_plane_distance, depth_range);
|
||||
return TraitClass::calc_projection_matrix(m_field_of_view, m_view_port, m_near_plane_distance,
|
||||
m_far_plane_distance, depth_range);
|
||||
}
|
||||
|
||||
[[nodiscard("You must use view-projection matrix")]]
|
||||
OMATH_CONSTEXPR const Mat4X4Type& get_view_projection_matrix() const noexcept
|
||||
constexpr const Mat4X4Type& get_view_projection_matrix() const noexcept
|
||||
{
|
||||
if (!m_view_projection_matrix.has_value())
|
||||
m_view_projection_matrix = get_projection_matrix() * get_view_matrix();
|
||||
@@ -238,14 +238,15 @@ namespace omath::projection
|
||||
return m_view_projection_matrix.value();
|
||||
}
|
||||
|
||||
[[nodiscard("You must use view matrix")]] OMATH_CONSTEXPR const Mat4X4Type& get_view_matrix() const noexcept
|
||||
[[nodiscard("You must use view matrix")]] constexpr const Mat4X4Type& get_view_matrix() const noexcept
|
||||
{
|
||||
if (!m_view_matrix.has_value())
|
||||
m_view_matrix = calc_view_matrix();
|
||||
|
||||
return m_view_matrix.value();
|
||||
}
|
||||
[[nodiscard("You must use projection matrix")]] OMATH_CONSTEXPR const Mat4X4Type& get_projection_matrix() const noexcept
|
||||
[[nodiscard("You must use projection matrix")]] constexpr const Mat4X4Type&
|
||||
get_projection_matrix() const noexcept
|
||||
{
|
||||
if (!m_projection_matrix.has_value())
|
||||
m_projection_matrix = calc_projection_matrix();
|
||||
@@ -320,7 +321,7 @@ namespace omath::projection
|
||||
}
|
||||
|
||||
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
||||
[[nodiscard("You must use screen position")]] OMATH_CONSTEXPR std::expected<Vector3<NumericType>, Error>
|
||||
[[nodiscard("You must use screen position")]] constexpr std::expected<Vector3<NumericType>, Error>
|
||||
world_to_screen(const Vector3<NumericType>& world_position) const noexcept
|
||||
{
|
||||
const auto normalized_cords = world_to_view_port(world_position);
|
||||
@@ -336,7 +337,7 @@ namespace omath::projection
|
||||
std::unreachable();
|
||||
}
|
||||
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
||||
[[nodiscard("You must use unclipped screen position")]] OMATH_CONSTEXPR std::expected<Vector3<NumericType>, Error>
|
||||
[[nodiscard("You must use unclipped screen position")]] constexpr std::expected<Vector3<NumericType>, Error>
|
||||
world_to_screen_unclipped(const Vector3<NumericType>& world_position) const noexcept
|
||||
{
|
||||
const auto normalized_cords = world_to_view_port(world_position, ViewPortClipping::MANUAL);
|
||||
@@ -352,7 +353,7 @@ namespace omath::projection
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
[[nodiscard("You must use frustum culling result")]] OMATH_CONSTEXPR bool
|
||||
[[nodiscard("You must use frustum culling result")]] constexpr bool
|
||||
is_culled_by_frustum(const Triangle<Vector3<NumericType>>& triangle) const noexcept
|
||||
{
|
||||
// Transform to clip space (before perspective divide)
|
||||
@@ -420,7 +421,7 @@ namespace omath::projection
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard("You must use AABB frustum culling result")]] OMATH_CONSTEXPR bool
|
||||
[[nodiscard("You must use AABB frustum culling result")]] constexpr bool
|
||||
is_aabb_culled_by_frustum(const primitives::Aabb<NumericType>& aabb) const noexcept
|
||||
{
|
||||
// For each plane, find the AABB corner most in the direction of the plane normal
|
||||
@@ -438,7 +439,7 @@ namespace omath::projection
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard("You must use OBB frustum culling result")]] OMATH_CONSTEXPR bool
|
||||
[[nodiscard("You must use OBB frustum culling result")]] constexpr bool
|
||||
is_obb_culled_by_frustum(const primitives::Obb<NumericType>& obb) const noexcept
|
||||
{
|
||||
// For each plane, project the OBB extents onto the plane normal to get the
|
||||
@@ -459,7 +460,7 @@ namespace omath::projection
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard("You must use view port position")]] OMATH_CONSTEXPR std::expected<Vector3<NumericType>, Error>
|
||||
[[nodiscard("You must use view port position")]] constexpr std::expected<Vector3<NumericType>, Error>
|
||||
world_to_view_port(const Vector3<NumericType>& world_position,
|
||||
const ViewPortClipping& clipping = ViewPortClipping::AUTO) const noexcept
|
||||
{
|
||||
@@ -502,10 +503,11 @@ namespace omath::projection
|
||||
return project_to_view_port(projected);
|
||||
}
|
||||
[[nodiscard("You must use world position")]]
|
||||
OMATH_CONSTEXPR std::expected<Vector3<NumericType>, Error>
|
||||
constexpr std::expected<Vector3<NumericType>, Error>
|
||||
view_port_to_world(const Vector3<NumericType>& ndc) const noexcept
|
||||
{
|
||||
auto view_port_to_world = [&ndc](const Mat4X4Type& view_projection) -> std::expected<Vector3<NumericType>, Error>
|
||||
auto view_port_to_world =
|
||||
[&ndc](const Mat4X4Type& view_projection) -> std::expected<Vector3<NumericType>, Error>
|
||||
{
|
||||
const auto inv_view_proj = view_projection.inverted();
|
||||
|
||||
@@ -536,7 +538,7 @@ namespace omath::projection
|
||||
|
||||
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
||||
[[nodiscard("You must use world position")]]
|
||||
OMATH_CONSTEXPR std::expected<Vector3<NumericType>, Error>
|
||||
constexpr std::expected<Vector3<NumericType>, Error>
|
||||
screen_to_world(const Vector3<NumericType>& screen_pos) const noexcept
|
||||
{
|
||||
return view_port_to_world(screen_to_ndc<screen_start>(screen_pos));
|
||||
@@ -544,7 +546,7 @@ namespace omath::projection
|
||||
|
||||
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
||||
[[nodiscard("You must use world position")]]
|
||||
OMATH_CONSTEXPR std::expected<Vector3<NumericType>, Error>
|
||||
constexpr std::expected<Vector3<NumericType>, Error>
|
||||
screen_to_world(const Vector2<NumericType>& screen_pos) const noexcept
|
||||
{
|
||||
const auto& [x, y] = screen_pos;
|
||||
@@ -579,7 +581,7 @@ namespace omath::projection
|
||||
// Top = r3 - r1
|
||||
// Near = r3 + r2 ([-1,1]) or r2 ([0,1])
|
||||
// Far = r3 - r2
|
||||
[[nodiscard("You must use frustum planes")]] OMATH_CONSTEXPR std::array<FrustumPlane, 6>
|
||||
[[nodiscard("You must use frustum planes")]] constexpr std::array<FrustumPlane, 6>
|
||||
extract_frustum_planes() const noexcept
|
||||
{
|
||||
const auto& m = get_view_projection_matrix();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include "omath/trigonometry/angles.hpp"
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
@@ -71,31 +71,31 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type sin() const noexcept
|
||||
constexpr Type sin() const noexcept
|
||||
{
|
||||
return internal::sin(as_radians());
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type cos() const noexcept
|
||||
constexpr Type cos() const noexcept
|
||||
{
|
||||
return internal::cos(as_radians());
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type tan() const noexcept
|
||||
constexpr Type tan() const noexcept
|
||||
{
|
||||
return internal::tan(as_radians());
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type atan() const noexcept
|
||||
constexpr Type atan() const noexcept
|
||||
{
|
||||
return internal::atan(as_radians());
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
OMATH_CONSTEXPR Type cot() const noexcept
|
||||
constexpr Type cot() const noexcept
|
||||
{
|
||||
return cos() / sin();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "omath/internal/optional_constexpr_math.hpp"
|
||||
#include "omath/internal/constexpr_math.hpp"
|
||||
#include <cmath>
|
||||
#include <numbers>
|
||||
|
||||
@@ -25,20 +25,19 @@ namespace omath::angles
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]] OMATH_CONSTEXPR Type horizontal_fov_to_vertical(const Type& horizontal_fov,
|
||||
const Type& aspect) noexcept
|
||||
[[nodiscard]] constexpr Type horizontal_fov_to_vertical(const Type& horizontal_fov, const Type& aspect) noexcept
|
||||
{
|
||||
const auto fov_rad = degrees_to_radians(horizontal_fov);
|
||||
|
||||
const auto vert_fov = static_cast<Type>(2) * internal::atan(internal::tan(fov_rad / static_cast<Type>(2)) / aspect);
|
||||
const auto vert_fov =
|
||||
static_cast<Type>(2) * internal::atan(internal::tan(fov_rad / static_cast<Type>(2)) / aspect);
|
||||
|
||||
return radians_to_degrees(vert_fov);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]] OMATH_CONSTEXPR Type vertical_fov_to_horizontal(const Type& vertical_fov,
|
||||
const Type& aspect) noexcept
|
||||
[[nodiscard]] constexpr Type vertical_fov_to_horizontal(const Type& vertical_fov, const Type& aspect) noexcept
|
||||
{
|
||||
const auto fov_as_radians = degrees_to_radians(vertical_fov);
|
||||
|
||||
@@ -50,7 +49,7 @@ namespace omath::angles
|
||||
|
||||
template<class Type>
|
||||
requires std::is_arithmetic_v<Type>
|
||||
[[nodiscard]] OMATH_CONSTEXPR Type wrap_angle(const Type& angle, const Type& min, const Type& max) noexcept
|
||||
[[nodiscard]] constexpr Type wrap_angle(const Type& angle, const Type& min, const Type& max) noexcept
|
||||
{
|
||||
if (angle <= max && angle >= min)
|
||||
return angle;
|
||||
|
||||
+2
-7
@@ -10,8 +10,8 @@ module;
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <functional>
|
||||
#include <iomanip>
|
||||
#include <initializer_list>
|
||||
#include <iomanip>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
@@ -37,10 +37,6 @@ module;
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
|
||||
#if defined(OMATH_USE_GCEM)
|
||||
#include <gcem.hpp>
|
||||
#endif
|
||||
|
||||
#if defined(OMATH_IMGUI_INTEGRATION)
|
||||
#include <imgui.h>
|
||||
#endif
|
||||
@@ -58,7 +54,6 @@ module;
|
||||
|
||||
export module omath;
|
||||
|
||||
export
|
||||
{
|
||||
export {
|
||||
#include "omath/omath.hpp"
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
using namespace omath;
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
namespace
|
||||
{
|
||||
constexpr bool close_to(const float actual, const float expected, const float epsilon)
|
||||
@@ -41,7 +40,7 @@ static_assert(
|
||||
&& close_to(rotation.at(1, 1), 1.0f, 1e-5f) && close_to(rotation.at(2, 2), 1.0f, 1e-5f)
|
||||
&& close_to(rotation.at(3, 3), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"CryEngine basis vectors should be constexpr with gcem");
|
||||
"CryEngine basis vectors should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -50,7 +49,7 @@ static_assert(
|
||||
return close_to(view.at(0, 0), 1.0f, 1e-5f) && close_to(view.at(1, 2), 1.0f, 1e-5f)
|
||||
&& close_to(view.at(2, 1), 1.0f, 1e-5f) && close_to(view.at(3, 3), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"CryEngine view matrix should be constexpr with gcem");
|
||||
"CryEngine view matrix should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -62,7 +61,7 @@ static_assert(
|
||||
|
||||
return vec_close_to(origin, {1.0f, 2.0f, 3.0f}, 1e-5f) && vec_close_to(scale, {2.0f, 3.0f, 4.0f}, 1e-5f);
|
||||
}(),
|
||||
"CryEngine transform extraction should be constexpr with gcem");
|
||||
"CryEngine transform extraction should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -73,7 +72,7 @@ static_assert(
|
||||
&& close_to(projection.at(2, 2), 1.1f, 1e-5f) && close_to(projection.at(2, 3), -1.1f, 1e-5f)
|
||||
&& close_to(projection.at(3, 2), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"CryEngine projection matrix should be constexpr with gcem");
|
||||
"CryEngine projection matrix should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -91,7 +90,7 @@ static_assert(
|
||||
&& close_to(projection.at(1, 1), 1.0f, 1e-5f) && close_to(projection.at(2, 2), 1.1f, 1e-5f)
|
||||
&& close_to(projection.at(2, 3), -1.1f, 1e-5f) && close_to(projection.at(3, 2), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"CryEngine CameraTrait should be constexpr with gcem");
|
||||
"CryEngine CameraTrait should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(omath::cry_engine::units_to_centimeters(100.0f) == 1.0f);
|
||||
static_assert(omath::cry_engine::units_to_meters(2.0f) == 2.0f);
|
||||
@@ -99,7 +98,6 @@ static_assert(omath::cry_engine::units_to_kilometers(2000.0f) == 2.0f);
|
||||
static_assert(omath::cry_engine::centimeters_to_units(1.0f) == 100.0f);
|
||||
static_assert(omath::cry_engine::meters_to_units(2.0f) == 2.0f);
|
||||
static_assert(omath::cry_engine::kilometers_to_units(2.0f) == 2000.0f);
|
||||
#endif
|
||||
|
||||
TEST(unit_test_cry_engine, look_at_forward)
|
||||
{
|
||||
|
||||
@@ -1,40 +1,32 @@
|
||||
// Tests for engine trait headers to improve header coverage
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/engines/frostbite_engine/camera.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/iw_engine/camera.hpp>
|
||||
#include <omath/engines/iw_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/iw_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/iw_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/opengl_engine/camera.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/unity_engine/camera.hpp>
|
||||
#include <omath/engines/unity_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/unity_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/unity_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/unreal_engine/camera.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/source_engine/camera.hpp>
|
||||
#include <omath/engines/source_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/source_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/cry_engine/camera.hpp>
|
||||
#include <omath/engines/cry_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/frostbite_engine/camera.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/iw_engine/camera.hpp>
|
||||
#include <omath/engines/iw_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/iw_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/iw_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/opengl_engine/camera.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/rage_engine/camera.hpp>
|
||||
#include <omath/engines/rage_engine/traits/camera_trait.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>
|
||||
#include <omath/engines/unity_engine/camera.hpp>
|
||||
#include <omath/engines/unity_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/unity_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/unity_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/unreal_engine/camera.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/projectile_prediction/projectile.hpp>
|
||||
#include <omath/projectile_prediction/target.hpp>
|
||||
#include <optional>
|
||||
@@ -51,7 +43,6 @@ static void expect_matrix_near(const MatT& a, const MatT& b, float eps = 1e-5f)
|
||||
}
|
||||
|
||||
// ── Launch offset tests for all engines ──────────────────────────────────────
|
||||
#ifdef OMATH_USE_GCEM
|
||||
template<class MatType, class NumericType>
|
||||
constexpr bool matrix_has_non_zero_element(const MatType& mat)
|
||||
{
|
||||
@@ -86,7 +77,6 @@ static_assert(camera_can_calculate_matrices_at_compile_time<unity_engine::Camera
|
||||
static_assert(camera_can_calculate_matrices_at_compile_time<cry_engine::Camera, float>());
|
||||
static_assert(camera_can_calculate_matrices_at_compile_time<rage_engine::Camera, float>());
|
||||
static_assert(camera_can_calculate_matrices_at_compile_time<unreal_engine::Camera, double>());
|
||||
#endif
|
||||
|
||||
#include <omath/engines/cry_engine/traits/pred_engine_trait.hpp>
|
||||
|
||||
@@ -121,8 +111,10 @@ static void verify_zero_offset_matches_default()
|
||||
p2.m_launch_speed = static_cast<AT>(50);
|
||||
p2.m_gravity_scale = static_cast<AT>(1);
|
||||
|
||||
const auto pos1 = Trait::predict_projectile_position(p, static_cast<AT>(15), static_cast<AT>(30), static_cast<AT>(1), static_cast<AT>(9.81));
|
||||
const auto pos2 = Trait::predict_projectile_position(p2, static_cast<AT>(15), static_cast<AT>(30), static_cast<AT>(1), static_cast<AT>(9.81));
|
||||
const auto pos1 = Trait::predict_projectile_position(p, static_cast<AT>(15), static_cast<AT>(30),
|
||||
static_cast<AT>(1), static_cast<AT>(9.81));
|
||||
const auto pos2 = Trait::predict_projectile_position(p2, static_cast<AT>(15), static_cast<AT>(30),
|
||||
static_cast<AT>(1), static_cast<AT>(9.81));
|
||||
#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64)
|
||||
constexpr double tol = 1e-6;
|
||||
#else
|
||||
@@ -205,7 +197,8 @@ TEST(LaunchOffsetTests, OffsetShiftsTrajectory)
|
||||
p_with_offset.m_gravity_scale = 1.f;
|
||||
|
||||
const auto pos1 = source_engine::PredEngineTrait::predict_projectile_position(p_no_offset, 20.f, 45.f, 2.f, 9.81f);
|
||||
const auto pos2 = source_engine::PredEngineTrait::predict_projectile_position(p_with_offset, 20.f, 45.f, 2.f, 9.81f);
|
||||
const auto pos2 =
|
||||
source_engine::PredEngineTrait::predict_projectile_position(p_with_offset, 20.f, 45.f, 2.f, 9.81f);
|
||||
|
||||
// The difference should be exactly the launch offset
|
||||
EXPECT_NEAR(pos2.x - pos1.x, 10.f, 1e-4f);
|
||||
@@ -268,12 +261,16 @@ TEST(TraitTests, Frostbite_Pred_And_Mesh_And_Camera)
|
||||
// CameraTrait look at should be callable
|
||||
const auto angles = e::CameraTrait::calc_look_at_angle({0, 0, 0}, {0, 1, 1});
|
||||
(void)angles;
|
||||
const auto proj = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f);
|
||||
expect_matrix_near(proj, expected);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
EXPECT_NE(proj, proj_zo);
|
||||
}
|
||||
@@ -319,12 +316,16 @@ TEST(TraitTests, IW_Pred_And_Mesh_And_Camera)
|
||||
e::ViewAngles va;
|
||||
expect_matrix_near(e::MeshTrait::rotation_matrix(va), e::rotation_matrix(va));
|
||||
|
||||
const auto proj = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(45.f), {1920.f, 1080.f}, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(45.f), {1920.f, 1080.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected = e::calc_perspective_projection_matrix(45.f, 1920.f / 1080.f, 0.1f, 1000.f);
|
||||
expect_matrix_near(proj, expected);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(45.f), {1920.f, 1080.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(45.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(45.f), {1920.f, 1080.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(45.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
EXPECT_NE(proj, proj_zo);
|
||||
|
||||
@@ -374,12 +375,16 @@ TEST(TraitTests, OpenGL_Pred_And_Mesh_And_Camera)
|
||||
e::ViewAngles va;
|
||||
expect_matrix_near(e::MeshTrait::rotation_matrix(va), e::rotation_matrix(va));
|
||||
|
||||
const auto proj = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f);
|
||||
expect_matrix_near(proj, expected);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
EXPECT_NE(proj, proj_zo);
|
||||
|
||||
@@ -429,12 +434,16 @@ TEST(TraitTests, Unity_Pred_And_Mesh_And_Camera)
|
||||
e::ViewAngles va;
|
||||
expect_matrix_near(e::MeshTrait::rotation_matrix(va), e::rotation_matrix(va));
|
||||
|
||||
const auto proj = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f);
|
||||
expect_matrix_near(proj, expected);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
EXPECT_NE(proj, proj_zo);
|
||||
|
||||
@@ -484,12 +493,16 @@ TEST(TraitTests, Unreal_Pred_And_Mesh_And_Camera)
|
||||
e::ViewAngles va;
|
||||
expect_matrix_near(e::MeshTrait::rotation_matrix(va), e::rotation_matrix(va));
|
||||
|
||||
const auto proj = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f);
|
||||
expect_matrix_near(proj, expected);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
EXPECT_NE(proj, proj_zo);
|
||||
|
||||
@@ -505,18 +518,17 @@ TEST(NDCDepthRangeTests, Source_BothDepthRanges)
|
||||
{
|
||||
namespace e = omath::source_engine;
|
||||
|
||||
const auto proj_no = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected_no = e::calc_perspective_projection_matrix(
|
||||
90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj_no =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected_no = e::calc_perspective_projection_matrix(90.f, 1920.f / 1080.f, 0.1f, 1000.f,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
expect_matrix_near(proj_no, expected_no);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f,
|
||||
NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(
|
||||
90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
|
||||
EXPECT_NE(proj_no, proj_zo);
|
||||
@@ -526,18 +538,17 @@ TEST(NDCDepthRangeTests, CryEngine_BothDepthRanges)
|
||||
{
|
||||
namespace e = omath::cry_engine;
|
||||
|
||||
const auto proj_no = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected_no = e::calc_perspective_projection_matrix(
|
||||
90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj_no =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected_no = e::calc_perspective_projection_matrix(90.f, 1920.f / 1080.f, 0.1f, 1000.f,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
expect_matrix_near(proj_no, expected_no);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f,
|
||||
NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(
|
||||
90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
|
||||
EXPECT_NE(proj_no, proj_zo);
|
||||
@@ -584,7 +595,8 @@ TEST(NDCDepthRangeTests, OpenGL_ZeroToOne_ZRange)
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
|
||||
// OpenGL engine uses column-major matrices, project manually
|
||||
auto proj_z = [&](float z) {
|
||||
auto proj_z = [&](float z)
|
||||
{
|
||||
auto clip = proj * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>({0, 0, z});
|
||||
return clip.at(2, 0) / clip.at(3, 0);
|
||||
};
|
||||
@@ -612,7 +624,8 @@ TEST(NDCDepthRangeTests, Unity_ZeroToOne_ZRange)
|
||||
// Unity is right-handed, row-major
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
|
||||
auto proj_z = [&](float z) {
|
||||
auto proj_z = [&](float z)
|
||||
{
|
||||
auto clip = proj * mat_column_from_vector<float>({0, 0, z});
|
||||
return clip.at(2, 0) / clip.at(3, 0);
|
||||
};
|
||||
@@ -650,7 +663,8 @@ TEST(NDCDepthRangeTests, CryEngine_ZeroToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, Source_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::source_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
EXPECT_NEAR(project_z_lh(proj, 0.1f), -1.0f, 1e-3f);
|
||||
EXPECT_NEAR(project_z_lh(proj, 1000.f), 1.0f, 1e-3f);
|
||||
@@ -659,7 +673,8 @@ TEST(NDCDepthRangeTests, Source_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, IW_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::iw_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
EXPECT_NEAR(project_z_lh(proj, 0.1f), -1.0f, 1e-3f);
|
||||
EXPECT_NEAR(project_z_lh(proj, 1000.f), 1.0f, 1e-3f);
|
||||
@@ -668,7 +683,8 @@ TEST(NDCDepthRangeTests, IW_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, Frostbite_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::frostbite_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
EXPECT_NEAR(project_z_lh(proj, 0.1f), -1.0f, 1e-3f);
|
||||
EXPECT_NEAR(project_z_lh(proj, 1000.f), 1.0f, 1e-3f);
|
||||
@@ -677,7 +693,8 @@ TEST(NDCDepthRangeTests, Frostbite_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, Unreal_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::unreal_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
EXPECT_NEAR(project_z_lh(proj, 0.1f), -1.0f, 1e-3f);
|
||||
EXPECT_NEAR(project_z_lh(proj, 1000.f), 1.0f, 1e-3f);
|
||||
@@ -686,7 +703,8 @@ TEST(NDCDepthRangeTests, Unreal_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, CryEngine_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::cry_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
EXPECT_NEAR(project_z_lh(proj, 0.1f), -1.0f, 1e-3f);
|
||||
EXPECT_NEAR(project_z_lh(proj, 1000.f), 1.0f, 1e-3f);
|
||||
@@ -695,9 +713,11 @@ TEST(NDCDepthRangeTests, CryEngine_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, OpenGL_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::opengl_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
auto proj_z = [&](float z) {
|
||||
auto proj_z = [&](float z)
|
||||
{
|
||||
auto clip = proj * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>({0, 0, z});
|
||||
return clip.at(2, 0) / clip.at(3, 0);
|
||||
};
|
||||
@@ -709,9 +729,11 @@ TEST(NDCDepthRangeTests, OpenGL_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, Unity_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::unity_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
auto proj_z = [&](float z) {
|
||||
auto proj_z = [&](float z)
|
||||
{
|
||||
auto clip = proj * mat_column_from_vector<float>({0, 0, z});
|
||||
return clip.at(2, 0) / clip.at(3, 0);
|
||||
};
|
||||
|
||||
@@ -19,13 +19,11 @@ namespace
|
||||
|
||||
constexpr float k_eps = 1e-5f;
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
constexpr bool close_to(const float actual, const float expected, const float epsilon)
|
||||
{
|
||||
const float diff = actual - expected;
|
||||
return (diff < 0.0f ? -diff : diff) <= epsilon;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -199,10 +197,13 @@ TEST(UnitTestAngle, BinaryMinus_ReturnsWrappedDiff)
|
||||
EXPECT_FLOAT_EQ(c.as_degrees(), 340.0f);
|
||||
}
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(close_to(Pitch::from_degrees(0.0f).sin(), 0.0f, k_eps), "Sin should be constexpr with gcem");
|
||||
static_assert(close_to(Pitch::from_degrees(0.0f).cos(), 1.0f, k_eps), "Cos should be constexpr with gcem");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).tan(), 1.0f, 1e-4f), "Tan should be constexpr with gcem");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).cot(), 1.0f, 1e-4f), "Cot should be constexpr with gcem");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).atan(), 0.66577375f, 1e-6f), "Atan should be constexpr with gcem");
|
||||
#endif
|
||||
static_assert(close_to(Pitch::from_degrees(0.0f).sin(), 0.0f, k_eps),
|
||||
"Sin should be constexpr with embedded constexpr math");
|
||||
static_assert(close_to(Pitch::from_degrees(0.0f).cos(), 1.0f, k_eps),
|
||||
"Cos should be constexpr with embedded constexpr math");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).tan(), 1.0f, 1e-4f),
|
||||
"Tan should be constexpr with embedded constexpr math");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).cot(), 1.0f, 1e-4f),
|
||||
"Cot should be constexpr with embedded constexpr math");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).atan(), 0.66577375f, 1e-6f),
|
||||
"Atan should be constexpr with embedded constexpr math");
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
using namespace omath;
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
namespace
|
||||
{
|
||||
using Pitch = Angle<float, static_cast<float>(-90), static_cast<float>(90), AngleFlags::Clamped>;
|
||||
@@ -18,7 +17,6 @@ namespace
|
||||
return (diff < 0.0f ? -diff : diff) <= epsilon;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
class UnitTestMat : public ::testing::Test
|
||||
{
|
||||
@@ -177,7 +175,6 @@ TEST_F(UnitTestMat, StaticMethod_ToScreenMat)
|
||||
EXPECT_FLOAT_EQ(screen_mat.at(3, 3), 1.0f);
|
||||
}
|
||||
|
||||
|
||||
// Test exception handling in At() method
|
||||
TEST_F(UnitTestMat, Method_At_OutOfRange)
|
||||
{
|
||||
@@ -225,7 +222,7 @@ TEST(UnitTestMatStandalone, Transpose_NonSquare)
|
||||
TEST(UnitTestMatStandalone, Enverse)
|
||||
{
|
||||
constexpr Mat<2, 2> m{{1.0f, 3.0f}, {2.0f, 5.0f}};
|
||||
constexpr Mat<2,2> mv{{-5.0f, 3.0f}, {2.0f, -1.0f}};
|
||||
constexpr Mat<2, 2> mv{{-5.0f, 3.0f}, {2.0f, -1.0f}};
|
||||
|
||||
EXPECT_EQ(mv, m.inverted());
|
||||
}
|
||||
@@ -248,9 +245,8 @@ TEST(UnitTestMatStandalone, Equanity)
|
||||
}
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveLeftHanded)
|
||||
{
|
||||
const auto perspective_proj = mat_perspective_left_handed_vertical_fov(90.f, 16.f/9.f, 0.1f, 1000.f);
|
||||
auto projected = perspective_proj
|
||||
* mat_column_from_vector<float>({0, 0, 0.1001});
|
||||
const auto perspective_proj = mat_perspective_left_handed_vertical_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
auto projected = perspective_proj * mat_column_from_vector<float>({0, 0, 0.1001});
|
||||
|
||||
projected /= projected.at(3, 0);
|
||||
|
||||
@@ -259,8 +255,9 @@ TEST(UnitTestMatStandalone, MatPerspectiveLeftHanded)
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedZeroToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj =
|
||||
mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
// Near plane point should map to z ~ 0
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, 0.1f});
|
||||
@@ -281,8 +278,9 @@ TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedZeroToOne)
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedZeroToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj =
|
||||
mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
// Near plane point (negative z for right-handed) should map to z ~ 0
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, -0.1f});
|
||||
@@ -306,7 +304,8 @@ TEST(UnitTestMatStandalone, MatPerspectiveNegativeOneToOneRange)
|
||||
// Verify existing [-1, 1] behavior with explicit template arg matches default
|
||||
const auto proj_default = mat_perspective_left_handed_vertical_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj_explicit = mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
EXPECT_EQ(proj_default, proj_explicit);
|
||||
|
||||
@@ -324,7 +323,8 @@ TEST(UnitTestMatStandalone, MatPerspectiveNegativeOneToOneRange)
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedNegOneToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f,
|
||||
0.1f, 1000.f);
|
||||
|
||||
// Near plane (negative z for RH) should map to z ~ -1
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, -0.1f});
|
||||
@@ -340,14 +340,15 @@ TEST(UnitTestMatStandalone, MatPerspectiveRightHandedNegOneToOne)
|
||||
auto mid_pt = proj * mat_column_from_vector<float>({0, 0, -500.f});
|
||||
mid_pt /= mid_pt.at(3, 0);
|
||||
EXPECT_GT(mid_pt.at(2, 0), -1.0f);
|
||||
EXPECT_LT(mid_pt.at(2, 0), 1.0f);
|
||||
EXPECT_LT(mid_pt.at(2, 0), 1.0f);
|
||||
}
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedHorizontalFovZeroToOne)
|
||||
{
|
||||
// hfov=90 deg, aspect=16/9 => tan(hfov/2)=1, so x_axis=1 and y_axis=aspect
|
||||
const auto proj = mat_perspective_left_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::ZERO_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj =
|
||||
mat_perspective_left_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
// Near plane should map to z ~ 0
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, 0.1f});
|
||||
@@ -368,7 +369,8 @@ TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedHorizontalFovZeroToOne)
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedHorizontalFovNegOneToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_left_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f,
|
||||
0.1f, 1000.f);
|
||||
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, 0.1f});
|
||||
near_pt /= near_pt.at(3, 0);
|
||||
@@ -385,8 +387,9 @@ TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedHorizontalFovNegOneToOne)
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovZeroToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_right_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::ZERO_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj =
|
||||
mat_perspective_right_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, -0.1f});
|
||||
near_pt /= near_pt.at(3, 0);
|
||||
@@ -404,7 +407,8 @@ TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovZeroToOne)
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovNegOneToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_right_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f,
|
||||
0.1f, 1000.f);
|
||||
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, -0.1f});
|
||||
near_pt /= near_pt.at(3, 0);
|
||||
@@ -422,7 +426,7 @@ TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovNegOneToOne)
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveHorizontalVsVerticalFovEquivalence)
|
||||
{
|
||||
constexpr float hfov_deg = 90.f;
|
||||
constexpr float aspect = 16.f / 9.f;
|
||||
constexpr float aspect = 16.f / 9.f;
|
||||
const float vfov_deg = angles::horizontal_fov_to_vertical(hfov_deg, aspect);
|
||||
|
||||
const auto proj_h = mat_perspective_left_handed_horizontal_fov(hfov_deg, aspect, 0.1f, 1000.f);
|
||||
@@ -440,11 +444,11 @@ TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedVerticalFovHandedness)
|
||||
{
|
||||
const auto proj = mat_perspective_left_handed_vertical_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
|
||||
EXPECT_GT(in_front.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
}
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedVerticalFovHandedness)
|
||||
@@ -452,21 +456,21 @@ TEST(UnitTestMatStandalone, MatPerspectiveRightHandedVerticalFovHandedness)
|
||||
const auto proj = mat_perspective_right_handed_vertical_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
|
||||
EXPECT_GT(in_front.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
}
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedHorizontalFovHandedness)
|
||||
{
|
||||
const auto proj = mat_perspective_left_handed_horizontal_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
|
||||
EXPECT_GT(in_front.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
}
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovHandedness)
|
||||
@@ -474,10 +478,10 @@ TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovHandedness)
|
||||
const auto proj = mat_perspective_right_handed_horizontal_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
|
||||
EXPECT_GT(in_front.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
}
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveZeroToOneEquanity)
|
||||
@@ -486,10 +490,12 @@ TEST(UnitTestMatStandalone, MatPerspectiveZeroToOneEquanity)
|
||||
constexpr omath::Vector3<float> left_handed = {0, 2, 10};
|
||||
constexpr omath::Vector3<float> right_handed = {0, 2, -10};
|
||||
|
||||
const auto proj_lh = mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj_rh = mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj_lh =
|
||||
mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj_rh =
|
||||
mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
auto ndc_lh = proj_lh * mat_column_from_vector(left_handed);
|
||||
auto ndc_rh = proj_rh * mat_column_from_vector(right_handed);
|
||||
@@ -532,20 +538,20 @@ TEST(UnitTestMatStandalone, MatOrthoNegativeOneToOneDefault)
|
||||
{
|
||||
// Verify explicit [-1, 1] matches default
|
||||
const auto ortho_default = mat_ortho_left_handed(-1.f, 1.f, -1.f, 1.f, 0.1f, 100.f);
|
||||
const auto ortho_explicit = mat_ortho_left_handed<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(-1.f, 1.f, -1.f, 1.f, 0.1f, 100.f);
|
||||
const auto ortho_explicit =
|
||||
mat_ortho_left_handed<float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(-1.f, 1.f, -1.f,
|
||||
1.f, 0.1f, 100.f);
|
||||
|
||||
EXPECT_EQ(ortho_default, ortho_explicit);
|
||||
}
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
constexpr auto scale = mat_extract_scale(mat_scale(Vector3{2.0f, 3.0f, 4.0f}));
|
||||
return close_to(scale.x, 2.0f, 1e-5f) && close_to(scale.y, 3.0f, 1e-5f) && close_to(scale.z, 4.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat scale extraction should be constexpr with gcem");
|
||||
"Mat scale extraction should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -555,7 +561,7 @@ static_assert(
|
||||
&& close_to(rotation.at(1, 0), 1.0f, 1e-5f) && close_to(rotation.at(1, 1), 0.0f, 1e-5f)
|
||||
&& close_to(rotation.at(2, 2), 1.0f, 1e-5f) && close_to(rotation.at(3, 3), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat rotation should be constexpr with gcem");
|
||||
"Mat rotation should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -567,7 +573,7 @@ static_assert(
|
||||
&& close_to(projection.at(2, 2), 1.1f, 1e-5f) && close_to(projection.at(2, 3), -1.1f, 1e-5f)
|
||||
&& close_to(projection.at(3, 2), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat vertical-FOV perspective should be constexpr with gcem");
|
||||
"Mat vertical-FOV perspective should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -579,5 +585,4 @@ static_assert(
|
||||
&& close_to(projection.at(2, 2), -1.1f, 1e-5f) && close_to(projection.at(2, 3), -1.1f, 1e-5f)
|
||||
&& close_to(projection.at(3, 2), -1.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat horizontal-FOV perspective should be constexpr with gcem");
|
||||
#endif
|
||||
"Mat horizontal-FOV perspective should be constexpr with embedded constexpr math");
|
||||
|
||||
@@ -60,7 +60,6 @@ static void verify_random_look_at_targets_project_to_screen_center(const omath::
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
constexpr bool source_camera_constexpr_projection_round_trip()
|
||||
{
|
||||
constexpr auto fov = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f);
|
||||
@@ -74,23 +73,21 @@ constexpr bool source_camera_constexpr_projection_round_trip()
|
||||
return projected.has_value() && result.has_value() && result2.has_value()
|
||||
&& static_cast<omath::Vector2<float>>(projected.value())
|
||||
== static_cast<omath::Vector2<float>>(result2.value())
|
||||
&& omath::internal::abs(projected->x - 960.f) < 0.001f
|
||||
&& omath::internal::abs(projected->y - 504.f) < 0.001f
|
||||
&& omath::internal::abs(projected->x - 960.f) < 0.001f && omath::internal::abs(projected->y - 504.f) < 0.001f
|
||||
&& omath::internal::abs(projected->z - 1.f) < 0.001f;
|
||||
}
|
||||
|
||||
static_assert(source_camera_constexpr_projection_round_trip());
|
||||
#endif
|
||||
|
||||
TEST(UnitTestProjection, Projection)
|
||||
{
|
||||
OMATH_CONSTEXPR auto fov = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f);
|
||||
OMATH_CONSTEXPR auto cam = omath::source_engine::Camera(
|
||||
{0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
constexpr auto fov = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f);
|
||||
constexpr auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f},
|
||||
fov, 0.01f, 1000.f);
|
||||
|
||||
OMATH_CONSTEXPR auto projected = cam.world_to_screen({1000.f, 0, 50.f});
|
||||
OMATH_CONSTEXPR auto result = cam.screen_to_world(projected.value());
|
||||
OMATH_CONSTEXPR auto result2 = cam.world_to_screen(result.value());
|
||||
constexpr auto projected = cam.world_to_screen({1000.f, 0, 50.f});
|
||||
constexpr auto result = cam.screen_to_world(projected.value());
|
||||
constexpr auto result2 = cam.world_to_screen(result.value());
|
||||
|
||||
EXPECT_EQ(static_cast<omath::Vector2<float>>(projected.value()),
|
||||
static_cast<omath::Vector2<float>>(result2.value()));
|
||||
@@ -587,11 +584,9 @@ TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_LookingForward)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto result = omath::source_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -604,11 +599,9 @@ TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_PositivePitchAndYaw)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto result = omath::source_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -621,11 +614,9 @@ TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_NegativePitchAndYaw)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(-45.f),
|
||||
omath::source_engine::YawAngle::from_degrees(-90.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(-45.f),
|
||||
omath::source_engine::YawAngle::from_degrees(-90.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto result = omath::source_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -640,11 +631,9 @@ TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_OffOriginCameraIgnored)
|
||||
// so the same angles should be recovered regardless of position.
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(20.f),
|
||||
omath::source_engine::YawAngle::from_degrees(60.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(20.f),
|
||||
omath::source_engine::YawAngle::from_degrees(60.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({100.f, 200.f, -50.f}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto result = omath::source_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -657,11 +646,9 @@ TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_RollAlwaysZero)
|
||||
{
|
||||
// Roll cannot be encoded in the forward vector, so it is always 0 in the result.
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(10.f),
|
||||
omath::source_engine::YawAngle::from_degrees(30.f),
|
||||
omath::source_engine::RollAngle::from_degrees(15.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(10.f),
|
||||
omath::source_engine::YawAngle::from_degrees(30.f),
|
||||
omath::source_engine::RollAngle::from_degrees(15.f)};
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto result = omath::source_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -686,11 +673,9 @@ TEST(UnitTestProjection, CalcOriginFromViewMatrix_ArbitraryPosition)
|
||||
{
|
||||
constexpr float k_eps = 1e-3f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({100.f, 200.f, -50.f}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto origin = omath::source_engine::Camera::calc_origin_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -705,11 +690,9 @@ TEST(UnitTestProjection, CalcOriginFromViewMatrix_WithRotation)
|
||||
// Origin recovery must work even when the camera is rotated.
|
||||
constexpr float k_eps = 1e-3f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({300.f, -100.f, 75.f}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto origin = omath::source_engine::Camera::calc_origin_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -726,16 +709,12 @@ TEST(UnitTestProjection, CalcOriginFromViewMatrix_IndependentOfAngles)
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
constexpr omath::Vector3<float> expected_origin{50.f, 50.f, 50.f};
|
||||
|
||||
const omath::source_engine::ViewAngles angles_a{
|
||||
omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles_b{
|
||||
omath::source_engine::PitchAngle::from_degrees(-60.f),
|
||||
omath::source_engine::YawAngle::from_degrees(135.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles_a{omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const omath::source_engine::ViewAngles angles_b{omath::source_engine::PitchAngle::from_degrees(-60.f),
|
||||
omath::source_engine::YawAngle::from_degrees(135.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
|
||||
const auto cam_a = omath::source_engine::Camera(expected_origin, angles_a, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
const auto cam_b = omath::source_engine::Camera(expected_origin, angles_b, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
@@ -758,11 +737,9 @@ TEST(UnitTestProjection, Unity_CalcViewAnglesFromViewMatrix_LookingForward)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const omath::unity_engine::ViewAngles angles{
|
||||
omath::unity_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(0.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::unity_engine::ViewAngles angles{omath::unity_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(0.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, angles, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
const auto result = omath::unity_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -775,11 +752,9 @@ TEST(UnitTestProjection, Unity_CalcViewAnglesFromViewMatrix_PositivePitchAndYaw)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const omath::unity_engine::ViewAngles angles{
|
||||
omath::unity_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(45.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::unity_engine::ViewAngles angles{omath::unity_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(45.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, angles, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
const auto result = omath::unity_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -792,11 +767,9 @@ TEST(UnitTestProjection, Unity_CalcViewAnglesFromViewMatrix_NegativePitchAndYaw)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const omath::unity_engine::ViewAngles angles{
|
||||
omath::unity_engine::PitchAngle::from_degrees(-45.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(-90.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::unity_engine::ViewAngles angles{omath::unity_engine::PitchAngle::from_degrees(-45.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(-90.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, angles, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
const auto result = omath::unity_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -822,11 +795,9 @@ TEST(UnitTestProjection, Unity_CalcOriginFromViewMatrix_ArbitraryPosition)
|
||||
{
|
||||
constexpr float k_eps = 1e-3f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const omath::unity_engine::ViewAngles angles{
|
||||
omath::unity_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(0.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::unity_engine::ViewAngles angles{omath::unity_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(0.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::unity_engine::Camera({100.f, 200.f, -50.f}, angles, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
const auto origin = omath::unity_engine::Camera::calc_origin_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -840,11 +811,9 @@ TEST(UnitTestProjection, Unity_CalcOriginFromViewMatrix_WithRotation)
|
||||
{
|
||||
constexpr float k_eps = 1e-3f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const omath::unity_engine::ViewAngles angles{
|
||||
omath::unity_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(45.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::unity_engine::ViewAngles angles{omath::unity_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(45.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::unity_engine::Camera({300.f, -100.f, 75.f}, angles, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
const auto origin = omath::unity_engine::Camera::calc_origin_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -860,21 +829,21 @@ TEST(UnitTestProjection, SourceEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::source_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::source_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::source_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::source_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::source_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::source_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::source_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::source_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::source_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::source_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::source_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::source_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::source_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::source_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::source_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::source_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, UnityEngine_ZeroAngles_BasisVectors)
|
||||
@@ -882,21 +851,21 @@ TEST(UnitTestProjection, UnityEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::unity_engine::Camera({}, {}, {1280.f, 720.f},
|
||||
omath::projection::FieldOfView::from_degrees(60.f), 0.03f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::unity_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::unity_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::unity_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::unity_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::unity_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::unity_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::unity_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::unity_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::unity_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::unity_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::unity_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::unity_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::unity_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::unity_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::unity_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, OpenGLEngine_ZeroAngles_BasisVectors)
|
||||
@@ -904,21 +873,21 @@ TEST(UnitTestProjection, OpenGLEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::opengl_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::opengl_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::opengl_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::opengl_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::opengl_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::opengl_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::opengl_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::opengl_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::opengl_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::opengl_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::opengl_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::opengl_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::opengl_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::opengl_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::opengl_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::opengl_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, UnrealEngine_ZeroAngles_BasisVectors)
|
||||
@@ -926,21 +895,21 @@ TEST(UnitTestProjection, UnrealEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::unreal_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::unreal_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::unreal_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::unreal_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::unreal_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::unreal_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::unreal_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::unreal_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::unreal_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::unreal_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::unreal_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::unreal_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::unreal_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::unreal_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::unreal_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::unreal_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, FrostbiteEngine_ZeroAngles_BasisVectors)
|
||||
@@ -948,21 +917,21 @@ TEST(UnitTestProjection, FrostbiteEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::frostbite_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::frostbite_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::frostbite_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::frostbite_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::frostbite_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::frostbite_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::frostbite_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::frostbite_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::frostbite_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::frostbite_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::frostbite_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::frostbite_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::frostbite_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::frostbite_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::frostbite_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::frostbite_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, CryEngine_ZeroAngles_BasisVectors)
|
||||
@@ -970,21 +939,21 @@ TEST(UnitTestProjection, CryEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::cry_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::cry_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::cry_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::cry_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::cry_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::cry_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::cry_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::cry_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::cry_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::cry_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::cry_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::cry_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::cry_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::cry_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::cry_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::cry_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, IWEngine_ZeroAngles_BasisVectors)
|
||||
@@ -992,21 +961,21 @@ TEST(UnitTestProjection, IWEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::iw_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::iw_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::iw_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::iw_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::iw_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::iw_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::iw_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::iw_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::iw_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::iw_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::iw_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::iw_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::iw_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::iw_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::iw_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::iw_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
// ---- extract_projection_params ----
|
||||
@@ -1142,11 +1111,9 @@ TEST(UnitTestProjection, SetViewAngles_InvalidatesViewMatrix)
|
||||
auto cam = omath::source_engine::Camera({}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto view_before = cam.get_view_matrix();
|
||||
const omath::source_engine::ViewAngles rotated{
|
||||
omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles rotated{omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
cam.set_view_angles(rotated);
|
||||
const auto view_after = cam.get_view_matrix();
|
||||
|
||||
@@ -1164,7 +1131,7 @@ TEST(UnitTestProjection, CalcLookAtAngles_ForwardTarget)
|
||||
const auto angles = cam.calc_look_at_angles({100.f, 0.f, 0.f});
|
||||
|
||||
EXPECT_NEAR(angles.pitch.as_degrees(), 0.f, 1e-4f);
|
||||
EXPECT_NEAR(angles.yaw.as_degrees(), 0.f, 1e-4f);
|
||||
EXPECT_NEAR(angles.yaw.as_degrees(), 0.f, 1e-4f);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, LookAt_ForwardVectorPointsAtTarget)
|
||||
@@ -1237,11 +1204,7 @@ TEST(UnitTestProjection, TriangleInsideFrustumNotCulled)
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
// Small triangle directly in front (Source: +X forward)
|
||||
const omath::Triangle<omath::Vector3<float>> tri{
|
||||
{100.f, 0.f, 1.f},
|
||||
{100.f, 1.f, -1.f},
|
||||
{100.f, -1.f, -1.f}
|
||||
};
|
||||
const omath::Triangle<omath::Vector3<float>> tri{{100.f, 0.f, 1.f}, {100.f, 1.f, -1.f}, {100.f, -1.f, -1.f}};
|
||||
EXPECT_FALSE(cam.is_culled_by_frustum(tri));
|
||||
}
|
||||
|
||||
@@ -1251,11 +1214,7 @@ TEST(UnitTestProjection, TriangleBehindCameraCulled)
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
// Triangle entirely behind the camera (-X)
|
||||
const omath::Triangle<omath::Vector3<float>> tri{
|
||||
{-100.f, 0.f, 1.f},
|
||||
{-100.f, 1.f, -1.f},
|
||||
{-100.f, -1.f, -1.f}
|
||||
};
|
||||
const omath::Triangle<omath::Vector3<float>> tri{{-100.f, 0.f, 1.f}, {-100.f, 1.f, -1.f}, {-100.f, -1.f, -1.f}};
|
||||
EXPECT_TRUE(cam.is_culled_by_frustum(tri));
|
||||
}
|
||||
|
||||
@@ -1265,11 +1224,7 @@ TEST(UnitTestProjection, TriangleBeyondFarPlaneCulled)
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
// Triangle beyond the 1000-unit far plane
|
||||
const omath::Triangle<omath::Vector3<float>> tri{
|
||||
{2000.f, 0.f, 1.f},
|
||||
{2000.f, 1.f, -1.f},
|
||||
{2000.f, -1.f, -1.f}
|
||||
};
|
||||
const omath::Triangle<omath::Vector3<float>> tri{{2000.f, 0.f, 1.f}, {2000.f, 1.f, -1.f}, {2000.f, -1.f, -1.f}};
|
||||
EXPECT_TRUE(cam.is_culled_by_frustum(tri));
|
||||
}
|
||||
|
||||
@@ -1279,11 +1234,7 @@ TEST(UnitTestProjection, TriangleFarToSideCulled)
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
// Triangle far outside the side frustum planes
|
||||
const omath::Triangle<omath::Vector3<float>> tri{
|
||||
{100.f, 5000.f, 0.f},
|
||||
{100.f, 5001.f, 1.f},
|
||||
{100.f, 5001.f, -1.f}
|
||||
};
|
||||
const omath::Triangle<omath::Vector3<float>> tri{{100.f, 5000.f, 0.f}, {100.f, 5001.f, 1.f}, {100.f, 5001.f, -1.f}};
|
||||
EXPECT_TRUE(cam.is_culled_by_frustum(tri));
|
||||
}
|
||||
|
||||
@@ -1293,10 +1244,6 @@ TEST(UnitTestProjection, TriangleStraddlingFrustumNotCulled)
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
// Large triangle with vertices on both sides of the frustum — should not be culled
|
||||
const omath::Triangle<omath::Vector3<float>> tri{
|
||||
{ 100.f, 0.f, 0.f},
|
||||
{ 100.f, 5000.f, 0.f},
|
||||
{ 100.f, 0.f, 5000.f}
|
||||
};
|
||||
const omath::Triangle<omath::Vector3<float>> tri{{100.f, 0.f, 0.f}, {100.f, 5000.f, 0.f}, {100.f, 0.f, 5000.f}};
|
||||
EXPECT_FALSE(cam.is_culled_by_frustum(tri));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
using namespace omath;
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
namespace
|
||||
{
|
||||
constexpr bool close_to(const float actual, const float expected, const float epsilon)
|
||||
@@ -17,7 +16,6 @@ namespace
|
||||
return (diff < 0.0f ? -diff : diff) <= epsilon;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
class UnitTestTriangle : public ::testing::Test
|
||||
{
|
||||
@@ -30,36 +28,21 @@ protected:
|
||||
constexpr void SetUp() override
|
||||
{
|
||||
// Triangle with vertices (0, 0, 0), (1, 0, 0), (0, 1, 0)
|
||||
t1 = Triangle<Vector3<float>>(
|
||||
Vector3(0.0f, 0.0f, 0.0f),
|
||||
Vector3(1.0f, 0.0f, 0.0f),
|
||||
Vector3(0.0f, 1.0f, 0.0f)
|
||||
);
|
||||
t1 = Triangle<Vector3<float>>(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 0.0f, 0.0f), Vector3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
// Triangle with vertices (1, 2, 3), (4, 5, 6), (7, 8, 9)
|
||||
t2 = Triangle<Vector3<float>>(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Vector3(4.0f, 5.0f, 6.0f),
|
||||
Vector3(7.0f, 8.0f, 9.0f)
|
||||
);
|
||||
t2 = Triangle<Vector3<float>>(Vector3(1.0f, 2.0f, 3.0f), Vector3(4.0f, 5.0f, 6.0f), Vector3(7.0f, 8.0f, 9.0f));
|
||||
|
||||
// An isosceles right triangle
|
||||
t3 = Triangle<Vector3<float>>(
|
||||
Vector3(0.0f, 0.0f, 0.0f),
|
||||
Vector3(2.0f, 0.0f, 0.0f),
|
||||
Vector3(0.0f, 2.0f, 0.0f)
|
||||
);
|
||||
t3 = Triangle<Vector3<float>>(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 0.0f, 0.0f), Vector3(0.0f, 2.0f, 0.0f));
|
||||
}
|
||||
};
|
||||
|
||||
// Test constructor and vertices
|
||||
TEST_F(UnitTestTriangle, Constructor)
|
||||
{
|
||||
constexpr Triangle<Vector3<float>> t(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Vector3(4.0f, 5.0f, 6.0f),
|
||||
Vector3(7.0f, 8.0f, 9.0f)
|
||||
);
|
||||
constexpr Triangle<Vector3<float>> t(Vector3(1.0f, 2.0f, 3.0f), Vector3(4.0f, 5.0f, 6.0f),
|
||||
Vector3(7.0f, 8.0f, 9.0f));
|
||||
|
||||
EXPECT_FLOAT_EQ(t.m_vertex1.x, 1.0f);
|
||||
EXPECT_FLOAT_EQ(t.m_vertex1.y, 2.0f);
|
||||
@@ -83,7 +66,6 @@ TEST_F(UnitTestTriangle, CalculateNormal)
|
||||
EXPECT_NEAR(std::fabs(normal_t1.z), 1.0f, 1e-5f);
|
||||
EXPECT_NEAR(normal_t1.length(), 1.0f, 1e-5f);
|
||||
|
||||
|
||||
// For t3, we expect the normal to be along +Z as well
|
||||
const Vector3 normal_t3 = t3.calculate_normal();
|
||||
EXPECT_NEAR(std::fabs(normal_t3.z), 1.0f, 1e-5f);
|
||||
@@ -94,7 +76,10 @@ TEST_F(UnitTestTriangle, SideLengths)
|
||||
{
|
||||
// For t1 side lengths
|
||||
EXPECT_FLOAT_EQ(t1.side_a_length(), std::sqrt(1.0f)); // distance between (0,0,0) and (1,0,0)
|
||||
EXPECT_FLOAT_EQ(t1.side_b_length(), std::sqrt(1.0f + 1.0f)); // distance between (4,5,6) & (7,8,9)... but we are testing t1, so let's be accurate:
|
||||
EXPECT_FLOAT_EQ(
|
||||
t1.side_b_length(),
|
||||
std::sqrt(1.0f
|
||||
+ 1.0f)); // distance between (4,5,6) & (7,8,9)... but we are testing t1, so let's be accurate:
|
||||
// Actually, for t1: vertex2=(1,0,0), vertex3=(0,1,0)
|
||||
// Dist between (0,1,0) and (1,0,0) = sqrt((1-0)^2 + (0-1)^2) = sqrt(1 + 1) = sqrt(2)
|
||||
EXPECT_FLOAT_EQ(t1.side_b_length(), std::sqrt(2.0f));
|
||||
@@ -123,7 +108,7 @@ TEST_F(UnitTestTriangle, SideVectors)
|
||||
|
||||
TEST_F(UnitTestTriangle, IsRectangular)
|
||||
{
|
||||
EXPECT_TRUE(Triangle<Vector3<float>>({2,0,0}, {}, {0,2,0}).is_rectangular());
|
||||
EXPECT_TRUE(Triangle<Vector3<float>>({2, 0, 0}, {}, {0, 2, 0}).is_rectangular());
|
||||
}
|
||||
// Test midpoint
|
||||
TEST_F(UnitTestTriangle, MidPoint)
|
||||
@@ -141,7 +126,6 @@ TEST_F(UnitTestTriangle, MidPoint)
|
||||
EXPECT_FLOAT_EQ(mid2.z, (3.0f + 6.0f + 9.0f) / 3.0f);
|
||||
}
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
@@ -155,5 +139,4 @@ static_assert(
|
||||
&& close_to(mid_point.x, 1.0f, 1e-5f) && close_to(mid_point.y, 4.0f / 3.0f, 1e-5f)
|
||||
&& close_to(mid_point.z, 0.0f, 1e-5f);
|
||||
}(),
|
||||
"Triangle helpers should be constexpr with gcem");
|
||||
#endif
|
||||
"Triangle helpers should be constexpr with embedded constexpr math");
|
||||
|
||||
@@ -463,8 +463,7 @@ static_assert(Vector2(1.0f, 2.0f).dot(Vector2(4.0f, 5.0f)) == 14.0f, "Dot produc
|
||||
static_assert(Vector2(4.0f, 5.0f).distance_to_sqr(Vector2(1.0f, 2.0f)) == 18.0f, "DistToSqr should be 18");
|
||||
static_assert(Vector2(-1.0f, -2.0f).abs() == Vector2(1.0f, 2.0f), "Abs should convert negative values to positive");
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(Vector2(3.0f, 4.0f).length() == 5.0f, "Length should be constexpr with gcem");
|
||||
static_assert(Vector2(0.0f, 0.0f).distance_to(Vector2(3.0f, 4.0f)) == 5.0f, "Distance should be constexpr with gcem");
|
||||
static_assert(Vector2(1.0f, 1.0f) < Vector2(3.0f, 4.0f), "Comparison should be constexpr with gcem");
|
||||
#endif
|
||||
static_assert(Vector2(3.0f, 4.0f).length() == 5.0f, "Length should be constexpr with embedded constexpr math");
|
||||
static_assert(Vector2(0.0f, 0.0f).distance_to(Vector2(3.0f, 4.0f)) == 5.0f,
|
||||
"Distance should be constexpr with embedded constexpr math");
|
||||
static_assert(Vector2(1.0f, 1.0f) < Vector2(3.0f, 4.0f), "Comparison should be constexpr with embedded constexpr math");
|
||||
|
||||
@@ -584,16 +584,15 @@ static_assert(Vector3(4.0f, 5.0f, 6.0f).distance_to_sqr(Vector3(1.0f, 2.0f, 3.0f
|
||||
static_assert(Vector3(-1.0f, -2.0f, -3.0f).abs() == Vector3(1.0f, 2.0f, 3.0f),
|
||||
"Abs should convert negative values to positive");
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(Vector3(1.0f, 2.0f, 2.0f).length() == 3.0f, "Length should be constexpr with gcem");
|
||||
static_assert(Vector3(1.0f, 2.0f, 2.0f).length() == 3.0f, "Length should be constexpr with embedded constexpr math");
|
||||
static_assert(Vector3(0.0f, 0.0f, 0.0f).distance_to(Vector3(1.0f, 2.0f, 2.0f)) == 3.0f,
|
||||
"Distance should be constexpr with gcem");
|
||||
static_assert(Vector3(1.0f, 1.0f, 1.0f) < Vector3(3.0f, 4.0f, 5.0f), "Comparison should be constexpr with gcem");
|
||||
"Distance should be constexpr with embedded constexpr math");
|
||||
static_assert(Vector3(1.0f, 1.0f, 1.0f) < Vector3(3.0f, 4.0f, 5.0f),
|
||||
"Comparison should be constexpr with embedded constexpr math");
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
constexpr auto angle = Vector3(1.0f, 0.0f, 0.0f).angle_between(Vector3(0.0f, 1.0f, 0.0f));
|
||||
return angle.has_value() && angle->as_degrees() > 89.999f && angle->as_degrees() < 90.001f;
|
||||
}(),
|
||||
"Angle between should be constexpr with gcem");
|
||||
#endif
|
||||
"Angle between should be constexpr with embedded constexpr math");
|
||||
|
||||
@@ -82,13 +82,6 @@
|
||||
"lua",
|
||||
"sol2"
|
||||
]
|
||||
},
|
||||
"gcem":
|
||||
{
|
||||
"description": "Improve constexpr compatibility using gcem",
|
||||
"dependencies": [
|
||||
"gcem"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user