diff --git a/.idea/editor.xml b/.idea/editor.xml
index fde53486..373c50fc 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -201,7 +201,7 @@
-
+
@@ -215,7 +215,7 @@
-
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f2ebbed8..4758a70a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,9 +1,9 @@
-cmake_minimum_required(VERSION 3.26)
+cmake_minimum_required(VERSION 3.31)
project(omath VERSION 3.5.0 LANGUAGES CXX)
include(CMakePackageConfigHelpers)
-
+include(GNUInstallDirs)
option(OMATH_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL})
option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON)
@@ -13,7 +13,7 @@ option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types
option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" OFF)
option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OFF)
option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build to improve general performance" ON)
-option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" ON)
+option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF)
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" OFF)
message(STATUS "[${PROJECT_NAME}]: Building on ${CMAKE_HOST_SYSTEM_NAME}")
@@ -27,16 +27,21 @@ message(STATUS "[${PROJECT_NAME}]: AVX2 feature status ${OMATH_USE_AVX2}")
message(STATUS "[${PROJECT_NAME}]: ImGUI integration feature status ${OMATH_IMGUI_INTEGRATION}")
message(STATUS "[${PROJECT_NAME}]: Legacy features support ${OMATH_ENABLE_LEGACY}")
-file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
-file(GLOB_RECURSE OMATH_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
+file(GLOB_RECURSE OMATH_MODULES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/modules/*.ixx")
if (OMATH_BUILD_AS_SHARED_LIBRARY)
- add_library(${PROJECT_NAME} SHARED ${OMATH_SOURCES} ${OMATH_HEADERS})
+ add_library(${PROJECT_NAME} SHARED)
else ()
- add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
+ add_library(${PROJECT_NAME} STATIC)
endif ()
+target_sources(${PROJECT_NAME}
+ PUBLIC
+ FILE_SET cxx_modules TYPE CXX_MODULES
+ BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules
+ FILES ${OMATH_MODULES}
+)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}")
@@ -132,6 +137,8 @@ install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib COMPONENT ${PROJECT_NAME} # For static libraries
LIBRARY DESTINATION lib COMPONENT ${PROJECT_NAME} # For shared libraries
RUNTIME DESTINATION bin COMPONENT ${PROJECT_NAME} # For executables (on Windows)
+ FILE_SET cxx_modules DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/modules
+ CXX_MODULES_BMI DESTINATION ${CMAKE_INSTALL_LIBDIR}/cxx/bmi
)
# Install headers as part of omath_component
@@ -142,6 +149,7 @@ install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME} COMPONENT ${PROJECT_NAME}
+ CXX_MODULES_DIRECTORY ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/cxx-modules
)
diff --git a/examples/example_proj_mat_builder.cpp b/examples/example_proj_mat_builder.cpp
index 5857e373..172efcea 100644
--- a/examples/example_proj_mat_builder.cpp
+++ b/examples/example_proj_mat_builder.cpp
@@ -5,7 +5,8 @@
#include
#include
-#include
+#include
+import omath.opengl_engine.formulas;
int main()
@@ -36,5 +37,5 @@ int main()
const auto mat =
omath::opengl_engine::calc_perspective_projection_matrix(fov, view_port_width / view_port_height, near, far);
- std::print("{}", mat.to_string());
+ std::print("{}", mat);
};
diff --git a/include/omath/3d_primitives/box.hpp b/include/omath/3d_primitives/box.hpp
deleted file mode 100644
index 3abb9a44..00000000
--- a/include/omath/3d_primitives/box.hpp
+++ /dev/null
@@ -1,16 +0,0 @@
-//
-// Created by Vlad on 4/18/2025.
-//
-
-#pragma once
-#include "omath/linear_algebra/vector3.hpp"
-#include "omath/triangle.hpp"
-#include
-
-namespace omath::primitives
-{
- [[nodiscard]]
- std::array>, 12> create_box(const Vector3& top, const Vector3& bottom,
- const Vector3& dir_forward, const Vector3& dir_right,
- float ratio = 4.f) noexcept;
-}
diff --git a/include/omath/3d_primitives/plane.hpp b/include/omath/3d_primitives/plane.hpp
deleted file mode 100644
index 39c0f2c4..00000000
--- a/include/omath/3d_primitives/plane.hpp
+++ /dev/null
@@ -1,16 +0,0 @@
-//
-// Created by Vlad on 8/28/2025.
-//
-
-#pragma once
-#include "omath/linear_algebra/vector3.hpp"
-#include "omath/triangle.hpp"
-#include
-
-namespace omath::primitives
-{
- [[nodiscard]]
- std::array>, 2> create_plane(const Vector3& vertex_a,
- const Vector3& vertex_b,
- const Vector3& direction, float size) noexcept;
-}
diff --git a/include/omath/angles.hpp b/include/omath/angles.hpp
deleted file mode 100644
index ce07dd83..00000000
--- a/include/omath/angles.hpp
+++ /dev/null
@@ -1,64 +0,0 @@
-//
-// Created by vlad on 11/6/23.
-//
-
-#pragma once
-#include
-#include
-
-namespace omath::angles
-{
- template
- requires std::is_floating_point_v
- [[nodiscard]] constexpr Type radians_to_degrees(const Type& radians) noexcept
- {
- return radians * (static_cast(180) / std::numbers::pi_v);
- }
-
- template
- requires std::is_floating_point_v
- [[nodiscard]] constexpr Type degrees_to_radians(const Type& degrees) noexcept
- {
- return degrees * (std::numbers::pi_v / static_cast(180));
- }
-
- template
- requires std::is_floating_point_v
- [[nodiscard]] 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(2) * std::atan(std::tan(fov_rad / static_cast(2)) / aspect);
-
- return radians_to_degrees(vert_fov);
- }
-
- template
- requires std::is_floating_point_v
- [[nodiscard]] Type vertical_fov_to_horizontal(const Type& vertical_fov, const Type& aspect) noexcept
- {
- const auto fov_as_radians = degrees_to_radians(vertical_fov);
-
- const auto horizontal_fov =
- static_cast(2) * std::atan(std::tan(fov_as_radians / static_cast(2)) * aspect);
-
- return radians_to_degrees(horizontal_fov);
- }
-
- template
- requires std::is_arithmetic_v
- [[nodiscard]] Type wrap_angle(const Type& angle, const Type& min, const Type& max) noexcept
- {
- if (angle <= max && angle >= min)
- return angle;
-
- const Type range = max - min;
-
- Type wrapped_angle = std::fmod(angle - min, range);
-
- if (wrapped_angle < 0)
- wrapped_angle += range;
-
- return wrapped_angle + min;
- }
-} // namespace omath::angles
diff --git a/include/omath/collision/line_tracer.hpp b/include/omath/collision/line_tracer.hpp
deleted file mode 100644
index f2c16275..00000000
--- a/include/omath/collision/line_tracer.hpp
+++ /dev/null
@@ -1,37 +0,0 @@
-//
-// Created by Orange on 11/13/2024.
-//
-#pragma once
-
-#include "omath/linear_algebra/vector3.hpp"
-#include "omath/triangle.hpp"
-
-namespace omath::collision
-{
- class Ray
- {
- public:
- Vector3 start;
- Vector3 end;
- bool infinite_length = false;
-
- [[nodiscard]]
- Vector3 direction_vector() const noexcept;
-
- [[nodiscard]]
- Vector3 direction_vector_normalized() const noexcept;
- };
- class LineTracer
- {
- public:
- LineTracer() = delete;
-
- [[nodiscard]]
- static bool can_trace_line(const Ray& ray, const Triangle>& triangle) noexcept;
-
- // Realization of Möller–Trumbore intersection algorithm
- // https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
- [[nodiscard]]
- static Vector3 get_ray_hit_point(const Ray& ray, const Triangle>& triangle) noexcept;
- };
-} // namespace omath::collision
diff --git a/include/omath/engines/iw_engine/camera.hpp b/include/omath/engines/iw_engine/camera.hpp
deleted file mode 100644
index 2efe29b1..00000000
--- a/include/omath/engines/iw_engine/camera.hpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//
-// Created by Vlad on 3/17/2025.
-//
-
-#pragma once
-#include "omath/engines/iw_engine/constants.hpp"
-#include "omath/projection/camera.hpp"
-#include "traits/camera_trait.hpp"
-
-namespace omath::iw_engine
-{
- using Camera = projection::Camera;
-} // namespace omath::iw_engine
\ No newline at end of file
diff --git a/include/omath/engines/iw_engine/formulas.hpp b/include/omath/engines/iw_engine/formulas.hpp
deleted file mode 100644
index 433987da..00000000
--- a/include/omath/engines/iw_engine/formulas.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Created by Vlad on 3/17/2025.
-//
-
-#pragma once
-#include "omath/engines/iw_engine/constants.hpp"
-
-namespace omath::iw_engine
-{
- [[nodiscard]]
- Vector3 forward_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Vector3 right_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Vector3 up_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
-
- [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
-
- [[nodiscard]]
- Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
-} // namespace omath::iw_engine
diff --git a/include/omath/engines/iw_engine/traits/camera_trait.hpp b/include/omath/engines/iw_engine/traits/camera_trait.hpp
deleted file mode 100644
index 88c21569..00000000
--- a/include/omath/engines/iw_engine/traits/camera_trait.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// Created by Vlad on 8/10/2025.
-//
-
-#pragma once
-#include "omath/engines/iw_engine/constants.hpp"
-#include "omath/projection/camera.hpp"
-
-namespace omath::iw_engine
-{
- class CameraTrait final
- {
- public:
- [[nodiscard]]
- static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept;
-
- [[nodiscard]]
- static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
- [[nodiscard]]
- static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
- float near, float far) noexcept;
- };
-
-} // namespace omath::iw_engine
\ No newline at end of file
diff --git a/include/omath/engines/opengl_engine/camera.hpp b/include/omath/engines/opengl_engine/camera.hpp
deleted file mode 100644
index e69ee340..00000000
--- a/include/omath/engines/opengl_engine/camera.hpp
+++ /dev/null
@@ -1,12 +0,0 @@
-//
-// Created by Orange on 12/23/2024.
-//
-#pragma once
-#include "omath/engines/opengl_engine/constants.hpp"
-#include "omath/projection/camera.hpp"
-#include "traits/camera_trait.hpp"
-
-namespace omath::opengl_engine
-{
- using Camera = projection::Camera;
-} // namespace omath::opengl_engine
\ No newline at end of file
diff --git a/include/omath/engines/opengl_engine/formulas.hpp b/include/omath/engines/opengl_engine/formulas.hpp
deleted file mode 100644
index 31714f56..00000000
--- a/include/omath/engines/opengl_engine/formulas.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Created by Orange on 12/23/2024.
-//
-#pragma once
-#include "omath/engines/opengl_engine/constants.hpp"
-
-
-namespace omath::opengl_engine
-{
- [[nodiscard]]
- Vector3 forward_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Vector3 right_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Vector3 up_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
-
- [[nodiscard]]
- Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
-} // namespace omath::opengl_engine
diff --git a/include/omath/engines/opengl_engine/traits/camera_trait.hpp b/include/omath/engines/opengl_engine/traits/camera_trait.hpp
deleted file mode 100644
index 3fb57c07..00000000
--- a/include/omath/engines/opengl_engine/traits/camera_trait.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// Created by Vlad on 8/10/2025.
-//
-
-#pragma once
-#include "omath/engines/opengl_engine/constants.hpp"
-#include "omath/projection/camera.hpp"
-
-namespace omath::opengl_engine
-{
- class CameraTrait final
- {
- public:
- [[nodiscard]]
- static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept;
-
- [[nodiscard]]
- static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
- [[nodiscard]]
- static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
- float near, float far) noexcept;
- };
-
-} // namespace omath::opengl_engine
\ No newline at end of file
diff --git a/include/omath/engines/source_engine/camera.hpp b/include/omath/engines/source_engine/camera.hpp
deleted file mode 100644
index 6769d40d..00000000
--- a/include/omath/engines/source_engine/camera.hpp
+++ /dev/null
@@ -1,11 +0,0 @@
-//
-// Created by Orange on 12/4/2024.
-//
-#pragma once
-#include "omath/engines/source_engine/constants.hpp"
-#include "omath/projection/camera.hpp"
-#include "traits/camera_trait.hpp"
-namespace omath::source_engine
-{
- using Camera = projection::Camera;
-} // namespace omath::source_engine
\ No newline at end of file
diff --git a/include/omath/engines/source_engine/formulas.hpp b/include/omath/engines/source_engine/formulas.hpp
deleted file mode 100644
index a51a6333..00000000
--- a/include/omath/engines/source_engine/formulas.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//
-// Created by Orange on 12/4/2024.
-//
-#pragma once
-#include "omath/engines/source_engine/constants.hpp"
-
-namespace omath::source_engine
-{
- [[nodiscard]]
- Vector3 forward_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Vector3 right_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Vector3 up_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
-
- [[nodiscard]]
- Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
-} // namespace omath::source_engine
diff --git a/include/omath/engines/source_engine/traits/camera_trait.hpp b/include/omath/engines/source_engine/traits/camera_trait.hpp
deleted file mode 100644
index d027d25e..00000000
--- a/include/omath/engines/source_engine/traits/camera_trait.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// Created by Vlad on 8/10/2025.
-//
-
-#pragma once
-#include "omath/engines/source_engine/constants.hpp"
-#include "omath/projection/camera.hpp"
-
-namespace omath::source_engine
-{
- class CameraTrait final
- {
- public:
- [[nodiscard]]
- static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept;
-
- [[nodiscard]]
- static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
- [[nodiscard]]
- static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
- float near, float far) noexcept;
- };
-
-} // namespace omath::source_engine
\ No newline at end of file
diff --git a/include/omath/engines/unity_engine/camera.hpp b/include/omath/engines/unity_engine/camera.hpp
deleted file mode 100644
index 642290a3..00000000
--- a/include/omath/engines/unity_engine/camera.hpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//
-// Created by Vlad on 3/22/2025.
-//
-
-#pragma once
-#include "omath/engines/unity_engine/constants.hpp"
-#include "omath/projection/camera.hpp"
-#include "traits/camera_trait.hpp"
-
-namespace omath::unity_engine
-{
- using Camera = projection::Camera;
-} // namespace omath::unity_engine
\ No newline at end of file
diff --git a/include/omath/engines/unity_engine/formulas.hpp b/include/omath/engines/unity_engine/formulas.hpp
deleted file mode 100644
index be071367..00000000
--- a/include/omath/engines/unity_engine/formulas.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Created by Vlad on 3/22/2025.
-//
-
-#pragma once
-#include "omath/engines/unity_engine/constants.hpp"
-
-namespace omath::unity_engine
-{
- [[nodiscard]]
- Vector3 forward_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Vector3 right_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Vector3 up_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
-
- [[nodiscard]]
- Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
-} // namespace omath::unity_engine
diff --git a/include/omath/engines/unity_engine/traits/camera_trait.hpp b/include/omath/engines/unity_engine/traits/camera_trait.hpp
deleted file mode 100644
index 2d98b9db..00000000
--- a/include/omath/engines/unity_engine/traits/camera_trait.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// Created by Vlad on 8/10/2025.
-//
-
-#pragma once
-#include "omath/engines/unity_engine/formulas.hpp"
-#include "omath/projection/camera.hpp"
-
-namespace omath::unity_engine
-{
- class CameraTrait final
- {
- public:
- [[nodiscard]]
- static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept;
-
- [[nodiscard]]
- static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
- [[nodiscard]]
- static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
- float near, float far) noexcept;
- };
-
-} // namespace omath::unity_engine
\ No newline at end of file
diff --git a/include/omath/engines/unreal_engine/camera.hpp b/include/omath/engines/unreal_engine/camera.hpp
deleted file mode 100644
index 30d5daf5..00000000
--- a/include/omath/engines/unreal_engine/camera.hpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//
-// Created by Vlad on 3/22/2025.
-//
-
-#pragma once
-#include "omath/engines/unreal_engine/constants.hpp"
-#include "omath/projection/camera.hpp"
-#include "traits/camera_trait.hpp"
-
-namespace omath::unreal_engine
-{
- using Camera = projection::Camera;
-} // namespace omath::unreal_engine
\ No newline at end of file
diff --git a/include/omath/engines/unreal_engine/formulas.hpp b/include/omath/engines/unreal_engine/formulas.hpp
deleted file mode 100644
index 4e601ce8..00000000
--- a/include/omath/engines/unreal_engine/formulas.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Created by Vlad on 3/22/2025.
-//
-
-#pragma once
-#include "omath/engines/unreal_engine/constants.hpp"
-
-namespace omath::unreal_engine
-{
- [[nodiscard]]
- Vector3 forward_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Vector3 right_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Vector3 up_vector(const ViewAngles& angles) noexcept;
-
- [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
-
- [[nodiscard]]
- Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
-
- [[nodiscard]]
- Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
-} // namespace omath::unreal_engine
diff --git a/include/omath/engines/unreal_engine/traits/camera_trait.hpp b/include/omath/engines/unreal_engine/traits/camera_trait.hpp
deleted file mode 100644
index f2de27e4..00000000
--- a/include/omath/engines/unreal_engine/traits/camera_trait.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// Created by Vlad on 8/10/2025.
-//
-
-#pragma once
-#include "omath/engines/unreal_engine/formulas.hpp"
-#include "omath/projection/camera.hpp"
-
-namespace omath::unreal_engine
-{
- class CameraTrait final
- {
- public:
- [[nodiscard]]
- static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept;
-
- [[nodiscard]]
- static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
- [[nodiscard]]
- static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
- float near, float far) noexcept;
- };
-
-} // namespace omath::unreal_engine
\ No newline at end of file
diff --git a/include/omath/linear_algebra/matrix.hpp b/include/omath/linear_algebra/matrix.hpp
deleted file mode 100644
index 32e9a87f..00000000
--- a/include/omath/linear_algebra/matrix.hpp
+++ /dev/null
@@ -1,127 +0,0 @@
-#pragma once
-
-/*
-THIS CODE IS DEPRECATED NEVER EVER USE Matrix CLASS
-AND VERY SLOW USE Mat INSTEAD!!!!!!!!!!!
-⠛⠛⣿⣿⣿⣿⣿⡷⢶⣦⣶⣶⣤⣤⣤⣀⠀⠀⠀
-⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀
-⠀⠀⠀⠉⠉⠉⠙⠻⣿⣿⠿⠿⠛⠛⠛⠻⣿⣿⣇⠀
-⠀⠀⢤⣀⣀⣀⠀⠀⢸⣷⡄⠀⣁⣀⣤⣴⣿⣿⣿⣆
-⠀⠀⠀⠀⠹⠏⠀⠀⠀⣿⣧⠀⠹⣿⣿⣿⣿⣿⡿⣿
-⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠿⠇⢀⣼⣿⣿⠛⢯⡿⡟
-⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠦⠴⢿⢿⣿⡿⠷⠀⣿⠀
-⠀⠀⠀⠀⠀⠀⠀⠙⣷⣶⣶⣤⣤⣤⣤⣤⣶⣦⠃⠀
-⠀⠀⠀⠀⠀⠀⠀⢐⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀
-⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀
-⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠻⢿⣿⣿⣿⣿⠟⠁
-*/
-
-#ifdef OMATH_ENABLE_LEGACY
-#include "omath/vector3.hpp"
-#include
-#include
-#include
-
-namespace omath
-{
-
- class Matrix final
- {
- public:
- Matrix();
- Matrix(size_t rows, size_t columns);
-
- Matrix(const std::initializer_list>& rows);
-
- [[nodiscard]]
- static Matrix to_screen_matrix(float screen_width, float screen_height);
-
- [[nodiscard]]
- static Matrix translation_matrix(const Vector3& diff);
-
- [[nodiscard]]
- static Matrix orientation_matrix(const Vector3& forward, const Vector3& right,
- const Vector3& up);
-
- [[nodiscard]]
- static Matrix projection_matrix(float field_of_view, float aspect_ratio, float near, float far);
-
- Matrix(const Matrix& other);
-
- Matrix(size_t rows, size_t columns, const float* raw_data);
-
- Matrix(Matrix&& other) noexcept;
-
- [[nodiscard]]
- size_t row_count() const noexcept;
-
- [[nodiscard]]
- float& operator[](size_t row, size_t column);
-
- [[nodiscard]]
- size_t columns_count() const noexcept;
-
- [[nodiscard]]
- std::pair size() const noexcept;
-
- [[nodiscard]]
- float& at(size_t row, size_t col);
-
- [[nodiscard]]
- float sum();
-
- void set_data_from_raw(const float* raw_matrix);
-
- [[nodiscard]]
- Matrix transpose() const;
-
- void set(float val);
-
- [[nodiscard]]
- const float& at(size_t row, size_t col) const;
-
- Matrix operator*(const Matrix& other) const;
-
- Matrix& operator*=(const Matrix& other);
-
- Matrix operator*(float f) const;
-
- Matrix& operator*=(float f);
-
- Matrix& operator/=(float f);
-
- void clear();
-
- [[nodiscard]]
- Matrix strip(size_t row, size_t column) const;
-
- [[nodiscard]]
- float minor(size_t i, size_t j) const;
-
- [[nodiscard]]
- float alg_complement(size_t i, size_t j) const;
-
- [[nodiscard]]
- float determinant() const;
-
- [[nodiscard]]
- const float* raw() const;
-
- Matrix& operator=(const Matrix& other);
-
- Matrix& operator=(Matrix&& other) noexcept;
-
- Matrix operator/(float f) const;
-
- [[nodiscard]]
- std::string to_string() const;
-
- ~Matrix();
-
- private:
- size_t m_rows;
- size_t m_columns;
- std::unique_ptr m_data;
- };
-} // namespace omath
-#endif
diff --git a/include/omath/omath.hpp b/include/omath/omath.hpp
deleted file mode 100644
index a867dd17..00000000
--- a/include/omath/omath.hpp
+++ /dev/null
@@ -1,84 +0,0 @@
-//
-// omath.hpp - Main header file that includes all omath library components
-// Created for the omath library
-//
-
-#pragma once
-
-// Basic math utilities
-#include "omath/angles.hpp"
-#include "omath/angle.hpp"
-
-// Vector classes (in dependency order)
-#include "omath/linear_algebra/vector2.hpp"
-#include "omath/linear_algebra/vector4.hpp"
-#include "omath/linear_algebra/vector3.hpp"
-
-// Matrix classes
-#include "linear_algebra/matrix.hpp"
-#include "omath/linear_algebra/mat.hpp"
-
-// Color functionality
-#include "omath/color.hpp"
-
-// Geometric primitives
-#include "omath/triangle.hpp"
-#include "omath/view_angles.hpp"
-
-// 3D primitives
-#include "omath/3d_primitives/box.hpp"
-
-// Collision detection
-#include "omath/collision/line_tracer.hpp"
-
-// Pathfinding algorithms
-#include "omath/pathfinding/a_star.hpp"
-#include "omath/pathfinding/navigation_mesh.hpp"
-
-// Projectile prediction
-#include "omath/projectile_prediction/projectile.hpp"
-#include "omath/projectile_prediction/target.hpp"
-#include "omath/projectile_prediction/proj_pred_engine.hpp"
-#include "omath/projectile_prediction/proj_pred_engine_legacy.hpp"
-#include "omath/projectile_prediction/proj_pred_engine_avx2.hpp"
-
-// Projection functionality
-#include "omath/projection/error_codes.hpp"
-#include "omath/projection/camera.hpp"
-
-// Engine-specific implementations
-
-// IW Engine
-#include "omath/engines/iw_engine/constants.hpp"
-#include "omath/engines/iw_engine/formulas.hpp"
-#include "omath/engines/iw_engine/camera.hpp"
-#include "omath/engines/iw_engine/traits/camera_trait.hpp"
-#include "omath/engines/iw_engine/traits/pred_engine_trait.hpp"
-
-// OpenGL Engine
-#include "omath/engines/opengl_engine/constants.hpp"
-#include "omath/engines/opengl_engine/formulas.hpp"
-#include "omath/engines/opengl_engine/camera.hpp"
-#include "omath/engines/opengl_engine/traits/camera_trait.hpp"
-#include "omath/engines/opengl_engine/traits/pred_engine_trait.hpp"
-
-// Source Engine
-#include "omath/engines/source_engine/constants.hpp"
-#include "omath/engines/source_engine/formulas.hpp"
-#include "omath/engines/source_engine/camera.hpp"
-#include "omath/engines/source_engine/traits/camera_trait.hpp"
-#include "omath/engines/source_engine/traits/pred_engine_trait.hpp"
-
-// Unity Engine
-#include "omath/engines/unity_engine/constants.hpp"
-#include "omath/engines/unity_engine/formulas.hpp"
-#include "omath/engines/unity_engine/camera.hpp"
-#include "omath/engines/unity_engine/traits/camera_trait.hpp"
-#include "omath/engines/unity_engine/traits/pred_engine_trait.hpp"
-
-// Unreal Engine
-#include "omath/engines/unreal_engine/constants.hpp"
-#include "omath/engines/unreal_engine/formulas.hpp"
-#include "omath/engines/unreal_engine/camera.hpp"
-#include "omath/engines/unreal_engine/traits/camera_trait.hpp"
-#include "omath/engines/unreal_engine/traits/pred_engine_trait.hpp"
\ No newline at end of file
diff --git a/include/omath/pathfinding/a_star.hpp b/include/omath/pathfinding/a_star.hpp
deleted file mode 100644
index 218a059c..00000000
--- a/include/omath/pathfinding/a_star.hpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//
-// Created by Vlad on 28.07.2024.
-//
-
-#pragma once
-#include "omath/linear_algebra/vector3.hpp"
-#include "omath/pathfinding/navigation_mesh.hpp"
-#include
-
-namespace omath::pathfinding
-{
- struct PathNode;
- class Astar final
- {
- public:
- [[nodiscard]]
- static std::vector> find_path(const Vector3& start, const Vector3& end,
- const NavigationMesh& nav_mesh) noexcept;
-
- private:
- [[nodiscard]]
- static std::vector>
- reconstruct_final_path(const std::unordered_map, PathNode>& closed_list,
- const Vector3& current) noexcept;
-
- [[nodiscard]]
- static auto get_perfect_node(const std::unordered_map, PathNode>& open_list,
- const Vector3& end_vertex) noexcept;
- };
-} // namespace omath::pathfinding
diff --git a/include/omath/pathfinding/navigation_mesh.hpp b/include/omath/pathfinding/navigation_mesh.hpp
deleted file mode 100644
index 35cc6e6b..00000000
--- a/include/omath/pathfinding/navigation_mesh.hpp
+++ /dev/null
@@ -1,37 +0,0 @@
-//
-// Created by Vlad on 28.07.2024.
-//
-
-#pragma once
-
-#include "omath/linear_algebra/vector3.hpp"
-#include
-#include
-#include
-
-namespace omath::pathfinding
-{
-
- enum Error
- {
- };
-
- class NavigationMesh final
- {
- public:
- [[nodiscard]]
- std::expected, std::string> get_closest_vertex(const Vector3& point) const noexcept;
-
- [[nodiscard]]
- const std::vector>& get_neighbors(const Vector3& vertex) const noexcept;
-
- [[nodiscard]]
- bool empty() const;
-
- [[nodiscard]] std::vector serialize() const noexcept;
-
- void deserialize(const std::vector& raw) noexcept;
-
- std::unordered_map, std::vector>> m_vertex_map;
- };
-} // namespace omath::pathfinding
diff --git a/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp b/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp
deleted file mode 100644
index e4a7dc51..00000000
--- a/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp
+++ /dev/null
@@ -1,28 +0,0 @@
-//
-// Created by Vlad on 2/23/2025.
-//
-#pragma once
-#include "omath/projectile_prediction/proj_pred_engine.hpp"
-
-namespace omath::projectile_prediction
-{
- class ProjPredEngineAvx2 final : public ProjPredEngineInterface
- {
- public:
- [[nodiscard]] std::optional>
- maybe_calculate_aim_point(const Projectile& projectile, const Target& target) const override;
-
- ProjPredEngineAvx2(float gravity_constant, float simulation_time_step, float maximum_simulation_time);
- ~ProjPredEngineAvx2() override = default;
-
- private:
- [[nodiscard]] static std::optional calculate_pitch(const Vector3& proj_origin,
- const Vector3& target_pos,
- float bullet_gravity, float v0, float time) ;
-
- // We use [[maybe_unused]] here since AVX2 is not available for ARM and ARM64 CPU
- [[maybe_unused]] const float m_gravity_constant;
- [[maybe_unused]] const float m_simulation_time_step;
- [[maybe_unused]] const float m_maximum_simulation_time;
- };
-} // namespace omath::projectile_prediction
diff --git a/source/3d_primitives/box.cpp b/modules/3d_primites/box.ixx
similarity index 76%
rename from source/3d_primitives/box.cpp
rename to modules/3d_primites/box.ixx
index 9c251b98..5b840698 100644
--- a/source/3d_primitives/box.cpp
+++ b/modules/3d_primites/box.ixx
@@ -1,13 +1,18 @@
//
-// Created by Vlad on 4/18/2025.
+// Created by Vlad on 9/1/2025.
//
-#include "omath/3d_primitives/box.hpp"
+module;
+#include
-namespace omath::primitives
+export module omath.box;
+export import omath.triangle;
+
+export namespace omath::primitives
{
- std::array>, 12> create_box(const Vector3& top, const Vector3& bottom,
- const Vector3& dir_forward,
- const Vector3& dir_right, const float ratio) noexcept
+ [[nodiscard]]
+ std::array, 12> create_box(const Vector3& top, const Vector3& bottom,
+ const Vector3& dir_forward, const Vector3& dir_right,
+ const float ratio = 4.f) noexcept
{
const auto height = top.distance_to(bottom);
const auto side_size = height / ratio;
@@ -51,4 +56,4 @@ namespace omath::primitives
return poly;
}
-} // namespace omath::primitives
+} // namespace omath::primitives
\ No newline at end of file
diff --git a/modules/3d_primites/plane.ixx b/modules/3d_primites/plane.ixx
new file mode 100644
index 00000000..ac9d6ef1
--- /dev/null
+++ b/modules/3d_primites/plane.ixx
@@ -0,0 +1,23 @@
+//
+// Created by Vlad on 9/1/2025.
+//
+module;
+#include
+
+export module omath.plane;
+export import omath.triangle;
+
+export namespace omath::primitives
+{
+ [[nodiscard]]
+ std::array, 2> create_plane(const Vector3& vertex_a, const Vector3& vertex_b,
+ const Vector3& direction, const float size) noexcept
+ {
+ const auto second_vertex_a = vertex_a + direction * size;
+ return std::array
+ {
+ Triangle{second_vertex_a, vertex_a, vertex_b},
+ Triangle{second_vertex_a, vertex_b + direction * size, vertex_b}
+ };
+ }
+}
diff --git a/include/omath/triangle.hpp b/modules/3d_primites/triangle.ixx
similarity index 77%
rename from include/omath/triangle.hpp
rename to modules/3d_primites/triangle.ixx
index 519c48cb..ff1a6cd3 100644
--- a/include/omath/triangle.hpp
+++ b/modules/3d_primites/triangle.ixx
@@ -1,10 +1,13 @@
//
-// Created by Orange on 11/13/2024.
+// Created by Vlad on 9/1/2025.
//
-#pragma once
-#include "linear_algebra/vector3.hpp"
+module;
+#include
-namespace omath
+export module omath.triangle;
+export import omath.vector3;
+
+export namespace omath
{
/*
v1
@@ -16,7 +19,7 @@ namespace omath
b
*/
- template
+ template>
class Triangle final
{
public:
@@ -26,12 +29,12 @@ namespace omath
{
}
- Vector3 m_vertex1;
- Vector3 m_vertex2;
- Vector3 m_vertex3;
+ Vector m_vertex1;
+ Vector m_vertex2;
+ Vector m_vertex3;
[[nodiscard]]
- constexpr Vector3 calculate_normal() const
+ constexpr Vector calculate_normal() const
{
const auto b = side_b_vector();
const auto a = side_a_vector();
@@ -52,7 +55,7 @@ namespace omath
}
[[nodiscard]]
- constexpr Vector3 side_a_vector() const
+ constexpr Vector side_a_vector() const
{
return m_vertex1 - m_vertex2;
}
@@ -72,12 +75,12 @@ namespace omath
return std::abs(side_a * side_a + side_b * side_b - hypot_value * hypot_value) <= 0.0001f;
}
[[nodiscard]]
- constexpr Vector3 side_b_vector() const
+ constexpr Vector side_b_vector() const
{
return m_vertex3 - m_vertex2;
}
[[nodiscard]]
- constexpr Vector3 mid_point() const
+ constexpr Vector mid_point() const
{
return (m_vertex1 + m_vertex2 + m_vertex3) / 3;
}
diff --git a/modules/collision/line_tracer.ixx b/modules/collision/line_tracer.ixx
new file mode 100644
index 00000000..48d853a4
--- /dev/null
+++ b/modules/collision/line_tracer.ixx
@@ -0,0 +1,90 @@
+//
+// Created by Vlad on 9/1/2025.
+//
+module;
+
+#include
+#include
+
+export module omath.line_tracer;
+export import omath.triangle;
+
+
+export namespace omath::collision
+{
+ class Ray
+ {
+ public:
+ Vector3 start;
+ Vector3 end;
+ bool infinite_length = false;
+
+ [[nodiscard]]
+ Vector3 direction_vector() const noexcept
+ {
+ return end - start;
+ }
+
+ [[nodiscard]]
+ Vector3 direction_vector_normalized() const noexcept
+ {
+ return direction_vector().normalized();
+ }
+ };
+ class LineTracer
+ {
+ public:
+ LineTracer() = delete;
+
+ [[nodiscard]]
+ static bool can_trace_line(const Ray& ray, const Triangle<>& triangle) noexcept
+ {
+ return get_ray_hit_point(ray, triangle) == ray.end;
+ }
+
+ // Realization of Möller–Trumbore intersection algorithm
+ // https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
+ [[nodiscard]]
+ static Vector3 get_ray_hit_point(const Ray& ray, const Triangle<>& triangle) noexcept
+ {
+ constexpr float k_epsilon = std::numeric_limits::epsilon();
+
+ const auto side_a = triangle.side_a_vector();
+ const auto side_b = triangle.side_b_vector();
+
+ const auto ray_dir = ray.direction_vector();
+
+ const auto p = ray_dir.cross(side_b);
+ const auto det = side_a.dot(p);
+
+ if (std::abs(det) < k_epsilon)
+ return ray.end;
+
+ const auto inv_det = 1.0f / det;
+ const auto t = ray.start - triangle.m_vertex2;
+ const auto u = t.dot(p) * inv_det;
+
+ if ((u < 0 && std::abs(u) > k_epsilon) || (u > 1 && std::abs(u - 1) > k_epsilon))
+ return ray.end;
+
+ const auto q = t.cross(side_a);
+ // ReSharper disable once CppTooWideScopeInitStatement
+ const auto v = ray_dir.dot(q) * inv_det;
+
+ if ((v < 0 && std::abs(v) > k_epsilon) || (u + v > 1 && std::abs(u + v - 1) > k_epsilon))
+ return ray.end;
+
+ const auto t_hit = side_b.dot(q) * inv_det;
+
+ if (ray.infinite_length)
+ {
+ if (t_hit <= k_epsilon)
+ return ray.end;
+ }
+ else if (t_hit <= k_epsilon || t_hit > 1.0f - k_epsilon)
+ return ray.end;
+
+ return ray.start + ray_dir * t_hit;
+ }
+ };
+} // namespace omath::collision
diff --git a/modules/game_engines/iw_engine/camera.ixx b/modules/game_engines/iw_engine/camera.ixx
new file mode 100644
index 00000000..2c6ac489
--- /dev/null
+++ b/modules/game_engines/iw_engine/camera.ixx
@@ -0,0 +1,15 @@
+//
+// Created by Vlad on 9/1/2025.
+//
+
+export module omath.iw_engine.camera;
+
+import omath.camera;
+import omath.iw_engine.constants;
+import omath.iw_engine.camera_trait;
+
+
+export namespace omath::iw_engine
+{
+ using Camera = projection::Camera;
+}
\ No newline at end of file
diff --git a/include/omath/engines/iw_engine/constants.hpp b/modules/game_engines/iw_engine/constants.ixx
similarity index 75%
rename from include/omath/engines/iw_engine/constants.hpp
rename to modules/game_engines/iw_engine/constants.ixx
index 63d1177d..a4672584 100644
--- a/include/omath/engines/iw_engine/constants.hpp
+++ b/modules/game_engines/iw_engine/constants.ixx
@@ -1,14 +1,16 @@
//
-// Created by Vlad on 3/17/2025.
+// Created by Vlad on 9/1/2025.
//
-#pragma once
-#include "omath/linear_algebra/mat.hpp"
-#include "omath/linear_algebra/vector3.hpp"
-#include
-#include
+export module omath.iw_engine.constants;
-namespace omath::iw_engine
+import omath.vector3;
+import omath.mat;
+import omath.angle;
+import omath.view_angles;
+
+
+export namespace omath::iw_engine
{
constexpr Vector3 k_abs_up = {0, 0, 1};
constexpr Vector3 k_abs_right = {0, -1, 0};
diff --git a/source/engines/iw_engine/formulas.cpp b/modules/game_engines/iw_engine/formulas.ixx
similarity index 56%
rename from source/engines/iw_engine/formulas.cpp
rename to modules/game_engines/iw_engine/formulas.ixx
index c346d50c..91d7704a 100644
--- a/source/engines/iw_engine/formulas.cpp
+++ b/modules/game_engines/iw_engine/formulas.ixx
@@ -1,53 +1,70 @@
//
-// Created by Vlad on 3/19/2025.
+// Created by Vlad on 9/1/2025.
//
-#include "omath/engines/iw_engine/formulas.hpp"
+module;
-namespace omath::iw_engine
+#include
+
+export module omath.iw_engine.formulas;
+
+import omath.vector3;
+import omath.iw_engine.constants;
+import omath.mat;
+import omath.angle;
+
+export namespace omath::iw_engine
{
+ [[nodiscard]]
+ 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]]
Vector3 forward_vector(const ViewAngles& angles) noexcept
{
- const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
+ {
+ const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
- return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
+ return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
+ }
}
+ [[nodiscard]]
Vector3 right_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
+
+ [[nodiscard]]
Vector3 up_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
- 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);
- }
- Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
+ [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
{
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
}
+ [[nodiscard]]
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
const float far) noexcept
{
// NOTE: Need magic number to fix fov calculation, since IW engine inherit Quake proj matrix calculation
constexpr auto k_multiply_factor = 0.75f;
- const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f) * k_multiply_factor;
+ const float fov_half_tan = std::tan(degrees_to_radians(field_of_view) / 2.f) * k_multiply_factor;
return {
- {1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
- {0, 1.f / (fov_half_tan), 0, 0},
- {0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
- {0, 0, 1, 0},
- };
+ {1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
+ {0, 1.f / (fov_half_tan), 0, 0},
+ {0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
+ {0, 0, 1, 0},
+ };
};
} // namespace omath::iw_engine
diff --git a/modules/game_engines/iw_engine/traits/camera_trait.ixx b/modules/game_engines/iw_engine/traits/camera_trait.ixx
new file mode 100644
index 00000000..02940afc
--- /dev/null
+++ b/modules/game_engines/iw_engine/traits/camera_trait.ixx
@@ -0,0 +1,42 @@
+//
+// Created by Vlad on 9/1/2025.
+//
+module;
+#include
+export module omath.iw_engine.camera_trait;
+
+import omath.iw_engine.constants;
+import omath.vector3;
+import omath.camera;
+import omath.iw_engine.formulas;
+
+export namespace omath::iw_engine
+{
+ class CameraTrait final
+ {
+ public:
+ [[nodiscard]]
+ static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept
+ {
+ const auto distance = cam_origin.distance_to(look_at);
+ const auto delta = cam_origin - look_at;
+
+ return {PitchAngle::from_radians(-std::asin(delta.z / distance)),
+ YawAngle::from_radians(std::atan2(delta.y, delta.x)), RollAngle::from_radians(0.f)};
+ }
+
+ [[nodiscard]]
+ static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
+ {
+ return iw_engine::calc_view_matrix(angles, cam_origin);
+ }
+
+ [[nodiscard]]
+ static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
+ const float near, const float far) noexcept
+ {
+ return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far);
+ }
+ };
+
+} // namespace omath::iw_engine
\ No newline at end of file
diff --git a/include/omath/engines/iw_engine/traits/pred_engine_trait.hpp b/modules/game_engines/iw_engine/traits/pred_engine_trait.ixx
similarity index 83%
rename from include/omath/engines/iw_engine/traits/pred_engine_trait.hpp
rename to modules/game_engines/iw_engine/traits/pred_engine_trait.ixx
index 7961268a..a02b21f5 100644
--- a/include/omath/engines/iw_engine/traits/pred_engine_trait.hpp
+++ b/modules/game_engines/iw_engine/traits/pred_engine_trait.ixx
@@ -1,14 +1,20 @@
//
-// Created by Vlad on 8/6/2025.
+// Created by Vlad on 9/2/2025.
//
-#pragma once
-
-#include "omath/engines/iw_engine/formulas.hpp"
-#include "omath/projectile_prediction/projectile.hpp"
-#include "omath/projectile_prediction/target.hpp"
+module;
#include
+#include
+
+export module omath.iw_engine.pred_engine_trait;
+
+import omath.vector3;
+import omath.iw_engine.formulas;
+import omath.iw_engine.constants;
+import omath.projectile_prediction.projectile;
+import omath.projectile_prediction.target;
+import omath.angle;
-namespace omath::iw_engine
+export namespace omath::iw_engine
{
class PredEngineTrait final
{
@@ -54,7 +60,7 @@ namespace omath::iw_engine
const std::optional projectile_pitch) noexcept
{
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
- const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
+ const auto height = delta2d * std::tan(degrees_to_radians(projectile_pitch.value()));
return {predicted_target_position.x, predicted_target_position.y, projectile.m_origin.z + height};
}
@@ -66,14 +72,14 @@ namespace omath::iw_engine
const auto distance = origin.distance_to(view_to);
const auto delta = view_to - origin;
- return angles::radians_to_degrees(std::asin(delta.z / distance));
+ return radians_to_degrees(std::asin(delta.z / distance));
}
[[nodiscard]]
static float calc_direct_yaw_angle(const Vector3& origin, const Vector3& view_to) noexcept
{
const auto delta = view_to - origin;
- return angles::radians_to_degrees(std::atan2(delta.y, delta.x));
+ return radians_to_degrees(std::atan2(delta.y, delta.x));
};
};
} // namespace omath::iw_engine
\ No newline at end of file
diff --git a/modules/game_engines/opengl_engine/camera.ixx b/modules/game_engines/opengl_engine/camera.ixx
new file mode 100644
index 00000000..ee085b44
--- /dev/null
+++ b/modules/game_engines/opengl_engine/camera.ixx
@@ -0,0 +1,14 @@
+//
+// Created by Vlad on 9/2/2025.
+//
+
+export module omath.opengl_engine.camera;
+
+export import omath.camera;
+import omath.opengl_engine.constants;
+import omath.opengl_engine.camera_trait;
+
+export namespace omath::opengl_engine
+{
+ using Camera = projection::Camera;
+}
\ No newline at end of file
diff --git a/include/omath/engines/opengl_engine/constants.hpp b/modules/game_engines/opengl_engine/constants.ixx
similarity index 75%
rename from include/omath/engines/opengl_engine/constants.hpp
rename to modules/game_engines/opengl_engine/constants.ixx
index 4f5a955a..16c86f29 100644
--- a/include/omath/engines/opengl_engine/constants.hpp
+++ b/modules/game_engines/opengl_engine/constants.ixx
@@ -1,14 +1,15 @@
//
-// Created by Orange on 12/23/2024.
+// Created by Vlad on 9/2/2025.
//
-#pragma once
-#include "omath/linear_algebra/mat.hpp"
-#include "omath/linear_algebra/vector3.hpp"
-#include
-#include
+export module omath.opengl_engine.constants;
-namespace omath::opengl_engine
+import omath.vector3;
+import omath.mat;
+import omath.angle;
+import omath.view_angles;
+
+export namespace omath::opengl_engine
{
constexpr Vector3 k_abs_up = {0, 1, 0};
constexpr Vector3 k_abs_right = {1, 0, 0};
diff --git a/source/engines/opengl_engine/formulas.cpp b/modules/game_engines/opengl_engine/formulas.ixx
similarity index 66%
rename from source/engines/opengl_engine/formulas.cpp
rename to modules/game_engines/opengl_engine/formulas.ixx
index 4a14ab2f..2570d659 100644
--- a/source/engines/opengl_engine/formulas.cpp
+++ b/modules/game_engines/opengl_engine/formulas.ixx
@@ -1,46 +1,62 @@
//
-// Created by Vlad on 3/19/2025.
+// Created by Vlad on 9/2/2025.
//
-#include "omath/engines/opengl_engine/formulas.hpp"
+module;
+#include
+export module omath.opengl_engine.formulas;
-namespace omath::opengl_engine
+import omath.vector3;
+import omath.opengl_engine.constants;
+import omath.mat;
+import omath.angle;
+
+export namespace omath::opengl_engine
{
+ [[nodiscard]]
+ Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
+ {
+ return mat_rotation_axis_x(-angles.pitch)
+ * mat_rotation_axis_y(-angles.yaw)
+ * mat_rotation_axis_z(angles.roll);
+ }
+ [[nodiscard]]
Vector3 forward_vector(const ViewAngles& angles) noexcept
{
- const auto vec
- = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
+ const auto vec =
+ rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
+
+ [[nodiscard]]
Vector3 right_vector(const ViewAngles& angles) noexcept
{
- const auto vec
- = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
+ const auto vec =
+ rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
+
+ [[nodiscard]]
Vector3 up_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
- Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
+
+ [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
{
return mat_camera_view(-forward_vector(angles), right_vector(angles),
up_vector(angles), cam_origin);
}
- Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
- {
- return mat_rotation_axis_x(-angles.pitch)
- * mat_rotation_axis_y(-angles.yaw)
- * mat_rotation_axis_z(angles.roll);
- }
+
+ [[nodiscard]]
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
const float far) noexcept
{
- const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
+ const float fov_half_tan = std::tan(degrees_to_radians(field_of_view) / 2.f);
return {
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
diff --git a/modules/game_engines/opengl_engine/traits/camera_trait.ixx b/modules/game_engines/opengl_engine/traits/camera_trait.ixx
new file mode 100644
index 00000000..4597e703
--- /dev/null
+++ b/modules/game_engines/opengl_engine/traits/camera_trait.ixx
@@ -0,0 +1,43 @@
+//
+// Created by Vlad on 9/2/2025.
+//
+module;
+#include
+
+export module omath.opengl_engine.camera_trait;
+
+import omath.vector3;
+import omath.view_angles;
+import omath.opengl_engine.constants;
+import omath.opengl_engine.formulas;
+import omath.camera;
+
+export namespace omath::opengl_engine
+{
+ class CameraTrait final
+ {
+ public:
+ [[nodiscard]]
+ static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept
+ {
+ const auto distance = cam_origin.distance_to(look_at);
+ const auto delta = cam_origin - look_at;
+
+ return {PitchAngle::from_radians(-std::asin(delta.y / distance)),
+ YawAngle::from_radians(std::atan2(delta.z, delta.x)), RollAngle::from_radians(0.f)};
+ }
+
+ [[nodiscard]]
+ static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
+ {
+ return opengl_engine::calc_view_matrix(angles, cam_origin);
+ }
+ [[nodiscard]]
+ static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
+ float near, float far) noexcept
+ {
+ return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far);
+ }
+ };
+
+} // namespace omath::opengl_engine
\ No newline at end of file
diff --git a/include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp b/modules/game_engines/opengl_engine/traits/pred_engine_trait.ixx
similarity index 84%
rename from include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp
rename to modules/game_engines/opengl_engine/traits/pred_engine_trait.ixx
index 9c014ff8..19969e17 100644
--- a/include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp
+++ b/modules/game_engines/opengl_engine/traits/pred_engine_trait.ixx
@@ -1,11 +1,18 @@
//
-// Created by Vlad on 8/6/2025.
+// Created by Vlad on 9/2/2025.
//
-#pragma once
-#include "omath/engines/opengl_engine/formulas.hpp"
-#include "omath/projectile_prediction/projectile.hpp"
-#include "omath/projectile_prediction/target.hpp"
+module;
#include
+#include
+
+export module omath.opengl_engine.pred_engine_trait;
+
+import omath.opengl_engine.formulas;
+import omath.opengl_engine.constants;
+import omath.vector3;
+import omath.projectile_prediction.projectile;
+import omath.projectile_prediction.target;
+import omath.angle;
namespace omath::opengl_engine
{
@@ -53,7 +60,7 @@ namespace omath::opengl_engine
const std::optional projectile_pitch) noexcept
{
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
- const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
+ const auto height = delta2d * std::tan(degrees_to_radians(projectile_pitch.value()));
return {predicted_target_position.x, predicted_target_position.y + height, projectile.m_origin.z};
}
@@ -65,14 +72,14 @@ namespace omath::opengl_engine
const auto distance = origin.distance_to(view_to);
const auto delta = view_to - origin;
- return angles::radians_to_degrees(std::asin(delta.y / distance));
+ return radians_to_degrees(std::asin(delta.y / distance));
}
[[nodiscard]]
static float calc_direct_yaw_angle(const Vector3& origin, const Vector3& view_to) noexcept
{
const auto delta = view_to - origin;
- return angles::radians_to_degrees(std::atan2(delta.z, delta.x));
+ return radians_to_degrees(std::atan2(delta.z, delta.x));
};
};
-} // namespace omath::opengl_engine
+}
\ No newline at end of file
diff --git a/modules/game_engines/source_engine/camera.ixx b/modules/game_engines/source_engine/camera.ixx
new file mode 100644
index 00000000..83e1a689
--- /dev/null
+++ b/modules/game_engines/source_engine/camera.ixx
@@ -0,0 +1,13 @@
+//
+// Created by Vlad on 9/2/2025.
+//
+
+export module omath.source_engine.camera;
+import omath.camera;
+export import omath.source_engine.constants;
+export import omath.source_engine.camera_trait;
+
+export namespace omath::source_engine
+{
+ using Camera = projection::Camera;
+}
\ No newline at end of file
diff --git a/include/omath/engines/source_engine/constants.hpp b/modules/game_engines/source_engine/constants.ixx
similarity index 71%
rename from include/omath/engines/source_engine/constants.hpp
rename to modules/game_engines/source_engine/constants.ixx
index 33df18ba..89bff3c9 100644
--- a/include/omath/engines/source_engine/constants.hpp
+++ b/modules/game_engines/source_engine/constants.ixx
@@ -1,14 +1,15 @@
//
-// Created by Orange on 12/4/2024.
+// Created by Vlad on 9/2/2025.
//
-#pragma once
-#include "omath/linear_algebra/mat.hpp"
-#include "omath/linear_algebra/vector3.hpp"
-#include
-#include
+export module omath.source_engine.constants;
-namespace omath::source_engine
+import omath.vector3;
+import omath.mat;
+import omath.angle;
+import omath.view_angles;
+
+export namespace omath::source_engine
{
constexpr Vector3 k_abs_up = {0, 0, 1};
constexpr Vector3 k_abs_right = {0, -1, 0};
@@ -22,4 +23,4 @@ namespace omath::source_engine
using RollAngle = Angle;
using ViewAngles = omath::ViewAngles;
-} // namespace omath::source_engine
+}
\ No newline at end of file
diff --git a/source/engines/source_engine/formulas.cpp b/modules/game_engines/source_engine/formulas.ixx
similarity index 66%
rename from source/engines/source_engine/formulas.cpp
rename to modules/game_engines/source_engine/formulas.ixx
index 326507e8..88eda5ac 100644
--- a/source/engines/source_engine/formulas.cpp
+++ b/modules/game_engines/source_engine/formulas.ixx
@@ -1,10 +1,26 @@
//
-// Created by Vlad on 3/19/2025.
+// Created by Vlad on 9/2/2025.
//
-#include
+module;
+#include
-namespace omath::source_engine
+export module omath.source_engine.formulas;
+
+import omath.vector3;
+import omath.source_engine.constants;
+import omath.view_angles;
+import omath.mat;
+import omath.angle;
+
+export namespace omath::source_engine
{
+ [[nodiscard]]
+ 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]]
Vector3 forward_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
@@ -12,17 +28,14 @@ namespace omath::source_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
- 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]]
Vector3 right_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
+ [[nodiscard]]
Vector3 up_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
@@ -30,18 +43,18 @@ namespace omath::source_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
- Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
+ [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
{
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
}
- Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
- const float far) noexcept
+ [[nodiscard]]
+ Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept
{
// NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation
constexpr auto k_multiply_factor = 0.75f;
- const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f) * k_multiply_factor;
+ const float fov_half_tan = std::tan(degrees_to_radians(field_of_view) / 2.f) * k_multiply_factor;
return {
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
@@ -50,4 +63,4 @@ namespace omath::source_engine
{0, 0, 1, 0},
};
}
-} // namespace omath::source_engine
+} // namespace omath::source_engine
\ No newline at end of file
diff --git a/modules/game_engines/source_engine/traits/camera_trait.ixx b/modules/game_engines/source_engine/traits/camera_trait.ixx
new file mode 100644
index 00000000..650157a5
--- /dev/null
+++ b/modules/game_engines/source_engine/traits/camera_trait.ixx
@@ -0,0 +1,40 @@
+//
+// Created by Vlad on 9/2/2025.
+//
+module;
+#include
+
+export module omath.source_engine.camera_trait;
+
+import omath.source_engine.constants;
+import omath.source_engine.formulas;
+import omath.vector3;
+import omath.camera;
+export namespace omath::source_engine
+{
+ class CameraTrait final
+ {
+ public:
+ [[nodiscard]]
+ static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept
+ {
+ const auto distance = cam_origin.distance_to(look_at);
+ const auto delta = cam_origin - look_at;
+
+ return {PitchAngle::from_radians(-std::asin(delta.z / distance)),
+ YawAngle::from_radians(std::atan2(delta.y, delta.x)), RollAngle::from_radians(0.f)};
+ }
+
+ [[nodiscard]]
+ static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
+ {
+ return source_engine::calc_view_matrix(angles, cam_origin);
+ }
+ [[nodiscard]]
+ static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
+ const float near, const float far) noexcept
+ {
+ return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far);
+ }
+ };
+}
\ No newline at end of file
diff --git a/include/omath/engines/source_engine/traits/pred_engine_trait.hpp b/modules/game_engines/source_engine/traits/pred_engine_trait.ixx
similarity index 83%
rename from include/omath/engines/source_engine/traits/pred_engine_trait.hpp
rename to modules/game_engines/source_engine/traits/pred_engine_trait.ixx
index ca9771e1..a37d3381 100644
--- a/include/omath/engines/source_engine/traits/pred_engine_trait.hpp
+++ b/modules/game_engines/source_engine/traits/pred_engine_trait.ixx
@@ -1,14 +1,20 @@
//
-// Created by Vlad on 8/3/2025.
+// Created by Vlad on 9/2/2025.
//
-
-#pragma once
-#include "omath/engines/source_engine/formulas.hpp"
-#include "omath/projectile_prediction/projectile.hpp"
-#include "omath/projectile_prediction/target.hpp"
+module;
+#include
#include
-namespace omath::source_engine
+export module omath.source_engine.pred_engine_trait;
+
+import omath.vector3;
+import omath.angle;
+import omath.source_engine.formulas;
+import omath.source_engine.constants;
+import omath.projectile_prediction.target;
+import omath.projectile_prediction.projectile;
+
+export namespace omath::source_engine
{
class PredEngineTrait final
{
@@ -54,7 +60,7 @@ namespace omath::source_engine
const std::optional projectile_pitch) noexcept
{
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
- const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
+ const auto height = delta2d * std::tan(degrees_to_radians(projectile_pitch.value()));
return {predicted_target_position.x, predicted_target_position.y, projectile.m_origin.z + height};
}
@@ -66,14 +72,14 @@ namespace omath::source_engine
const auto distance = origin.distance_to(view_to);
const auto delta = view_to - origin;
- return angles::radians_to_degrees(std::asin(delta.z / distance));
+ return radians_to_degrees(std::asin(delta.z / distance));
}
[[nodiscard]]
static float calc_direct_yaw_angle(const Vector3& origin, const Vector3& view_to) noexcept
{
const auto delta = view_to - origin;
- return angles::radians_to_degrees(std::atan2(delta.y, delta.x));
+ return radians_to_degrees(std::atan2(delta.y, delta.x));
};
};
} // namespace omath::source_engine
\ No newline at end of file
diff --git a/modules/game_engines/unity_engine/camera.ixx b/modules/game_engines/unity_engine/camera.ixx
new file mode 100644
index 00000000..032fdf13
--- /dev/null
+++ b/modules/game_engines/unity_engine/camera.ixx
@@ -0,0 +1,14 @@
+//
+// Created by Vlad on 9/3/2025.
+//
+
+export module omath.unity_engine.camera;
+import omath.camera;
+import omath.unity_engine.constants;
+import omath.unity_engine.camera_trait;
+
+
+export namespace omath::unity_engine
+{
+ using Camera = projection::Camera;
+}
\ No newline at end of file
diff --git a/include/omath/engines/unity_engine/constants.hpp b/modules/game_engines/unity_engine/constants.ixx
similarity index 72%
rename from include/omath/engines/unity_engine/constants.hpp
rename to modules/game_engines/unity_engine/constants.ixx
index 81151bc6..444653f3 100644
--- a/include/omath/engines/unity_engine/constants.hpp
+++ b/modules/game_engines/unity_engine/constants.ixx
@@ -1,15 +1,16 @@
//
-// Created by Vlad on 3/22/2025.
+// Created by Vlad on 9/3/2025.
//
-#pragma once
+export module omath.unity_engine.constants;
-#include "omath/linear_algebra/mat.hpp"
-#include "omath/linear_algebra/vector3.hpp"
-#include
-#include
+export import omath.vector3;
+export import omath.vector3;
+export import omath.mat;
+export import omath.angle;
+export import omath.view_angles;
-namespace omath::unity_engine
+export namespace omath::unity_engine
{
constexpr Vector3 k_abs_up = {0, 1, 0};
constexpr Vector3 k_abs_right = {1, 0, 0};
diff --git a/source/engines/unity_engine/formulas.cpp b/modules/game_engines/unity_engine/formulas.ixx
similarity index 76%
rename from source/engines/unity_engine/formulas.cpp
rename to modules/game_engines/unity_engine/formulas.ixx
index 4560e277..405e08f2 100644
--- a/source/engines/unity_engine/formulas.cpp
+++ b/modules/game_engines/unity_engine/formulas.ixx
@@ -1,43 +1,57 @@
//
-// Created by Vlad on 3/22/2025.
+// Created by Vlad on 9/3/2025.
//
-#include "omath/engines/unity_engine/formulas.hpp"
+module;
+#include
-namespace omath::unity_engine
+export module omath.unity_engine.formulas;
+export import omath.unity_engine.constants;
+
+export namespace omath::unity_engine
{
+ [[nodiscard]]
+ Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
+ {
+ return mat_rotation_axis_x(angles.pitch)
+ * mat_rotation_axis_y(angles.yaw)
+ * mat_rotation_axis_z(angles.roll);
+ }
+
+ [[nodiscard]]
Vector3 forward_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
+
+ [[nodiscard]]
Vector3 right_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
+
+ [[nodiscard]]
Vector3 up_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
- Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
+
+ [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
{
return mat_camera_view(forward_vector(angles), -right_vector(angles),
up_vector(angles), cam_origin);
}
- Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
- {
- return mat_rotation_axis_x(angles.pitch)
- * mat_rotation_axis_y(angles.yaw)
- * mat_rotation_axis_z(angles.roll);
- }
+
+ [[nodiscard]]
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
const float far) noexcept
{
- const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
+ const float fov_half_tan = std::tan(degrees_to_radians(field_of_view) / 2.f);
return {
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
@@ -46,4 +60,4 @@ namespace omath::unity_engine
{0, 0, -1.f, 0},
};
}
-} // namespace omath::unity_engine
+} // namespace omath::unity_engine
\ No newline at end of file
diff --git a/modules/game_engines/unity_engine/traits/camera_trait.ixx b/modules/game_engines/unity_engine/traits/camera_trait.ixx
new file mode 100644
index 00000000..3d1fd465
--- /dev/null
+++ b/modules/game_engines/unity_engine/traits/camera_trait.ixx
@@ -0,0 +1,42 @@
+//
+// Created by Vlad on 9/3/2025.
+//
+module;
+#include
+
+export module omath.unity_engine.camera_trait;
+import omath.unity_engine.formulas;
+import omath.projectile_prediction.projectile;
+import omath.projectile_prediction.target;
+import omath.camera;
+
+export namespace omath::unity_engine
+{
+ class CameraTrait final
+ {
+ public:
+ [[nodiscard]]
+ static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept
+ {
+ const auto distance = cam_origin.distance_to(look_at);
+ const auto delta = cam_origin - look_at;
+
+ return {PitchAngle::from_radians(-std::asin(delta.y / distance)),
+ YawAngle::from_radians(std::atan2(delta.z, delta.x)), RollAngle::from_radians(0.f)};
+ }
+
+ [[nodiscard]]
+ static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
+ {
+ return unity_engine::calc_view_matrix(angles, cam_origin);
+ }
+
+ [[nodiscard]]
+ static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
+ const float near, const float far) noexcept
+ {
+ return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far);
+ }
+ };
+
+}
\ No newline at end of file
diff --git a/include/omath/engines/unity_engine/traits/pred_engine_trait.hpp b/modules/game_engines/unity_engine/traits/pred_engine_trait.ixx
similarity index 83%
rename from include/omath/engines/unity_engine/traits/pred_engine_trait.hpp
rename to modules/game_engines/unity_engine/traits/pred_engine_trait.ixx
index 5851e4c6..956a72f4 100644
--- a/include/omath/engines/unity_engine/traits/pred_engine_trait.hpp
+++ b/modules/game_engines/unity_engine/traits/pred_engine_trait.ixx
@@ -1,13 +1,16 @@
//
-// Created by Vlad on 8/6/2025.
+// Created by Vlad on 9/3/2025.
//
-#pragma once
-#include "omath/engines/unity_engine/formulas.hpp"
-#include "omath/projectile_prediction/projectile.hpp"
-#include "omath/projectile_prediction/target.hpp"
+module;
+#include
#include
+export module omath.unity_engine.pred_engine_trait;
+import omath.unity_engine.formulas;
+import omath.projectile_prediction.target;
+import omath.projectile_prediction.projectile;
+import omath.angle;
-namespace omath::unity_engine
+export namespace omath::unity_engine
{
class PredEngineTrait final
{
@@ -53,7 +56,7 @@ namespace omath::unity_engine
const std::optional projectile_pitch) noexcept
{
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
- const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
+ const auto height = delta2d * std::tan(degrees_to_radians(projectile_pitch.value()));
return {predicted_target_position.x, predicted_target_position.y + height, projectile.m_origin.z};
}
@@ -65,14 +68,14 @@ namespace omath::unity_engine
const auto distance = origin.distance_to(view_to);
const auto delta = view_to - origin;
- return angles::radians_to_degrees(std::asin(delta.y / distance));
+ return radians_to_degrees(std::asin(delta.y / distance));
}
[[nodiscard]]
static float calc_direct_yaw_angle(const Vector3& origin, const Vector3& view_to) noexcept
{
const auto delta = view_to - origin;
- return angles::radians_to_degrees(std::atan2(delta.z, delta.x));
+ return radians_to_degrees(std::atan2(delta.z, delta.x));
};
};
-} // namespace omath::unity_engine
+} // namespace omath::unity_engine
\ No newline at end of file
diff --git a/modules/game_engines/unreal_engine/camera.ixx b/modules/game_engines/unreal_engine/camera.ixx
new file mode 100644
index 00000000..789853c7
--- /dev/null
+++ b/modules/game_engines/unreal_engine/camera.ixx
@@ -0,0 +1,14 @@
+//
+// Created by Vlad on 9/3/2025.
+//
+
+export module omath.unreal_engine.camera;
+export import omath.camera;
+import omath.unreal_engine.constants;
+import omath.unreal_engine.camera_trait;
+
+
+export namespace omath::unreal_engine
+{
+ using Camera = projection::Camera;
+}
\ No newline at end of file
diff --git a/include/omath/engines/unreal_engine/constants.hpp b/modules/game_engines/unreal_engine/constants.ixx
similarity index 75%
rename from include/omath/engines/unreal_engine/constants.hpp
rename to modules/game_engines/unreal_engine/constants.ixx
index e2e0eb7e..917ab871 100644
--- a/include/omath/engines/unreal_engine/constants.hpp
+++ b/modules/game_engines/unreal_engine/constants.ixx
@@ -1,15 +1,15 @@
//
-// Created by Vlad on 3/22/2025.
+// Created by Vlad on 9/3/2025.
//
-#pragma once
+export module omath.unreal_engine.constants;
-#include "omath/linear_algebra/mat.hpp"
-#include "omath/linear_algebra/vector3.hpp"
-#include
-#include