Compare commits

...

9 Commits

Author SHA1 Message Date
b06fd00673 Merge pull request #41 from orange-cpp/u/improved-cmake
improved cmake, removed useless cmake files
2025-04-30 21:31:34 +03:00
998c8f3a43 improved cmake, removed useless cmake files 2025-04-30 21:26:25 +03:00
faeef594b9 moved installation stuff to INSTALL.md 2025-04-30 18:15:46 +03:00
40a301186e Merge pull request #40 from orange-cpp/u/orange/inverted-matrix
U/orange/inverted matrix
2025-04-29 20:53:02 +03:00
a41526c494 style fix 2025-04-29 20:52:41 +03:00
a0d1dc4313 added test case 2025-04-29 20:49:59 +03:00
1c5c9360c8 added inverse method 2025-04-29 20:33:39 +03:00
4615769682 added additional methods 2025-04-29 20:10:17 +03:00
4ef674f7b4 fixed infinite recursion in compile time 2025-04-29 20:08:27 +03:00
18 changed files with 135 additions and 113 deletions

View File

@@ -11,15 +11,19 @@ option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF)
option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" OFF)
option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OFF)
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)
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")
if (OMATH_BUILD_AS_SHARED_LIBRARY)
add_library(omath SHARED source/matrix.cpp)
else()
add_library(omath STATIC source/matrix.cpp)
endif()
add_library(omath SHARED ${OMATH_SOURCES} ${OMATH_HEADERS})
else ()
add_library(omath STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
endif ()
message(STATUS "Building on ${CMAKE_HOST_SYSTEM_NAME}")
add_library(omath::omath ALIAS omath)
@@ -28,28 +32,28 @@ if (OMATH_IMGUI_INTEGRATION)
target_compile_definitions(omath PUBLIC OMATH_IMGUI_INTEGRATION)
# IMGUI is being linked as submodule
if(TARGET imgui)
if (TARGET imgui)
target_link_libraries(omath PUBLIC imgui)
install(TARGETS imgui
EXPORT omathTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
else()
else ()
# Assume that IMGUI linked via VCPKG.
find_package(imgui CONFIG REQUIRED)
target_link_libraries(omath PUBLIC imgui::imgui)
endif()
endif ()
endif()
endif ()
if (OMATH_USE_AVX2)
target_compile_definitions(omath PUBLIC OMATH_USE_AVX2)
endif()
endif ()
if (OMATH_SUPRESS_SAFETY_CHECKS)
target_compile_definitions(omath PUBLIC OMATH_SUPRESS_SAFETY_CHECKS)
endif()
endif ()
set_target_properties(omath PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
@@ -61,37 +65,35 @@ if (OMATH_USE_UNITY_BUILD)
set_target_properties(omath PROPERTIES
UNITY_BUILD ON
UNITY_BUILD_BATCH_SIZE 20)
endif()
endif ()
if (OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
set_target_properties(omath PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
endif()
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(omath PRIVATE -mavx2 -mfma)
endif()
endif ()
target_compile_features(omath PUBLIC cxx_std_23)
add_subdirectory(source)
if(OMATH_BUILD_TESTS)
if (OMATH_BUILD_TESTS)
add_subdirectory(extlibs)
add_subdirectory(tests)
endif()
endif ()
if (OMATH_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR)
target_compile_options(omath PRIVATE /W4 /WX)
elseif(OMATH_THREAT_WARNING_AS_ERROR)
elseif (OMATH_THREAT_WARNING_AS_ERROR)
target_compile_options(omath PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()
endif ()
target_include_directories(omath
PUBLIC

54
INSTALL.md Normal file
View File

@@ -0,0 +1,54 @@
# 📥Installation Guide
## <img width="28px" src="https://vcpkg.io/assets/mark/mark.svg" /> Using vcpkg
**Note**: Support vcpkg for package management
1. Install [vcpkg](https://github.com/microsoft/vcpkg)
2. Run the following command to install the orange-math package:
```
vcpkg install orange-math
```
CMakeLists.txt
```cmake
find_package(omath CONFIG REQUIRED)
target_link_libraries(main PRIVATE omath::omath)
```
For detailed commands on installing different versions and more information, please refer to Microsoft's [official instructions](https://learn.microsoft.com/en-us/vcpkg/get_started/overview).
## <img width="28px" src="https://upload.wikimedia.org/wikipedia/commons/e/ef/CMake_logo.svg?" /> Build from source using CMake
1. **Preparation**
Install needed tools: cmake, clang, git, msvc (windows only).
1. **Linux:**
```bash
sudo pacman -Sy cmake ninja clang git
```
2. **MacOS:**
```bash
brew install llvm git cmake ninja
```
3. **Windows:**
Install Visual Studio from [here](https://visualstudio.microsoft.com/downloads/) and Git from [here](https://git-scm.com/downloads).
Use x64 Native Tools shell to execute needed commands down below.
2. **Clone the repository:**
```bash
git clone https://github.com/orange-cpp/omath.git
```
3. **Navigate to the project directory:**
```bash
cd omath
```
4. **Build the project using CMake:**
```bash
cmake --preset windows-release -S .
cmake --build cmake-build/build/windows-release --target omath -j 6
```
Use **\<platform\>-\<build configuration\>** preset to build siutable version for yourself. Like **windows-release** or **linux-release**.
| Platform Name | Build Config |
|---------------|---------------|
| windows | release/debug |
| linux | release/debug |
| darwin | release/debug |

View File

@@ -37,40 +37,9 @@ Oranges's Math Library (omath) is a comprehensive, open-source library aimed at
| Linux | ✅YES |
| Darwin (MacOS) | ✅YES |
## ⏬ Getting Started
### Prerequisites
- C++ Compiler
- CMake (for building the project)
## ⏬ Installation
Please read our [installation guide](https://github.com/orange-cpp/omath/blob/main/INSTALL.md). If this link doesn't work check out INSTALL.md file.
### Installation
### vcpkg
**Note**: Support vcpkg for package management
1. Install vcpkg (https://github.com/microsoft/vcpkg)
2. Run the following command to install the orange-math package:
```
vcpkg install orange-math
```
CMakeLists.txt
```cmake
find_package(omath CONFIG REQUIRED)
target_link_libraries(main PRIVATE omath::omath)
```
For detailed commands on installing different versions and more information, please refer to Microsoft's official instructions (https://learn.microsoft.com/en-us/vcpkg/get_started/overview)
### Build from source
1. Clone the repository:
```
git clone https://github.com/orange-cpp/omath.git
```
2. Navigate to the project directory:
```
cd omath
```
3. Build the project using CMake:
```
cmake --preset windows-release -S .
cmake --build cmake-build/build/windows-release --target omath -j 6
```
Use **\<platform\>-\<build configuration\>** preset to build siutable version for yourself. Like **windows-release** or **linux-release**.
## ❔ Usage
Simple world to screen function
```c++

View File

@@ -253,21 +253,24 @@ namespace omath
if constexpr (Rows == 2)
return At(0, 0) * At(1, 1) - At(0, 1) * At(1, 0);
else
if constexpr (Rows > 2)
{
Type det = 0;
for (size_t i = 0; i < Columns; ++i)
for (size_t column = 0; column < Columns; ++column)
{
const Type cofactor = (i % 2 == 0 ? 1 : -1) * At(0, i) * Minor(0, i).Determinant();
const Type cofactor = At(0, column) * AlgComplement(0, column);
det += cofactor;
}
return det;
}
std::unreachable();
}
[[nodiscard]]
constexpr Mat<Rows - 1, Columns - 1, Type, StoreType> Minor(const size_t row, const size_t column) const
constexpr Mat<Rows - 1, Columns - 1, Type, StoreType> Strip(const size_t row, const size_t column) const
{
static_assert(Rows-1 > 0 && Columns-1 > 0);
Mat<Rows - 1, Columns - 1, Type, StoreType> result;
for (size_t i = 0, m = 0; i < Rows; ++i)
{
@@ -285,6 +288,19 @@ namespace omath
return result;
}
[[nodiscard]]
constexpr Type Minor(const size_t row, const size_t column) const
{
return Strip(row, column).Determinant();
}
[[nodiscard]]
constexpr Type AlgComplement(const size_t row, const size_t column) const
{
const auto minor = Minor(row, column);
return (row + column + 2) % 2 == 0 ? minor: -minor;
}
[[nodiscard]]
constexpr const std::array<Type, Rows * Columns>& RawArray() const
{
@@ -343,6 +359,25 @@ namespace omath
};
}
[[nodiscard]]
constexpr std::optional<Mat> Inverted() const
{
const auto det = Determinant();
if (det == 0)
return std::nullopt;
const auto transposed = Transposed();
Mat result;
for (std::size_t row = 0; row < Rows; row++)
for (std::size_t column = 0; column < Rows; column++)
result.At(row, column) = transposed.AlgComplement(row, column);
result /= det;
return {result};
}
private:
std::array<Type, Rows * Columns> m_data;
};

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE box.cpp)

View File

@@ -1,11 +0,0 @@
target_sources(omath PRIVATE
matrix.cpp
color.cpp
)
add_subdirectory(projectile_prediction)
add_subdirectory(pathfinding)
add_subdirectory(projection)
add_subdirectory(collision)
add_subdirectory(engines)
add_subdirectory(3d_primitives)

View File

@@ -1,3 +0,0 @@
target_sources(omath PRIVATE
line_tracer.cpp
)

View File

@@ -1,4 +0,0 @@
add_subdirectory(source_engine)
add_subdirectory(opengl_engine)
add_subdirectory(iw_engine)
add_subdirectory(unity_engine)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE camera.cpp formulas.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE camera.cpp formulas.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE camera.cpp formulas.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE formulas.cpp camera.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE navigation_mesh.cpp a_star.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE proj_pred_engine_legacy.cpp projectile.cpp target.cpp proj_pred_engine_avx2.cpp proj_pred_engine.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE camera.cpp)

View File

@@ -1,33 +1,13 @@
enable_testing()
project(unit-tests)
project(unit_tests)
include(GoogleTest)
add_executable(unit-tests
general/unit_test_prediction.cpp
general/unit_test_matrix.cpp
general/unit_test_mat.cpp
general/unit_test_a_star.cpp
general/unit_test_projection.cpp
general/unit_test_vector3.cpp
general/unit_test_vector2.cpp
general/unit_test_color.cpp
general/unit_test_vector4.cpp
general/unit_test_line_trace.cpp
general/unit_test_angles.cpp
general/unit_test_view_angles.cpp
general/unit_test_angle.cpp
general/unit_test_triangle.cpp
general/unit_test_box_primitive.cpp
engines/unit_test_open_gl.cpp
engines/unit_test_unity_engine.cpp
engines/unit_test_source_engine.cpp
engines/unit_test_iw_engine.cpp
file(GLOB_RECURSE UNIT_TESTS_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_executable(unit_tests ${UNIT_TESTS_SOURCES})
)
set_target_properties(unit-tests PROPERTIES
set_target_properties(unit_tests PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
UNITY_BUILD ON
@@ -36,6 +16,6 @@ set_target_properties(unit-tests PROPERTIES
CXX_STANDARD_REQUIRED ON)
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath::omath)
target_link_libraries(unit_tests PRIVATE gtest gtest_main omath::omath)
gtest_discover_tests(unit-tests)
gtest_discover_tests(unit_tests)

View File

@@ -5,7 +5,7 @@
#include <omath/engines/unity_engine/camera.hpp>
#include <omath/engines/unity_engine/constants.hpp>
#include <omath/engines/unity_engine/formulas.hpp>
#include <print>
TEST(UnitTestUnityEngine, ForwardVector)
{

View File

@@ -180,10 +180,10 @@ TEST(UnitTestMatStandalone, Determinant_3x3)
}
// Test Minor for 3x3 matrix
TEST(UnitTestMatStandalone, Minor_3x3)
TEST(UnitTestMatStandalone, Strip_3x3)
{
constexpr Mat<3, 3> m{{3, 0, 2}, {2, 0, -2}, {0, 1, 1}};
auto minor = m.Minor(0, 0);
auto minor = m.Strip(0, 0);
EXPECT_EQ(minor.RowCount(), 2);
EXPECT_EQ(minor.ColumnsCount(), 2);
EXPECT_FLOAT_EQ(minor.At(0, 0), 0.0f);
@@ -206,3 +206,11 @@ TEST(UnitTestMatStandalone, Transpose_NonSquare)
EXPECT_FLOAT_EQ(transposed.At(1, 1), 5.0f);
EXPECT_FLOAT_EQ(transposed.At(2, 1), 6.0f);
}
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}};
EXPECT_EQ(mv, m.Inverted());
}