mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 23:13:26 +00:00
Compare commits
65 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e7380b5eb6 | |||
| f8d6e4b544 | |||
| 893eca296b | |||
| b0bd58ccb2 | |||
| 44a42d39d0 | |||
| a8c7e8eb54 | |||
| cef22919a4 | |||
| f79350e609 | |||
| 1102cad390 | |||
| df4e999c82 | |||
| 3baeb182f0 | |||
| 5539bbad0d | |||
| 4d4dfae8f2 | |||
| 03c514104e | |||
| 792db7a673 | |||
| bfd399e631 | |||
| 7fef690f5e | |||
| 3df7d65ac1 | |||
| e1a1164136 | |||
| 23216279dc | |||
| 9e082f7dfa | |||
| 7750819e83 | |||
| 2ec0e2f93f | |||
| 9170ffb1a9 | |||
| e05f9ef5a9 | |||
| 89bb4aa625 | |||
|
|
9b0845593d | ||
| 617ded2dd4 | |||
| e882a224d2 | |||
| e04f6573c0 | |||
| 791e3b2313 | |||
| 26b56d757c | |||
| fbb77b9925 | |||
| 7b671dbd90 | |||
| 5875930f1a | |||
| d773985822 | |||
| a2de6f8fae | |||
| d71795006d | |||
| 561438d45c | |||
| 874b028e86 | |||
| 68ec42d9ed | |||
| 8aeb4667d7 | |||
| 565464f0cd | |||
| 04b50d4545 | |||
| e01d32fb22 | |||
| a3a023a664 | |||
| 1b5a7ed4fd | |||
|
|
362b818a71 | ||
| 29a96d64bb | |||
| 256365e52e | |||
| e333d81b81 | |||
| d66f60d419 | |||
| 4a4939b604 | |||
| ebe8d1a90e | |||
| 1a3376fe6c | |||
| 20188d7043 | |||
| f59e0d255f | |||
| 071cb15492 | |||
| f8812ed9e7 | |||
| 19d310d35f | |||
| c364879b5f | |||
| 418b7c0e7e | |||
| 69f46abce1 | |||
| de61f7a5d8 | |||
| 07a449b633 |
BIN
.github/images/yt_previews/img.png
vendored
Normal file
BIN
.github/images/yt_previews/img.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
5
.gitmodules
vendored
5
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "extlibs/googletest"]
|
||||
path = extlibs/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
url = https://github.com/google/googletest.git
|
||||
[submodule "extlibs/benchmark"]
|
||||
path = extlibs/benchmark
|
||||
url = https://github.com/google/benchmark.git
|
||||
|
||||
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
@@ -2,6 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/extlibs/benchmark" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/extlibs/googletest" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -6,6 +6,7 @@ include(CMakePackageConfigHelpers)
|
||||
|
||||
|
||||
option(OMATH_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL})
|
||||
option(OMATH_BUILD_BENCHMARK "Build benchmarks" ${PROJECT_IS_TOP_LEVEL})
|
||||
option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON)
|
||||
option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
|
||||
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
|
||||
@@ -16,9 +17,10 @@ option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build
|
||||
option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF)
|
||||
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" OFF)
|
||||
|
||||
message(STATUS "[${PROJECT_NAME}]: Building on ${CMAKE_HOST_SYSTEM_NAME}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Building on ${CMAKE_HOST_SYSTEM_NAME}, compiler ${CMAKE_CXX_COMPILER_ID}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Warnings as errors ${OMATH_THREAT_WARNING_AS_ERROR}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Build unit tests ${OMATH_BUILD_TESTS}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Build benchmark ${OMATH_BUILD_BENCHMARK}")
|
||||
message(STATUS "[${PROJECT_NAME}]: As dynamic library ${OMATH_BUILD_AS_SHARED_LIBRARY}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Static C++ runtime ${OMATH_STATIC_MSVC_RUNTIME_LIBRARY}")
|
||||
message(STATUS "[${PROJECT_NAME}]: CMake unity build ${OMATH_USE_UNITY_BUILD}")
|
||||
@@ -90,16 +92,23 @@ if (OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE -mavx2 -mfma)
|
||||
if (OMATH_USE_AVX2 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC -mavx2 -mavx -mfma)
|
||||
endif ()
|
||||
|
||||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
|
||||
|
||||
if (OMATH_BUILD_TESTS OR OMATH_BUILD_BENCHMARK)
|
||||
add_subdirectory(extlibs)
|
||||
endif ()
|
||||
|
||||
if (OMATH_BUILD_TESTS)
|
||||
add_subdirectory(extlibs)
|
||||
add_subdirectory(tests)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_BUILD_TESTS)
|
||||
endif ()
|
||||
|
||||
if (OMATH_BUILD_BENCHMARK)
|
||||
add_subdirectory(benchmark)
|
||||
endif ()
|
||||
|
||||
if (OMATH_BUILD_EXAMPLES)
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
Thanks to everyone who made this possible, including:
|
||||
|
||||
- Saikari aka luadebug for VCPKG port and awesome new initial logo design.
|
||||
- AmbushedRaccoon for telegram post about omath to boost repository activity.
|
||||
- Billy O'Neal aka BillyONeal for fixing compilation issues due to C math library compatibility.
|
||||
|
||||
And a big hand to everyone else who has contributed over the past!
|
||||
|
||||
|
||||
75
README.md
75
README.md
@@ -12,9 +12,25 @@
|
||||
[](https://discord.gg/eDgdaWbqwZ)
|
||||
[](https://t.me/orangennotes)
|
||||
|
||||
OMath is a 100% independent, constexpr template blazingly fast math library that doesn't have legacy C++ code.
|
||||
|
||||
It provides the latest features, is highly customizable, has all for cheat development, DirectX/OpenGL/Vulkan support, premade support for different game engines, much more constexpr stuff than in other libraries and more...
|
||||
<br>
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
**[<kbd> <br> Install <br> </kbd>][INSTALL]**
|
||||
**[<kbd> <br> Examples <br> </kbd>][EXAMPLES]**
|
||||
**[<kbd> <br> Contribute <br> </kbd>][CONTRIBUTING]**
|
||||
**[<kbd> <br> Donate <br> </kbd>][SPONSOR]**
|
||||
|
||||
---
|
||||
|
||||
<br>
|
||||
|
||||
</div>
|
||||
|
||||
Oranges's Math Library (omath) is a comprehensive, open-source library aimed at providing efficient, reliable, and versatile mathematical functions and algorithms. Developed primarily in C++, this library is designed to cater to a wide range of mathematical operations essential in scientific computing, engineering, and academic research.
|
||||
|
||||
<div align = center>
|
||||
<a href="https://www.star-history.com/#orange-cpp/omath&Date">
|
||||
@@ -36,6 +52,29 @@ Oranges's Math Library (omath) is a comprehensive, open-source library aimed at
|
||||
- **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution
|
||||
- **Ready for meta-programming**: Omath use templates for common types like Vectors, Matrixes etc, to handle all types!
|
||||
|
||||
# Gallery
|
||||
|
||||
<br>
|
||||
|
||||
[](https://youtu.be/lM_NJ1yCunw?si=-Qf5yzDcWbaxAXGQ)
|
||||
|
||||
<br>
|
||||
|
||||
![APEX Preview]
|
||||
|
||||
<br>
|
||||
|
||||
![BO2 Preview]
|
||||
|
||||
<br>
|
||||
|
||||
![CS2 Preview]
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
|
||||
|
||||
## Supported Render Pipelines
|
||||
| ENGINE | SUPPORT |
|
||||
|----------|---------|
|
||||
@@ -53,9 +92,6 @@ Oranges's Math Library (omath) is a comprehensive, open-source library aimed at
|
||||
| Linux | ✅YES |
|
||||
| Darwin (MacOS) | ✅YES |
|
||||
|
||||
## ⏬ 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.
|
||||
|
||||
## ❔ Usage
|
||||
ESP example
|
||||
```c++
|
||||
@@ -77,26 +113,17 @@ for (auto ent: apex_sdk::EntityList::GetAllEntities())
|
||||
// esp rendering...
|
||||
}
|
||||
```
|
||||
## Showcase
|
||||
<details>
|
||||
<summary>OMATH for making cheats (click to open)</summary>
|
||||
|
||||
With `omath/projection` module you can achieve simple ESP hack for powered by Source/Unreal/Unity engine games, like [Apex Legends](https://store.steampowered.com/app/1172470/Apex_Legends/).
|
||||
|
||||

|
||||
Or for InfinityWard Engine based games. Like Call of Duty Black Ops 2!
|
||||

|
||||
Or create simple trigger bot with embeded traceline from omath::collision::LineTrace
|
||||

|
||||
Or even advanced projectile aimbot
|
||||
[Watch Video](https://youtu.be/lM_NJ1yCunw?si=5E87OrQMeypxSJ3E)
|
||||
</details>
|
||||
|
||||
## 🫵🏻 Contributing
|
||||
Contributions to `omath` are welcome! Please read `CONTRIBUTING.md` for details on our code of conduct and the process for submitting pull requests.
|
||||
|
||||
## 📜 License
|
||||
This project is licensed under the ZLIB - see the `LICENSE` file for details.
|
||||
|
||||
## 💘 Acknowledgments
|
||||
- [All contributors](https://github.com/orange-cpp/omath/graphs/contributors)
|
||||
|
||||
<!----------------------------------{ Images }--------------------------------->
|
||||
[APEX Preview]: .github/images/showcase/apex.png
|
||||
[BO2 Preview]: .github/images/showcase/cod_bo2.png
|
||||
[CS2 Preview]: .github/images/showcase/cs2.jpeg
|
||||
|
||||
<!----------------------------------{ Buttons }--------------------------------->
|
||||
[INSTALL]: INSTALL.md
|
||||
[CONTRIBUTING]: CONTRIBUTING.md
|
||||
[EXAMPLES]: examples
|
||||
[SPONSOR]: https://boosty.to/orangecpp/purchase/3568644?ssource=DIRECT&share=subscription_link
|
||||
|
||||
15
benchmark/CMakeLists.txt
Normal file
15
benchmark/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
project(omath_benchmark)
|
||||
|
||||
|
||||
file(GLOB_RECURSE OMATH_BENCHMARK_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
add_executable(${PROJECT_NAME} ${OMATH_BENCHMARK_SOURCES})
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||
CXX_STANDARD 23
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark omath)
|
||||
66
benchmark/benchmark_mat.cpp
Normal file
66
benchmark/benchmark_mat.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// Created by Vlad on 9/17/2025.
|
||||
//
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
#include <omath/omath.hpp>
|
||||
#include <chrono>
|
||||
using namespace omath;
|
||||
|
||||
|
||||
void mat_float_multiplication_col_major(benchmark::State& state)
|
||||
{
|
||||
using MatType = Mat<128, 128, float, MatStoreType::COLUMN_MAJOR>;
|
||||
MatType a;
|
||||
MatType b;
|
||||
a.set(3.f);
|
||||
b.set(7.f);
|
||||
|
||||
|
||||
for (auto _ : state)
|
||||
std::ignore = a * b;
|
||||
}
|
||||
void mat_float_multiplication_row_major(benchmark::State& state)
|
||||
{
|
||||
using MatType = Mat<128, 128, float, MatStoreType::ROW_MAJOR>;
|
||||
MatType a;
|
||||
MatType b;
|
||||
a.set(3.f);
|
||||
b.set(7.f);
|
||||
|
||||
|
||||
for (auto _ : state)
|
||||
std::ignore = a * b;
|
||||
}
|
||||
|
||||
void mat_double_multiplication_row_major(benchmark::State& state)
|
||||
{
|
||||
using MatType = Mat<128, 128, double, MatStoreType::ROW_MAJOR>;
|
||||
MatType a;
|
||||
MatType b;
|
||||
a.set(3.f);
|
||||
b.set(7.f);
|
||||
|
||||
|
||||
for (auto _ : state)
|
||||
std::ignore = a * b;
|
||||
}
|
||||
|
||||
void mat_double_multiplication_col_major(benchmark::State& state)
|
||||
{
|
||||
using MatType = Mat<128, 128, double, MatStoreType::COLUMN_MAJOR>;
|
||||
MatType a;
|
||||
MatType b;
|
||||
a.set(3.f);
|
||||
b.set(7.f);
|
||||
|
||||
|
||||
for (auto _ : state)
|
||||
std::ignore = a * b;
|
||||
}
|
||||
|
||||
BENCHMARK(mat_float_multiplication_col_major)->Iterations(5000);
|
||||
BENCHMARK(mat_float_multiplication_row_major)->Iterations(5000);
|
||||
|
||||
BENCHMARK(mat_double_multiplication_col_major)->Iterations(5000);
|
||||
BENCHMARK(mat_double_multiplication_row_major)->Iterations(5000);
|
||||
3
benchmark/benchmark_projectile_pred.cpp
Normal file
3
benchmark/benchmark_projectile_pred.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by Vlad on 9/18/2025.
|
||||
//
|
||||
5
benchmark/main.cpp
Normal file
5
benchmark/main.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Vlad on 9/17/2025.
|
||||
//
|
||||
#include <benchmark/benchmark.h>
|
||||
BENCHMARK_MAIN();
|
||||
@@ -1 +1,2 @@
|
||||
add_subdirectory(googletest)
|
||||
add_subdirectory(googletest)
|
||||
add_subdirectory(benchmark)
|
||||
1
extlibs/benchmark
Submodule
1
extlibs/benchmark
Submodule
Submodule extlibs/benchmark added at 2948b6a2e6
@@ -5,8 +5,8 @@
|
||||
#pragma once
|
||||
#include "omath/angles.hpp"
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <format>
|
||||
#include <utility>
|
||||
|
||||
namespace omath
|
||||
{
|
||||
@@ -150,17 +150,40 @@ namespace omath
|
||||
}
|
||||
};
|
||||
} // namespace omath
|
||||
template<class Type, Type min, Type max, omath::AngleFlags flags>
|
||||
struct std::formatter<omath::Angle<Type, min, max, flags>> // NOLINT(*-dcl58-cpp)
|
||||
|
||||
template<class T, T MinV, T MaxV, omath::AngleFlags F>
|
||||
struct std::formatter<omath::Angle<T, MinV, MaxV, F>, char> // NOLINT(*-dcl58-cpp)
|
||||
{
|
||||
[[nodiscard]]
|
||||
using AngleT = omath::Angle<T, MinV, MaxV, F>;
|
||||
|
||||
static constexpr auto parse(std::format_parse_context& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
[[nodiscard]]
|
||||
static auto format(const omath::Angle<Type, min, max, flags>& deg, std::format_context& ctx)
|
||||
|
||||
template<class FormatContext>
|
||||
auto format(const AngleT& a, FormatContext& ctx) const
|
||||
{
|
||||
return std::format_to(ctx.out(), "{}deg", deg.as_degrees());
|
||||
static_assert(std::is_same_v<typename FormatContext::char_type, char>);
|
||||
return std::format_to(ctx.out(), "{}deg", a.as_degrees());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// wchar_t formatter
|
||||
template<class T, T MinV, T MaxV, omath::AngleFlags F>
|
||||
struct std::formatter<omath::Angle<T, MinV, MaxV, F>, wchar_t> // NOLINT(*-dcl58-cpp)
|
||||
{
|
||||
using AngleT = omath::Angle<T, MinV, MaxV, F>;
|
||||
|
||||
static constexpr auto parse(std::wformat_parse_context& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<class FormatContext>
|
||||
auto format(const AngleT& a, FormatContext& ctx) const
|
||||
{
|
||||
static_assert(std::is_same_v<typename FormatContext::char_type, wchar_t>);
|
||||
return std::format_to(ctx.out(), L"{}deg", a.as_degrees());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace omath
|
||||
hsv_data.hue = 0.f;
|
||||
|
||||
else if (max == red)
|
||||
hsv_data.hue = 60.f * (std::fmodf(((green - blue) / delta), 6.f));
|
||||
hsv_data.hue = 60.f * (std::fmod(static_cast<float>((green - blue) / delta), 6.f));
|
||||
else if (max == green)
|
||||
hsv_data.hue = 60.f * (((blue - red) / delta) + 2.f);
|
||||
else if (max == blue)
|
||||
|
||||
@@ -11,7 +11,12 @@
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
#ifdef OMATH_USE_AVX2
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
|
||||
#undef near
|
||||
#undef far
|
||||
namespace omath
|
||||
{
|
||||
struct MatSize
|
||||
@@ -155,17 +160,19 @@ namespace omath
|
||||
constexpr Mat<Rows, OtherColumns, Type, StoreType>
|
||||
operator*(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
|
||||
{
|
||||
Mat<Rows, OtherColumns, Type, StoreType> result;
|
||||
|
||||
for (size_t i = 0; i < Rows; ++i)
|
||||
for (size_t j = 0; j < OtherColumns; ++j)
|
||||
{
|
||||
Type sum = 0;
|
||||
for (size_t k = 0; k < Columns; ++k)
|
||||
sum += at(i, k) * other.at(k, j);
|
||||
result.at(i, j) = sum;
|
||||
}
|
||||
return result;
|
||||
#ifdef OMATH_USE_AVX2
|
||||
if constexpr (StoreType == MatStoreType::ROW_MAJOR)
|
||||
return avx_multiply_row_major(other);
|
||||
else if constexpr (StoreType == MatStoreType::COLUMN_MAJOR)
|
||||
return avx_multiply_col_major(other);
|
||||
#else
|
||||
if constexpr (StoreType == MatStoreType::ROW_MAJOR)
|
||||
return cache_friendly_multiply_row_major(other);
|
||||
else if constexpr (StoreType == MatStoreType::COLUMN_MAJOR)
|
||||
return cache_friendly_multiply_col_major(other);
|
||||
#endif
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
constexpr Mat& operator*=(const Type& f) noexcept
|
||||
@@ -367,6 +374,176 @@ namespace omath
|
||||
|
||||
private:
|
||||
std::array<Type, Rows * Columns> m_data;
|
||||
|
||||
template<size_t OtherColumns> [[nodiscard]]
|
||||
constexpr Mat<Rows, OtherColumns, Type, MatStoreType::ROW_MAJOR>
|
||||
cache_friendly_multiply_row_major(const Mat<Columns, OtherColumns, Type, MatStoreType::ROW_MAJOR>& other) const
|
||||
{
|
||||
Mat<Rows, OtherColumns, Type, MatStoreType::ROW_MAJOR> result;
|
||||
for (std::size_t row_index = 0; row_index < Rows; ++row_index)
|
||||
for (std::size_t column_index = 0; column_index < Columns; ++column_index)
|
||||
{
|
||||
const Type& current_number = at(row_index, column_index);
|
||||
for (std::size_t other_column = 0; other_column < OtherColumns; ++other_column)
|
||||
result.at(row_index, other_column) += current_number * other.at(column_index, other_column);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<size_t OtherColumns> [[nodiscard]]
|
||||
constexpr Mat<Rows, OtherColumns, Type, MatStoreType::COLUMN_MAJOR> cache_friendly_multiply_col_major(
|
||||
const Mat<Columns, OtherColumns, Type, MatStoreType::COLUMN_MAJOR>& other) const
|
||||
{
|
||||
Mat<Rows, OtherColumns, Type, MatStoreType::COLUMN_MAJOR> result;
|
||||
for (std::size_t other_column = 0; other_column < OtherColumns; ++other_column)
|
||||
for (std::size_t column_index = 0; column_index < Columns; ++column_index)
|
||||
{
|
||||
const Type& current_number = other.at(column_index, other_column);
|
||||
for (std::size_t row_index = 0; row_index < Rows; ++row_index)
|
||||
result.at(row_index, other_column) += at(row_index, column_index) * current_number;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#ifdef OMATH_USE_AVX2
|
||||
template<size_t OtherColumns> [[nodiscard]]
|
||||
constexpr Mat<Rows, OtherColumns, Type, MatStoreType::COLUMN_MAJOR>
|
||||
avx_multiply_col_major(const Mat<Columns, OtherColumns, Type, MatStoreType::COLUMN_MAJOR>& other) const
|
||||
{
|
||||
Mat<Rows, OtherColumns, Type, MatStoreType::COLUMN_MAJOR> result;
|
||||
|
||||
const Type* this_mat_data = this->raw_array().data();
|
||||
const Type* other_mat_data = other.raw_array().data();
|
||||
Type* result_mat_data = result.raw_array().data();
|
||||
|
||||
if constexpr (std::is_same_v<Type, float>)
|
||||
{
|
||||
// ReSharper disable once CppTooWideScopeInitStatement
|
||||
constexpr std::size_t vector_size = 8;
|
||||
for (std::size_t j = 0; j < OtherColumns; ++j)
|
||||
{
|
||||
auto* c_col = reinterpret_cast<float*>(result_mat_data + j * Rows);
|
||||
for (std::size_t k = 0; k < Columns; ++k)
|
||||
{
|
||||
const float bkj = reinterpret_cast<const float*>(other_mat_data)[k + j * Columns];
|
||||
__m256 bkjv = _mm256_set1_ps(bkj);
|
||||
|
||||
const auto* a_col_k = reinterpret_cast<const float*>(this_mat_data + k * Rows);
|
||||
|
||||
std::size_t i = 0;
|
||||
for (; i + vector_size <= Rows; i += vector_size)
|
||||
{
|
||||
__m256 cvec = _mm256_loadu_ps(c_col + i);
|
||||
__m256 avec = _mm256_loadu_ps(a_col_k + i);
|
||||
cvec = _mm256_fmadd_ps(avec, bkjv, cvec);
|
||||
_mm256_storeu_ps(c_col + i, cvec);
|
||||
}
|
||||
for (; i < Rows; ++i)
|
||||
c_col[i] += a_col_k[i] * bkj;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (std::is_same_v<Type, double>)
|
||||
{ // double
|
||||
// ReSharper disable once CppTooWideScopeInitStatement
|
||||
constexpr std::size_t vector_size = 4;
|
||||
for (std::size_t j = 0; j < OtherColumns; ++j)
|
||||
{
|
||||
auto* c_col = reinterpret_cast<double*>(result_mat_data + j * Rows);
|
||||
for (std::size_t k = 0; k < Columns; ++k)
|
||||
{
|
||||
const double bkj = reinterpret_cast<const double*>(other_mat_data)[k + j * Columns];
|
||||
__m256d bkjv = _mm256_set1_pd(bkj);
|
||||
|
||||
const auto* a_col_k = reinterpret_cast<const double*>(this_mat_data + k * Rows);
|
||||
|
||||
std::size_t i = 0;
|
||||
for (; i + vector_size <= Rows; i += vector_size)
|
||||
{
|
||||
__m256d cvec = _mm256_loadu_pd(c_col + i);
|
||||
__m256d avec = _mm256_loadu_pd(a_col_k + i);
|
||||
cvec = _mm256_fmadd_pd(avec, bkjv, cvec);
|
||||
_mm256_storeu_pd(c_col + i, cvec);
|
||||
}
|
||||
for (; i < Rows; ++i)
|
||||
c_col[i] += a_col_k[i] * bkj;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
std::unreachable();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<size_t OtherColumns> [[nodiscard]]
|
||||
constexpr Mat<Rows, OtherColumns, Type, MatStoreType::ROW_MAJOR>
|
||||
avx_multiply_row_major(const Mat<Columns, OtherColumns, Type, MatStoreType::ROW_MAJOR>& other) const
|
||||
{
|
||||
Mat<Rows, OtherColumns, Type, MatStoreType::ROW_MAJOR> result;
|
||||
|
||||
const Type* this_mat_data = this->raw_array().data();
|
||||
const Type* other_mat_data = other.raw_array().data();
|
||||
Type* result_mat_data = result.raw_array().data();
|
||||
|
||||
if constexpr (std::is_same_v<Type, float>)
|
||||
{
|
||||
// ReSharper disable once CppTooWideScopeInitStatement
|
||||
constexpr std::size_t vector_size = 8;
|
||||
for (std::size_t i = 0; i < Rows; ++i)
|
||||
{
|
||||
Type* c_row = result_mat_data + i * OtherColumns;
|
||||
for (std::size_t k = 0; k < Columns; ++k)
|
||||
{
|
||||
const auto aik = static_cast<float>(this_mat_data[i * Columns + k]);
|
||||
__m256 aikv = _mm256_set1_ps(aik);
|
||||
const auto* b_row = reinterpret_cast<const float*>(other_mat_data + k * OtherColumns);
|
||||
|
||||
std::size_t j = 0;
|
||||
for (; j + vector_size <= OtherColumns; j += vector_size)
|
||||
{
|
||||
__m256 cvec = _mm256_loadu_ps(c_row + j);
|
||||
__m256 bvec = _mm256_loadu_ps(b_row + j);
|
||||
cvec = _mm256_fmadd_ps(bvec, aikv, cvec);
|
||||
|
||||
_mm256_storeu_ps(c_row + j, cvec);
|
||||
}
|
||||
for (; j < OtherColumns; ++j)
|
||||
c_row[j] += aik * b_row[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (std::is_same_v<Type, double>)
|
||||
{ // double
|
||||
// ReSharper disable once CppTooWideScopeInitStatement
|
||||
constexpr std::size_t vector_size = 4;
|
||||
for (std::size_t i = 0; i < Rows; ++i)
|
||||
{
|
||||
Type* c_row = result_mat_data + i * OtherColumns;
|
||||
for (std::size_t k = 0; k < Columns; ++k)
|
||||
{
|
||||
const auto aik = static_cast<double>(this_mat_data[i * Columns + k]);
|
||||
__m256d aikv = _mm256_set1_pd(aik);
|
||||
const auto* b_row = reinterpret_cast<const double*>(other_mat_data + k * OtherColumns);
|
||||
|
||||
std::size_t j = 0;
|
||||
for (; j + vector_size <= OtherColumns; j += vector_size)
|
||||
{
|
||||
__m256d cvec = _mm256_loadu_pd(c_row + j);
|
||||
__m256d bvec = _mm256_loadu_pd(b_row + j);
|
||||
cvec = _mm256_fmadd_pd(bvec, aikv, cvec);
|
||||
|
||||
_mm256_storeu_pd(c_row + j, cvec);
|
||||
}
|
||||
for (; j < OtherColumns; ++j)
|
||||
c_row[j] += aik * b_row[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
std::unreachable();
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR> [[nodiscard]]
|
||||
@@ -500,6 +677,23 @@ namespace omath
|
||||
{ 0.f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
}
|
||||
template<class T = float, MatStoreType St = MatStoreType::COLUMN_MAJOR>
|
||||
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();
|
||||
const Vector3<T> u = s.cross(f);
|
||||
return mat_camera_view<T, St>(f, s, u, eye);
|
||||
}
|
||||
|
||||
template<class T = float, MatStoreType St = MatStoreType::COLUMN_MAJOR>
|
||||
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();
|
||||
const Vector3<T> u = s.cross(f);
|
||||
return mat_camera_view<T, St>(-f, s, u, eye);
|
||||
}
|
||||
|
||||
} // namespace omath
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
|
||||
// Matrix classes
|
||||
#include "linear_algebra/matrix.hpp"
|
||||
#include "omath/linear_algebra/mat.hpp"
|
||||
|
||||
// Color functionality
|
||||
@@ -81,4 +80,4 @@
|
||||
#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"
|
||||
#include "omath/engines/unreal_engine/traits/pred_engine_trait.hpp"
|
||||
|
||||
@@ -4,13 +4,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "omath/projection/error_codes.hpp"
|
||||
#include "omath/linear_algebra/mat.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include "omath/projection/error_codes.hpp"
|
||||
#include <expected>
|
||||
#include <omath/angle.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef OMATH_BUILD_TESTS
|
||||
// ReSharper disable once CppInconsistentNaming
|
||||
class UnitTestProjection_Projection_Test;
|
||||
#endif
|
||||
|
||||
namespace omath::projection
|
||||
{
|
||||
class ViewPort final
|
||||
@@ -45,6 +50,9 @@ namespace omath::projection
|
||||
requires CameraEngineConcept<TraitClass, Mat4X4Type, ViewAnglesType>
|
||||
class Camera final
|
||||
{
|
||||
#ifdef OMATH_BUILD_TESTS
|
||||
friend UnitTestProjection_Projection_Test;
|
||||
#endif
|
||||
public:
|
||||
~Camera() = default;
|
||||
Camera(const Vector3<float>& position, const ViewAnglesType& view_angles, const ViewPort& view_port,
|
||||
@@ -54,12 +62,13 @@ namespace omath::projection
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void look_at(const Vector3<float>& target)
|
||||
{
|
||||
m_view_angles = TraitClass::calc_look_at_angle(m_origin, target);
|
||||
m_view_projection_matrix = std::nullopt;
|
||||
}
|
||||
|
||||
protected:
|
||||
[[nodiscard]] Mat4X4Type calc_view_projection_matrix() const noexcept
|
||||
{
|
||||
return TraitClass::calc_projection_matrix(m_field_of_view, m_view_port, m_near_plane_distance,
|
||||
@@ -164,6 +173,38 @@ namespace omath::projection
|
||||
|
||||
return Vector3<float>{projected.at(0, 0), projected.at(1, 0), projected.at(2, 0)};
|
||||
}
|
||||
[[nodiscard]]
|
||||
std::expected<Vector3<float>, Error> view_port_to_screen(const Vector3<float>& ndc) const noexcept
|
||||
{
|
||||
const auto inv_view_proj = get_view_projection_matrix().inverted();
|
||||
|
||||
if (!inv_view_proj)
|
||||
return std::unexpected(Error::INV_VIEW_PROJ_MAT_DET_EQ_ZERO);
|
||||
|
||||
auto inverted_projection =
|
||||
inv_view_proj.value() * mat_column_from_vector<float, Mat4X4Type::get_store_ordering()>(ndc);
|
||||
|
||||
if (!inverted_projection.at(3, 0))
|
||||
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
||||
|
||||
inverted_projection /= inverted_projection.at(3, 0);
|
||||
|
||||
return Vector3<float>{inverted_projection.at(0, 0), inverted_projection.at(1, 0),
|
||||
inverted_projection.at(2, 0)};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::expected<Vector3<float>, Error> screen_to_world(const Vector3<float>& screen_pos) const noexcept
|
||||
{
|
||||
return view_port_to_screen(screen_to_ndc(screen_pos));
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::expected<Vector3<float>, Error> screen_to_world(const Vector2<float>& screen_pos) const noexcept
|
||||
{
|
||||
const auto& [x, y] = screen_pos;
|
||||
return screen_to_world({x, y, 1.f});
|
||||
}
|
||||
|
||||
protected:
|
||||
ViewPort m_view_port{};
|
||||
@@ -186,19 +227,25 @@ namespace omath::projection
|
||||
|
||||
[[nodiscard]] Vector3<float> ndc_to_screen_position(const Vector3<float>& ndc) const noexcept
|
||||
{
|
||||
/*
|
||||
^
|
||||
| y
|
||||
1 |
|
||||
|
|
||||
|
|
||||
-1 ---------0--------- 1 --> x
|
||||
|
|
||||
|
|
||||
-1 |
|
||||
v
|
||||
*/
|
||||
/*
|
||||
^
|
||||
| y
|
||||
1 |
|
||||
|
|
||||
|
|
||||
-1 ---------0--------- 1 --> x
|
||||
|
|
||||
|
|
||||
-1 |
|
||||
v
|
||||
*/
|
||||
return {(ndc.x + 1.f) / 2.f * m_view_port.m_width, (1.f - ndc.y) / 2.f * m_view_port.m_height, ndc.z};
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector3<float> screen_to_ndc(const Vector3<float>& screen_pos) const noexcept
|
||||
{
|
||||
return {screen_pos.x / m_view_port.m_width * 2.f - 1.f, 1.f - screen_pos.y / m_view_port.m_height * 2.f,
|
||||
screen_pos.z};
|
||||
}
|
||||
};
|
||||
} // namespace omath::projection
|
||||
|
||||
@@ -10,5 +10,6 @@ namespace omath::projection
|
||||
enum class Error : uint16_t
|
||||
{
|
||||
WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS,
|
||||
INV_VIEW_PROJ_MAT_DET_EQ_ZERO,
|
||||
};
|
||||
}
|
||||
@@ -50,12 +50,10 @@ namespace omath::collision
|
||||
|
||||
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)
|
||||
if (ray.infinite_length && t_hit <= k_epsilon)
|
||||
return ray.end;
|
||||
|
||||
if (t_hit <= k_epsilon || t_hit > 1.0f - k_epsilon)
|
||||
return ray.end;
|
||||
|
||||
return ray.start + ray_dir * t_hit;
|
||||
|
||||
@@ -8,11 +8,10 @@ namespace omath::iw_engine
|
||||
|
||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto distance = cam_origin.distance_to(look_at);
|
||||
const auto delta = cam_origin - look_at;
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(delta.z / distance)),
|
||||
YawAngle::from_radians(std::atan2(delta.y, delta.x)), RollAngle::from_radians(0.f)};
|
||||
return {PitchAngle::from_radians(-std::asin(direction.z)),
|
||||
YawAngle::from_radians(std::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
|
||||
@@ -28,14 +28,13 @@ namespace omath::opengl_engine
|
||||
}
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view<float, MatStoreType::COLUMN_MAJOR>(-forward_vector(angles), right_vector(angles),
|
||||
up_vector(angles), cam_origin);
|
||||
return mat_look_at_right_handed(cam_origin, cam_origin+forward_vector(angles), up_vector(angles));
|
||||
}
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_x<float, MatStoreType::COLUMN_MAJOR>(-angles.pitch)
|
||||
* mat_rotation_axis_y<float, MatStoreType::COLUMN_MAJOR>(-angles.yaw)
|
||||
* mat_rotation_axis_z<float, MatStoreType::COLUMN_MAJOR>(angles.roll);
|
||||
return mat_rotation_axis_z<float, MatStoreType::COLUMN_MAJOR>(angles.roll)
|
||||
* mat_rotation_axis_y<float, MatStoreType::COLUMN_MAJOR>(angles.yaw)
|
||||
* mat_rotation_axis_x<float, MatStoreType::COLUMN_MAJOR>(angles.pitch);
|
||||
}
|
||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||
const float far) noexcept
|
||||
|
||||
@@ -9,11 +9,10 @@ namespace omath::opengl_engine
|
||||
|
||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto distance = cam_origin.distance_to(look_at);
|
||||
const auto delta = cam_origin - look_at;
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(delta.y / distance)),
|
||||
YawAngle::from_radians(std::atan2(delta.z, delta.x)), RollAngle::from_radians(0.f)};
|
||||
return {PitchAngle::from_radians(std::asin(direction.y)),
|
||||
YawAngle::from_radians(-std::atan2(direction.x, -direction.z)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
|
||||
@@ -8,11 +8,11 @@ namespace omath::source_engine
|
||||
|
||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto distance = cam_origin.distance_to(look_at);
|
||||
const auto delta = cam_origin - look_at;
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(delta.z / distance)),
|
||||
YawAngle::from_radians(std::atan2(delta.y, delta.x)), RollAngle::from_radians(0.f)};
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(direction.z)),
|
||||
YawAngle::from_radians(std::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
|
||||
@@ -30,9 +30,9 @@ namespace omath::unity_engine
|
||||
}
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch)
|
||||
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll)
|
||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||
* mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll);
|
||||
* mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch);
|
||||
}
|
||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||
const float far) noexcept
|
||||
|
||||
@@ -9,10 +9,10 @@ namespace omath::unity_engine
|
||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto distance = cam_origin.distance_to(look_at);
|
||||
const auto delta = cam_origin - look_at;
|
||||
const auto delta = look_at - cam_origin;
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(delta.y / distance)),
|
||||
YawAngle::from_radians(std::atan2(delta.z, delta.x)), RollAngle::from_radians(0.f)};
|
||||
YawAngle::from_radians(std::atan2(delta.x, delta.z)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace omath::unreal_engine
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.roll)
|
||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.pitch)
|
||||
* mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.yaw);
|
||||
* mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.pitch);
|
||||
}
|
||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||
const float far) noexcept
|
||||
|
||||
@@ -8,11 +8,10 @@ namespace omath::unreal_engine
|
||||
|
||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto distance = cam_origin.distance_to(look_at);
|
||||
const auto delta = cam_origin - look_at;
|
||||
const auto direction = (look_at - cam_origin).normalized();
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(delta.z / distance)),
|
||||
YawAngle::from_radians(std::atan2(delta.x, delta.y)), RollAngle::from_radians(0.f)};
|
||||
return {PitchAngle::from_radians(-std::asin(direction.z)),
|
||||
YawAngle::from_radians(std::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
|
||||
@@ -11,8 +11,6 @@ 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}"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||
UNITY_BUILD ON
|
||||
UNITY_BUILD_BATCH_SIZE 20
|
||||
CXX_STANDARD 23
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <omath/engines/iw_engine/camera.hpp>
|
||||
#include <omath/engines/iw_engine/constants.hpp>
|
||||
#include <omath/engines/iw_engine/formulas.hpp>
|
||||
|
||||
#include <random>
|
||||
|
||||
TEST(unit_test_iw_engine, ForwardVector)
|
||||
{
|
||||
@@ -68,7 +68,6 @@ TEST(unit_test_iw_engine, ProjectTargetMovedFromCamera)
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const auto cam = omath::iw_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
|
||||
for (float distance = 0.02f; distance < 1000.f; distance += 0.01f)
|
||||
{
|
||||
const auto projected = cam.world_to_screen({distance, 0, 0});
|
||||
@@ -102,4 +101,126 @@ TEST(unit_test_iw_engine, CameraSetAndGetOrigin)
|
||||
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||
|
||||
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||
}
|
||||
|
||||
TEST(unit_test_iw_engine, loook_at_random_all_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::iw_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{dist(gen), dist(gen), dist(gen)};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.001f || std::abs(projected_pos->y - 0.f) >= 0.001f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_iw_engine, loook_at_random_x_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::iw_engine::Camera({dist(gen), dist(gen), dist(gen)}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{dist(gen), 0.f, 0.f};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_iw_engine, loook_at_random_y_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::iw_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{0.f, dist(gen), 0.f};
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_iw_engine, loook_at_random_z_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::iw_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{0.f, 0.f, dist(gen)};
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.025f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <omath/engines/opengl_engine/camera.hpp>
|
||||
#include <omath/engines/opengl_engine/constants.hpp>
|
||||
#include <omath/engines/opengl_engine/formulas.hpp>
|
||||
|
||||
#include <random>
|
||||
|
||||
TEST(unit_test_opengl, ForwardVector)
|
||||
{
|
||||
@@ -29,7 +29,7 @@ TEST(unit_test_opengl, ForwardVectorRotationYaw)
|
||||
{
|
||||
omath::opengl_engine::ViewAngles angles;
|
||||
|
||||
angles.yaw = omath::opengl_engine::YawAngle::from_degrees(90.f);
|
||||
angles.yaw = omath::opengl_engine::YawAngle::from_degrees(-90.f);
|
||||
|
||||
const auto forward = omath::opengl_engine::forward_vector(angles);
|
||||
EXPECT_NEAR(forward.x, omath::opengl_engine::k_abs_right.x, 0.00001f);
|
||||
@@ -37,13 +37,11 @@ TEST(unit_test_opengl, ForwardVectorRotationYaw)
|
||||
EXPECT_NEAR(forward.z, omath::opengl_engine::k_abs_right.z, 0.00001f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(unit_test_opengl, ForwardVectorRotationPitch)
|
||||
{
|
||||
omath::opengl_engine::ViewAngles angles;
|
||||
|
||||
angles.pitch = omath::opengl_engine::PitchAngle::from_degrees(-90.f);
|
||||
angles.pitch = omath::opengl_engine::PitchAngle::from_degrees(90.f);
|
||||
|
||||
const auto forward = omath::opengl_engine::forward_vector(angles);
|
||||
EXPECT_NEAR(forward.x, omath::opengl_engine::k_abs_up.x, 0.00001f);
|
||||
@@ -68,7 +66,6 @@ TEST(unit_test_opengl, ProjectTargetMovedFromCamera)
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const auto cam = omath::opengl_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
|
||||
for (float distance = -10.f; distance > -1000.f; distance -= 0.01f)
|
||||
{
|
||||
const auto projected = cam.world_to_screen({0, 0, distance});
|
||||
@@ -102,4 +99,123 @@ TEST(unit_test_opengl, CameraSetAndGetOrigin)
|
||||
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||
|
||||
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||
}
|
||||
TEST(unit_test_opengl_engine, loook_at_random_all_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::opengl_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{dist(gen), dist(gen), dist(gen)};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.0001f || std::abs(projected_pos->y - 0.f) >= 0.0001f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_opengl_engine, loook_at_random_x_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::opengl_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{dist(gen), 0.f, 0.f};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_opengl_engine, loook_at_random_y_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::opengl_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{0.f, dist(gen), 0.f};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_opengl_engine, loook_at_random_z_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::opengl_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{0.f, 0.f, dist(gen)};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <omath/engines/source_engine/camera.hpp>
|
||||
#include <omath/engines/source_engine/constants.hpp>
|
||||
#include <omath/engines/source_engine/formulas.hpp>
|
||||
|
||||
#include <random>
|
||||
|
||||
TEST(unit_test_source_engine, ForwardVector)
|
||||
{
|
||||
@@ -68,7 +68,6 @@ TEST(unit_test_source_engine, ProjectTargetMovedFromCamera)
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
|
||||
for (float distance = 0.02f; distance < 1000.f; distance += 0.01f)
|
||||
{
|
||||
const auto projected = cam.world_to_screen({distance, 0, 0});
|
||||
@@ -122,4 +121,125 @@ TEST(unit_test_source_engine, CameraSetAndGetOrigin)
|
||||
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||
|
||||
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||
}
|
||||
|
||||
TEST(unit_test_source_engine, loook_at_random_all_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{dist(gen), dist(gen), dist(gen)};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.0001f || std::abs(projected_pos->y - 0.f) >= 0.0001f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_source_engine, loook_at_random_x_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{dist(gen), 0.f, 0.f};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_source_engine, loook_at_random_y_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{0.f, dist(gen), 0.f};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_source_engine, loook_at_random_z_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{0.f, 0.f, dist(gen)};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.025f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <omath/engines/unity_engine/constants.hpp>
|
||||
#include <omath/engines/unity_engine/formulas.hpp>
|
||||
#include <print>
|
||||
#include <random>
|
||||
|
||||
TEST(unit_test_unity_engine, ForwardVector)
|
||||
{
|
||||
@@ -68,7 +69,6 @@ TEST(unit_test_unity_engine, ProjectTargetMovedFromCamera)
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
|
||||
for (float distance = 0.02f; distance < 100.f; distance += 0.01f)
|
||||
{
|
||||
const auto projected = cam.world_to_screen({0, 0, distance});
|
||||
@@ -112,4 +112,125 @@ TEST(unit_test_unity_engine, CameraSetAndGetOrigin)
|
||||
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||
|
||||
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||
}
|
||||
TEST(unit_test_unity_engine, loook_at_random_all_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{dist(gen), dist(gen), dist(gen)};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.0001f || std::abs(projected_pos->y - 0.f) >= 0.0001f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_unity_engine, loook_at_random_x_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{dist(gen), 0.f, 0.f};
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.001f || std::abs(projected_pos->y - 0.f) >= 0.001f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_unity_engine, loook_at_random_y_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{0.f, dist(gen), 0.f};
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_unity_engine, loook_at_random_z_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{0.f, 0.f, dist(gen)};
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <omath/engines/unreal_engine/constants.hpp>
|
||||
#include <omath/engines/unreal_engine/formulas.hpp>
|
||||
#include <print>
|
||||
#include <random>
|
||||
|
||||
TEST(unit_test_unreal_engine, ForwardVector)
|
||||
{
|
||||
@@ -68,7 +69,6 @@ TEST(unit_test_unreal_engine, ProjectTargetMovedFromCamera)
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const auto cam = omath::unreal_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
|
||||
for (float distance = 0.02f; distance < 100.f; distance += 0.01f)
|
||||
{
|
||||
const auto projected = cam.world_to_screen({distance, 0, 0});
|
||||
@@ -102,4 +102,128 @@ TEST(unit_test_unreal_engine, CameraSetAndGetOrigin)
|
||||
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||
|
||||
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||
}
|
||||
|
||||
TEST(unit_test_unreal_engine, loook_at_random_all_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::unreal_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{dist(gen), dist(gen), dist(gen)};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.0001f || std::abs(projected_pos->y - 0.f) >= 0.0001f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_unreal_engine, loook_at_random_x_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::unreal_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{dist(gen), dist(gen), dist(gen)};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_unreal_engine, loook_at_random_y_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::unreal_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{0.f, dist(gen), 0.f};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_unreal_engine, loook_at_random_z_axis)
|
||||
{
|
||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
auto cam = omath::unreal_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||
|
||||
std::size_t failed_points = 0;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
const auto position_to_look = omath::Vector3<float>{0.f, 0.f, dist(gen)};
|
||||
|
||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||
continue;
|
||||
|
||||
cam.look_at(position_to_look);
|
||||
|
||||
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||
|
||||
EXPECT_TRUE(projected_pos.has_value());
|
||||
|
||||
if (!projected_pos)
|
||||
continue;
|
||||
|
||||
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
@@ -13,8 +13,12 @@ TEST(UnitTestProjection, Projection)
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, fov,
|
||||
0.01f, 1000.f);
|
||||
|
||||
const auto projected = cam.world_to_screen({1000, 0, 50});
|
||||
const auto projected = cam.world_to_screen({1000.f, 0, 50.f});
|
||||
const auto result = cam.screen_to_world(projected.value());
|
||||
const auto result2 = cam.world_to_screen(result.value());
|
||||
|
||||
EXPECT_EQ(static_cast<omath::Vector2<float>>(projected.value()),
|
||||
static_cast<omath::Vector2<float>>(result2.value()));
|
||||
EXPECT_NEAR(projected->x, 960.f, 0.001f);
|
||||
EXPECT_NEAR(projected->y, 504.f, 0.001f);
|
||||
EXPECT_NEAR(projected->z, 1.f, 0.001f);
|
||||
|
||||
Reference in New Issue
Block a user