Compare commits
145 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 568883ff1c | |||
| 97003b953a | |||
| 5646654317 | |||
| ee54e3de34 | |||
| 7b0af9cf66 | |||
| 563ae0a656 | |||
| b9e2307d7a | |||
| cd0a864e7c | |||
| 5c30f57c4c | |||
| 3dcd033616 | |||
| f10dc60772 | |||
| 37f624956b | |||
| 20dc4e6730 | |||
| f6c607d84c | |||
| 81ed5f80d7 | |||
|
|
e385686323 | ||
| 086eda4ee3 | |||
| 9419e390da | |||
| d919600ac2 | |||
| 11681ac601 | |||
| 6c5152297a | |||
| 547f64e4c4 | |||
| 3129e32f0c | |||
| 72b54e9673 | |||
| 2ff291b255 | |||
| 8eda1ce4bc | |||
| e1b4375621 | |||
| d84259fdcc | |||
| d64c7ad756 | |||
| 710f91999f | |||
| f3fe0e3cee | |||
| c5c5c2e972 | |||
| a7cb056ce7 | |||
| dae1555ec4 | |||
| 2c6ef1b8cc | |||
| d70e8853e8 | |||
| e35d64b486 | |||
| 9868c832a1 | |||
| 42e46f9921 | |||
| e7ccc2ead0 | |||
| 170f969697 | |||
| 131fd891b0 | |||
| a5396b72cb | |||
| ec876ea292 | |||
| 8021050fad | |||
| bd585b5412 | |||
| 06f9a8c9ee | |||
| 160b51da94 | |||
| 064edf9ef1 | |||
| f17d36dcd3 | |||
| ec4f9f6c90 | |||
| cbee8c2c95 | |||
| dc6edbb67f | |||
| 74381eda5c | |||
| 1ef7833bd9 | |||
| c10386f3f6 | |||
| 413cef4f23 | |||
| 867cee41c3 | |||
| 990fe78a33 | |||
| 1efdb50f73 | |||
|
|
86fea065e7 | ||
|
|
ac046aae6c | ||
|
|
9646054877 | ||
| 6334002639 | |||
| 72e0c0c90b | |||
| 2f2a5a00c4 | |||
| c394993418 | |||
| 476048583d | |||
| 76ae67c968 | |||
| d1d95d2f36 | |||
| 6409568334 | |||
| 83ba339eb5 | |||
| c49c93d542 | |||
| 92dab52d66 | |||
| dac3d8e43f | |||
| fb0b05d7ef | |||
| 993212e7ab | |||
| 380a9f0a16 | |||
| ba7bce5502 | |||
| ce40891e37 | |||
| c4d10f8872 | |||
| 2bb0c82c30 | |||
| a4dcf8dc3b | |||
| 17eaddbc8c | |||
| 9005c02499 | |||
| 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 |
BIN
.github/images/yt_previews/img.png
vendored
Normal file
|
After Width: | Height: | Size: 1.5 MiB |
8
.github/workflows/cmake-multi-platform.yml
vendored
@@ -35,11 +35,11 @@ jobs:
|
|||||||
|
|
||||||
- name: Configure (cmake --preset)
|
- name: Configure (cmake --preset)
|
||||||
shell: bash
|
shell: bash
|
||||||
run: cmake --preset linux-release -DOMATH_BUILD_TESTS=ON
|
run: cmake --preset linux-release -DOMATH_BUILD_TESTS=ON -DOMATH_BUILD_BENCHMARK=OFF
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
run: cmake --build cmake-build/build/linux-release --target all
|
run: cmake --build cmake-build/build/linux-release --target unit_tests omath
|
||||||
|
|
||||||
- name: Run unit_tests
|
- name: Run unit_tests
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -68,11 +68,11 @@ jobs:
|
|||||||
|
|
||||||
- name: Configure (cmake --preset)
|
- name: Configure (cmake --preset)
|
||||||
shell: bash
|
shell: bash
|
||||||
run: cmake --preset windows-release -DOMATH_BUILD_TESTS=ON
|
run: cmake --preset windows-release -DOMATH_BUILD_TESTS=ON -DOMATH_BUILD_BENCHMARK=OFF
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
run: cmake --build cmake-build/build/windows-release --target all
|
run: cmake --build cmake-build/build/windows-release --target unit_tests omath
|
||||||
|
|
||||||
- name: Run unit_tests.exe
|
- name: Run unit_tests.exe
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
5
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
|||||||
[submodule "extlibs/googletest"]
|
[submodule "extlibs/googletest"]
|
||||||
path = 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
|
||||||
|
|||||||
4
.idea/editor.xml
generated
@@ -201,7 +201,7 @@
|
|||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticDataMemberInUnnamedStruct/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticDataMemberInUnnamedStruct/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStringLiteralToCharPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStringLiteralToCharPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateArgumentsCanBeDeduced/@EntryIndexedValue" value="HINT" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateArgumentsCanBeDeduced/@EntryIndexedValue" value="HINT" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
@@ -215,7 +215,7 @@
|
|||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnamedNamespaceInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnamedNamespaceInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnsignedZeroComparison/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnsignedZeroComparison/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnusedIncludeDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnusedIncludeDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||||
|
|||||||
1
.idea/vcs.xml
generated
@@ -2,6 +2,7 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="" vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/extlibs/benchmark" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/extlibs/googletest" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/extlibs/googletest" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,14 +1,21 @@
|
|||||||
cmake_minimum_required(VERSION 3.26)
|
cmake_minimum_required(VERSION 3.26)
|
||||||
|
|
||||||
project(omath VERSION 3.5.0 LANGUAGES CXX)
|
project(omath VERSION 3.9.2 LANGUAGES CXX)
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
|
||||||
|
else ()
|
||||||
|
check_cxx_compiler_flag("-mavx2" COMPILER_SUPPORTS_AVX2)
|
||||||
|
endif ()
|
||||||
|
|
||||||
option(OMATH_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL})
|
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_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_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_USE_AVX2 "Omath will use AVX2 to boost performance" ${COMPILER_SUPPORTS_AVX2})
|
||||||
option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF)
|
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_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)
|
||||||
@@ -16,27 +23,35 @@ 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_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)
|
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}")
|
if (OMATH_USE_AVX2 AND NOT COMPILER_SUPPORTS_AVX2)
|
||||||
message(STATUS "[${PROJECT_NAME}]: Warnings as errors ${OMATH_THREAT_WARNING_AS_ERROR}")
|
message(WARNING "OMATH_USE_AVX2 requested, but compiler/target does not support AVX2. Disabling.")
|
||||||
message(STATUS "[${PROJECT_NAME}]: Build unit tests ${OMATH_BUILD_TESTS}")
|
set(OMATH_USE_AVX2 OFF CACHE BOOL "Omath will use AVX2 to boost performance" FORCE)
|
||||||
message(STATUS "[${PROJECT_NAME}]: As dynamic library ${OMATH_BUILD_AS_SHARED_LIBRARY}")
|
endif ()
|
||||||
message(STATUS "[${PROJECT_NAME}]: Static C++ runtime ${OMATH_STATIC_MSVC_RUNTIME_LIBRARY}")
|
|
||||||
message(STATUS "[${PROJECT_NAME}]: CMake unity build ${OMATH_USE_UNITY_BUILD}")
|
if (${PROJECT_IS_TOP_LEVEL})
|
||||||
message(STATUS "[${PROJECT_NAME}]: Example projects ${OMATH_BUILD_EXAMPLES}")
|
message(STATUS "[${PROJECT_NAME}]: Building on ${CMAKE_HOST_SYSTEM_NAME}, compiler ${CMAKE_CXX_COMPILER_ID}")
|
||||||
message(STATUS "[${PROJECT_NAME}]: AVX2 feature status ${OMATH_USE_AVX2}")
|
message(STATUS "[${PROJECT_NAME}]: Warnings as errors ${OMATH_THREAT_WARNING_AS_ERROR}")
|
||||||
message(STATUS "[${PROJECT_NAME}]: ImGUI integration feature status ${OMATH_IMGUI_INTEGRATION}")
|
message(STATUS "[${PROJECT_NAME}]: Build unit tests ${OMATH_BUILD_TESTS}")
|
||||||
message(STATUS "[${PROJECT_NAME}]: Legacy features support ${OMATH_ENABLE_LEGACY}")
|
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}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Example projects ${OMATH_BUILD_EXAMPLES}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: AVX2 feature status ${OMATH_USE_AVX2}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: ImGUI integration feature status ${OMATH_IMGUI_INTEGRATION}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Legacy features support ${OMATH_ENABLE_LEGACY}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
|
file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
|
||||||
file(GLOB_RECURSE OMATH_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
|
file(GLOB_RECURSE OMATH_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
|
||||||
|
|
||||||
|
|
||||||
if (OMATH_BUILD_AS_SHARED_LIBRARY)
|
if (OMATH_BUILD_AS_SHARED_LIBRARY)
|
||||||
add_library(${PROJECT_NAME} SHARED ${OMATH_SOURCES} ${OMATH_HEADERS})
|
add_library(${PROJECT_NAME} SHARED ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||||
else ()
|
else ()
|
||||||
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||||
|
|
||||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}")
|
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}")
|
||||||
@@ -90,19 +105,30 @@ if (OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
|
|||||||
)
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
if (OMATH_USE_AVX2)
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE -mavx2 -mfma)
|
if (MSVC)
|
||||||
|
target_compile_options(${PROJECT_NAME} PUBLIC /arch:AVX2)
|
||||||
|
elseif (EMSCRIPTEN)
|
||||||
|
target_compile_options(${PROJECT_NAME} PUBLIC -msimd128 -mavx2)
|
||||||
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
|
||||||
|
target_compile_options(${PROJECT_NAME} PUBLIC -mfma -mavx2)
|
||||||
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
|
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
|
||||||
|
|
||||||
|
add_subdirectory(extlibs)
|
||||||
|
|
||||||
|
|
||||||
if (OMATH_BUILD_TESTS)
|
if (OMATH_BUILD_TESTS)
|
||||||
add_subdirectory(extlibs)
|
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_BUILD_TESTS)
|
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_BUILD_TESTS)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (OMATH_BUILD_BENCHMARK)
|
||||||
|
add_subdirectory(benchmark)
|
||||||
|
endif ()
|
||||||
|
|
||||||
if (OMATH_BUILD_EXAMPLES)
|
if (OMATH_BUILD_EXAMPLES)
|
||||||
add_subdirectory(examples)
|
add_subdirectory(examples)
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
|
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
|
||||||
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
|
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"CMAKE_C_COMPILER": "cl.exe",
|
|
||||||
"CMAKE_CXX_COMPILER": "cl.exe"
|
"CMAKE_CXX_COMPILER": "cl.exe"
|
||||||
},
|
},
|
||||||
"condition": {
|
"condition": {
|
||||||
@@ -40,7 +39,6 @@
|
|||||||
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
|
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
|
||||||
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
|
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"CMAKE_C_COMPILER": "clang",
|
|
||||||
"CMAKE_CXX_COMPILER": "clang++"
|
"CMAKE_CXX_COMPILER": "clang++"
|
||||||
},
|
},
|
||||||
"condition": {
|
"condition": {
|
||||||
@@ -72,7 +70,6 @@
|
|||||||
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
|
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
|
||||||
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
|
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"CMAKE_C_COMPILER": "clang",
|
|
||||||
"CMAKE_CXX_COMPILER": "clang++"
|
"CMAKE_CXX_COMPILER": "clang++"
|
||||||
},
|
},
|
||||||
"condition": {
|
"condition": {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
Thanks to everyone who made this possible, including:
|
Thanks to everyone who made this possible, including:
|
||||||
|
|
||||||
- Saikari aka luadebug for VCPKG port and awesome new initial logo design.
|
- 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!
|
And a big hand to everyone else who has contributed over the past!
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ target("...")
|
|||||||
cmake --preset windows-release -S .
|
cmake --preset windows-release -S .
|
||||||
cmake --build cmake-build/build/windows-release --target omath -j 6
|
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**.
|
Use **\<platform\>-\<build configuration\>** preset to build suitable version for yourself. Like **windows-release** or **linux-release**.
|
||||||
|
|
||||||
| Platform Name | Build Config |
|
| Platform Name | Build Config |
|
||||||
|---------------|---------------|
|
|---------------|---------------|
|
||||||
|
|||||||
1
LICENSE
@@ -20,6 +20,7 @@ freely, subject to the following restrictions:
|
|||||||
with any of the following entities:
|
with any of the following entities:
|
||||||
* "Yandex" LLC
|
* "Yandex" LLC
|
||||||
* "Rutube" LLC
|
* "Rutube" LLC
|
||||||
|
* "Kaspersky" LLC
|
||||||
Or if you represent or are associated with any legal, organizational, or
|
Or if you represent or are associated with any legal, organizational, or
|
||||||
professional entity providing services to or on behalf of the aforementioned entities:
|
professional entity providing services to or on behalf of the aforementioned entities:
|
||||||
You are expressly forbidden from accessing, using, modifying, distributing, or
|
You are expressly forbidden from accessing, using, modifying, distributing, or
|
||||||
|
|||||||
104
README.md
@@ -12,9 +12,26 @@
|
|||||||
[](https://discord.gg/eDgdaWbqwZ)
|
[](https://discord.gg/eDgdaWbqwZ)
|
||||||
[](https://t.me/orangennotes)
|
[](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> Documentation <br> </kbd>][DOCUMENTATION]**
|
||||||
|
**[<kbd> <br> Contribute <br> </kbd>][CONTRIBUTING]**
|
||||||
|
**[<kbd> <br> Donate <br> </kbd>][SPONSOR]**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
</div>
|
</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>
|
<div align = center>
|
||||||
<a href="https://www.star-history.com/#orange-cpp/omath&Date">
|
<a href="https://www.star-history.com/#orange-cpp/omath&Date">
|
||||||
@@ -26,7 +43,7 @@ Oranges's Math Library (omath) is a comprehensive, open-source library aimed at
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
## 👁🗨 Features
|
# Features
|
||||||
- **Efficiency**: Optimized for performance, ensuring quick computations using AVX2.
|
- **Efficiency**: Optimized for performance, ensuring quick computations using AVX2.
|
||||||
- **Versatility**: Includes a wide array of mathematical functions and algorithms.
|
- **Versatility**: Includes a wide array of mathematical functions and algorithms.
|
||||||
- **Ease of Use**: Simplified interface for convenient integration into various projects.
|
- **Ease of Use**: Simplified interface for convenient integration into various projects.
|
||||||
@@ -35,68 +52,45 @@ Oranges's Math Library (omath) is a comprehensive, open-source library aimed at
|
|||||||
- **Collision Detection**: Production ready code to handle collision detection by using simple interfaces.
|
- **Collision Detection**: Production ready code to handle collision detection by using simple interfaces.
|
||||||
- **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution
|
- **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!
|
- **Ready for meta-programming**: Omath use templates for common types like Vectors, Matrixes etc, to handle all types!
|
||||||
|
- **Engine support**: Supports coordinate systems of Source, Unity, Unreal, IWEngine and canonical OpenGL.
|
||||||
|
- **Cross platform**: Supports Windows, MacOS and Linux.
|
||||||
|
- **Algorithms**: Has ability to scan for byte pattern with wildcards in PE files/modules, binary slices, works even with Wine apps.
|
||||||
|
<div align = center>
|
||||||
|
|
||||||
|
# Gallery
|
||||||
|
|
||||||
## Supported Render Pipelines
|
<br>
|
||||||
| ENGINE | SUPPORT |
|
|
||||||
|----------|---------|
|
|
||||||
| Source | ✅YES |
|
|
||||||
| Unity | ✅YES |
|
|
||||||
| IWEngine | ✅YES |
|
|
||||||
| OpenGL | ✅YES |
|
|
||||||
| Unreal | ✅YES |
|
|
||||||
|
|
||||||
## Supported Operating Systems
|
[](https://youtu.be/lM_NJ1yCunw?si=-Qf5yzDcWbaxAXGQ)
|
||||||
|
|
||||||
| OS | SUPPORT |
|
<br>
|
||||||
|----------------|---------|
|
|
||||||
| Windows 10/11 | ✅YES |
|
|
||||||
| Linux | ✅YES |
|
|
||||||
| Darwin (MacOS) | ✅YES |
|
|
||||||
|
|
||||||
## ⏬ Installation
|
![APEX Preview]
|
||||||
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
|
<br>
|
||||||
ESP example
|
|
||||||
```c++
|
|
||||||
omath::source_engine::Camera cam{localPlayer.GetCameraOrigin(),
|
|
||||||
localPlayer.GetAimPunch(),
|
|
||||||
{1920.f, 1080.f},
|
|
||||||
localPlayer.GetFieldOfView(),
|
|
||||||
0.01.f, 30000.f};
|
|
||||||
|
|
||||||
for (auto ent: apex_sdk::EntityList::GetAllEntities())
|
![BO2 Preview]
|
||||||
{
|
|
||||||
const auto bottom = cam.world_to_screen(ent.GetOrigin());
|
|
||||||
const auto top = cam.world_to_screen(ent.GetBonePosition(8) + omath::Vector3<float>{0, 0, 10});
|
|
||||||
|
|
||||||
const auto ent_health = ent.GetHealth();
|
<br>
|
||||||
|
|
||||||
if (!top || !bottom || ent_health <= 0)
|
![CS2 Preview]
|
||||||
continue;
|
|
||||||
// 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/).
|
<br>
|
||||||
|
<br>
|
||||||
|
|
||||||

|
</div>
|
||||||
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
|
# 💘 Acknowledgments
|
||||||
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)
|
- [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
|
||||||
|
[DOCUMENTATION]: http://libomath.org
|
||||||
|
[CONTRIBUTING]: CONTRIBUTING.md
|
||||||
|
[EXAMPLES]: examples
|
||||||
|
[SPONSOR]: https://boosty.to/orangecpp/purchase/3568644?ssource=DIRECT&share=subscription_link
|
||||||
|
|||||||
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)
|
||||||
65
benchmark/benchmark_mat.cpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 9/17/2025.
|
||||||
|
//
|
||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
|
||||||
|
#include <omath/omath.hpp>
|
||||||
|
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 ([[maybe_unused]] const 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 ([[maybe_unused]] const 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 ([[maybe_unused]] const 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 ([[maybe_unused]] const 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);
|
||||||
23
benchmark/benchmark_projectile_pred.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 9/18/2025.
|
||||||
|
//
|
||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
#include <omath/omath.hpp>
|
||||||
|
using namespace omath;
|
||||||
|
|
||||||
|
using namespace omath::projectile_prediction;
|
||||||
|
|
||||||
|
constexpr float simulation_time_step = 1.f / 1000.f;
|
||||||
|
constexpr float hit_distance_tolerance = 5.f;
|
||||||
|
|
||||||
|
void source_engine_projectile_prediction(benchmark::State& state)
|
||||||
|
{
|
||||||
|
constexpr Target target{.m_origin = {100, 0, 90}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
constexpr Projectile projectile = {.m_origin = {3, 2, 1}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
for ([[maybe_unused]] const auto _: state)
|
||||||
|
std::ignore = ProjPredEngineLegacy(400, simulation_time_step, 50, hit_distance_tolerance)
|
||||||
|
.maybe_calculate_aim_point(projectile, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(source_engine_projectile_prediction)->Iterations(10'000);
|
||||||
5
benchmark/main.cpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 9/17/2025.
|
||||||
|
//
|
||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
BENCHMARK_MAIN();
|
||||||
17
docs/index.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Welcome to MkDocs
|
||||||
|
|
||||||
|
For full documentation visit [mkdocs.org](https://www.mkdocs.org).
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
* `mkdocs new [dir-name]` - Create a new project.
|
||||||
|
* `mkdocs serve` - Start the live-reloading docs server.
|
||||||
|
* `mkdocs build` - Build the documentation site.
|
||||||
|
* `mkdocs -h` - Print help message and exit.
|
||||||
|
|
||||||
|
## Project layout
|
||||||
|
|
||||||
|
mkdocs.yml # The configuration file.
|
||||||
|
docs/
|
||||||
|
index.md # The documentation homepage.
|
||||||
|
... # Other markdown pages, images and other files.
|
||||||
@@ -1 +1,9 @@
|
|||||||
add_subdirectory(googletest)
|
|
||||||
|
if (OMATH_BUILD_TESTS)
|
||||||
|
add_subdirectory(googletest)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (OMATH_BUILD_BENCHMARK)
|
||||||
|
set(BENCHMARK_ENABLE_TESTING OFF)
|
||||||
|
add_subdirectory(benchmark)
|
||||||
|
endif ()
|
||||||
1
extlibs/benchmark
Submodule
@@ -3,8 +3,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "omath/linear_algebra/triangle.hpp"
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include "omath/triangle.hpp"
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
namespace omath::primitives
|
namespace omath::primitives
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "omath/linear_algebra/triangle.hpp"
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include "omath/triangle.hpp"
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
namespace omath::primitives
|
namespace omath::primitives
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "omath/linear_algebra/triangle.hpp"
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include "omath/triangle.hpp"
|
|
||||||
|
|
||||||
namespace omath::collision
|
namespace omath::collision
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "omath/linear_algebra/mat.hpp"
|
#include "omath/linear_algebra/mat.hpp"
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include <omath/angle.hpp>
|
#include <omath/trigonometry/angle.hpp>
|
||||||
#include <omath/view_angles.hpp>
|
#include <omath/trigonometry/view_angles.hpp>
|
||||||
|
|
||||||
namespace omath::iw_engine
|
namespace omath::iw_engine
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
#include "omath/linear_algebra/mat.hpp"
|
#include "omath/linear_algebra/mat.hpp"
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include <omath/angle.hpp>
|
#include <omath/trigonometry/angle.hpp>
|
||||||
#include <omath/view_angles.hpp>
|
#include <omath/trigonometry/view_angles.hpp>
|
||||||
|
|
||||||
namespace omath::opengl_engine
|
namespace omath::opengl_engine
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,17 +62,15 @@ namespace omath::opengl_engine
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||||
{
|
{
|
||||||
const auto distance = origin.distance_to(view_to);
|
const auto direction = (view_to - origin).normalized();
|
||||||
const auto delta = view_to - origin;
|
return angles::radians_to_degrees(std::asin(direction.y));
|
||||||
|
|
||||||
return angles::radians_to_degrees(std::asin(delta.y / distance));
|
|
||||||
}
|
}
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||||
{
|
{
|
||||||
const auto delta = view_to - origin;
|
const auto direction = (view_to - origin).normalized();
|
||||||
|
|
||||||
return angles::radians_to_degrees(std::atan2(delta.z, delta.x));
|
return angles::radians_to_degrees(-std::atan2(direction.x, -direction.z));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
} // namespace omath::opengl_engine
|
} // namespace omath::opengl_engine
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
#include "omath/linear_algebra/mat.hpp"
|
#include "omath/linear_algebra/mat.hpp"
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include <omath/angle.hpp>
|
#include <omath/trigonometry/angle.hpp>
|
||||||
#include <omath/view_angles.hpp>
|
#include <omath/trigonometry/view_angles.hpp>
|
||||||
|
|
||||||
namespace omath::source_engine
|
namespace omath::source_engine
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#include "omath/linear_algebra/mat.hpp"
|
#include "omath/linear_algebra/mat.hpp"
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include <omath/angle.hpp>
|
#include <omath/trigonometry/angle.hpp>
|
||||||
#include <omath/view_angles.hpp>
|
#include <omath/trigonometry/view_angles.hpp>
|
||||||
|
|
||||||
namespace omath::unity_engine
|
namespace omath::unity_engine
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,17 +62,15 @@ namespace omath::unity_engine
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||||
{
|
{
|
||||||
const auto distance = origin.distance_to(view_to);
|
const auto direction = (view_to - origin).normalized();
|
||||||
const auto delta = view_to - origin;
|
return angles::radians_to_degrees(std::asin(direction.y));
|
||||||
|
|
||||||
return angles::radians_to_degrees(std::asin(delta.y / distance));
|
|
||||||
}
|
}
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||||
{
|
{
|
||||||
const auto delta = view_to - origin;
|
const auto direction = (view_to - origin).normalized();
|
||||||
|
|
||||||
return angles::radians_to_degrees(std::atan2(delta.z, delta.x));
|
return angles::radians_to_degrees(std::atan2(direction.x, direction.z));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
} // namespace omath::unity_engine
|
} // namespace omath::unity_engine
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#include "omath/linear_algebra/mat.hpp"
|
#include "omath/linear_algebra/mat.hpp"
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include <omath/angle.hpp>
|
#include <omath/trigonometry/angle.hpp>
|
||||||
#include <omath/view_angles.hpp>
|
#include <omath/trigonometry/view_angles.hpp>
|
||||||
|
|
||||||
namespace omath::unreal_engine
|
namespace omath::unreal_engine
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,17 +62,16 @@ namespace omath::unreal_engine
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||||
{
|
{
|
||||||
const auto distance = origin.distance_to(view_to);
|
const auto direction = (view_to - origin).normalized();
|
||||||
const auto delta = view_to - origin;
|
|
||||||
|
|
||||||
return angles::radians_to_degrees(std::asin(delta.z / distance));
|
return angles::radians_to_degrees(std::asin(direction.z));
|
||||||
}
|
}
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||||
{
|
{
|
||||||
const auto delta = view_to - origin;
|
const auto direction = (view_to - origin).normalized();
|
||||||
|
|
||||||
return angles::radians_to_degrees(std::atan2(delta.y, delta.x));
|
return angles::radians_to_degrees(std::atan2(direction.y, direction.x));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
} // namespace omath::unreal_engine
|
} // namespace omath::unreal_engine
|
||||||
|
|||||||
@@ -11,7 +11,12 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#ifdef OMATH_USE_AVX2
|
||||||
|
#include <immintrin.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef near
|
||||||
|
#undef far
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
struct MatSize
|
struct MatSize
|
||||||
@@ -155,17 +160,19 @@ namespace omath
|
|||||||
constexpr Mat<Rows, OtherColumns, Type, StoreType>
|
constexpr Mat<Rows, OtherColumns, Type, StoreType>
|
||||||
operator*(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
|
operator*(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
|
||||||
{
|
{
|
||||||
Mat<Rows, OtherColumns, Type, StoreType> result;
|
#ifdef OMATH_USE_AVX2
|
||||||
|
if constexpr (StoreType == MatStoreType::ROW_MAJOR)
|
||||||
for (size_t i = 0; i < Rows; ++i)
|
return avx_multiply_row_major(other);
|
||||||
for (size_t j = 0; j < OtherColumns; ++j)
|
else if constexpr (StoreType == MatStoreType::COLUMN_MAJOR)
|
||||||
{
|
return avx_multiply_col_major(other);
|
||||||
Type sum = 0;
|
#else
|
||||||
for (size_t k = 0; k < Columns; ++k)
|
if constexpr (StoreType == MatStoreType::ROW_MAJOR)
|
||||||
sum += at(i, k) * other.at(k, j);
|
return cache_friendly_multiply_row_major(other);
|
||||||
result.at(i, j) = sum;
|
else if constexpr (StoreType == MatStoreType::COLUMN_MAJOR)
|
||||||
}
|
return cache_friendly_multiply_col_major(other);
|
||||||
return result;
|
#endif
|
||||||
|
else
|
||||||
|
std::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Mat& operator*=(const Type& f) noexcept
|
constexpr Mat& operator*=(const Type& f) noexcept
|
||||||
@@ -321,6 +328,21 @@ namespace omath
|
|||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
std::wstring to_wstring() const noexcept
|
||||||
|
{
|
||||||
|
const auto ascii_string = to_string();
|
||||||
|
return {ascii_string.cbegin(), ascii_string.cend()};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
// ReSharper disable once CppInconsistentNaming
|
||||||
|
std::u8string to_u8string() const noexcept
|
||||||
|
{
|
||||||
|
const auto ascii_string = to_string();
|
||||||
|
return {ascii_string.cbegin(), ascii_string.cend()};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool operator==(const Mat& mat) const
|
bool operator==(const Mat& mat) const
|
||||||
{
|
{
|
||||||
@@ -367,6 +389,176 @@ namespace omath
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<Type, Rows * Columns> m_data;
|
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];
|
||||||
|
const __m256 bkj_vec = _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);
|
||||||
|
const __m256 a_vec = _mm256_loadu_ps(a_col_k + i);
|
||||||
|
cvec = _mm256_fmadd_ps(a_vec, bkj_vec, 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];
|
||||||
|
const __m256d bkj_vec = _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);
|
||||||
|
const __m256d a_vec = _mm256_loadu_pd(a_col_k + i);
|
||||||
|
cvec = _mm256_fmadd_pd(a_vec, bkj_vec, 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]);
|
||||||
|
const __m256 aik_vec = _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);
|
||||||
|
const __m256 b_vec = _mm256_loadu_ps(b_row + j);
|
||||||
|
cvec = _mm256_fmadd_ps(b_vec, aik_vec, 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]);
|
||||||
|
const __m256d aik_vec = _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);
|
||||||
|
const __m256d b_vec = _mm256_loadu_pd(b_row + j);
|
||||||
|
cvec = _mm256_fmadd_pd(b_vec, aik_vec, 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]]
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR> [[nodiscard]]
|
||||||
@@ -500,6 +692,23 @@ namespace omath
|
|||||||
{ 0.f, 0.f, 0.f, 1.f }
|
{ 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
|
} // namespace omath
|
||||||
|
|
||||||
@@ -512,9 +721,18 @@ struct std::formatter<omath::Mat<Rows, Columns, Type, StoreType>> // NOLINT(*-dc
|
|||||||
{
|
{
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class FormatContext>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static auto format(const MatType& mat, std::format_context& ctx)
|
static auto format(const MatType& mat, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
return std::format_to(ctx.out(), "{}", mat.to_string());
|
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||||
|
return std::format_to(ctx.out(), "{}", mat.to_string());
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
|
||||||
|
return std::format_to(ctx.out(), L"{}", mat.to_wstring());
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
|
||||||
|
return std::format_to(ctx.out(), u8"{}", mat.to_u8string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Created by Orange on 11/13/2024.
|
// Created by Orange on 11/13/2024.
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "linear_algebra/vector3.hpp"
|
#include "vector3.hpp"
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
@@ -242,9 +242,18 @@ struct std::formatter<omath::Vector2<Type>> // NOLINT(*-dcl58-cpp)
|
|||||||
{
|
{
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class FormatContext>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static auto format(const omath::Vector2<Type>& vec, std::format_context& ctx)
|
static auto format(const omath::Vector2<Type>& vec, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y);
|
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||||
|
return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
|
||||||
|
return std::format_to(ctx.out(), L"[{}, {}]", vec.x, vec.y);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
|
||||||
|
return std::format_to(ctx.out(), u8"[{}, {}]", vec.x, vec.y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "omath/angle.hpp"
|
#include "omath/trigonometry/angle.hpp"
|
||||||
#include "omath/linear_algebra/vector2.hpp"
|
#include "omath/linear_algebra/vector2.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <expected>
|
#include <expected>
|
||||||
@@ -245,15 +245,6 @@ namespace omath
|
|||||||
return std::make_tuple(this->x, this->y, z);
|
return std::make_tuple(this->x, this->y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] Vector3 view_angle_to(const Vector3& other) const noexcept
|
|
||||||
{
|
|
||||||
const auto distance = distance_to(other);
|
|
||||||
const auto delta = other - *this;
|
|
||||||
|
|
||||||
return {angles::radians_to_degrees(std::asin(delta.z / distance)),
|
|
||||||
angles::radians_to_degrees(std::atan2(delta.y, delta.x)), 0};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool operator<(const Vector3& other) const noexcept
|
bool operator<(const Vector3& other) const noexcept
|
||||||
{
|
{
|
||||||
@@ -303,9 +294,18 @@ struct std::formatter<omath::Vector3<Type>> // NOLINT(*-dcl58-cpp)
|
|||||||
{
|
{
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class FormatContext>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static auto format(const omath::Vector3<Type>& vec, std::format_context& ctx)
|
static auto format(const omath::Vector3<Type>& vec, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
return std::format_to(ctx.out(), "[{}, {}, {}]", vec.x, vec.y, vec.z);
|
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||||
|
return std::format_to(ctx.out(), "[{}, {}, {}]", vec.x, vec.y, vec.z);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
|
||||||
|
return std::format_to(ctx.out(), L"[{}, {}, {}]", vec.x, vec.y, vec.z);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
|
||||||
|
return std::format_to(ctx.out(), u8"[{}, {}, {}]", vec.x, vec.y, vec.z);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -210,9 +210,17 @@ struct std::formatter<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
|
|||||||
{
|
{
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
template<class FormatContext>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static auto format(const omath::Vector4<Type>& vec, std::format_context& ctx)
|
static auto format(const omath::Vector4<Type>& vec, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
return std::format_to(ctx.out(), "[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
|
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||||
|
return std::format_to(ctx.out(), "[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
|
||||||
|
return std::format_to(ctx.out(), L"[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
|
||||||
|
return std::format_to(ctx.out(), u8"[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Basic math utilities
|
// Basic math utilities
|
||||||
#include "omath/angles.hpp"
|
#include "omath/trigonometry/angles.hpp"
|
||||||
#include "omath/angle.hpp"
|
#include "omath/trigonometry/angle.hpp"
|
||||||
|
|
||||||
// Vector classes (in dependency order)
|
// Vector classes (in dependency order)
|
||||||
#include "omath/linear_algebra/vector2.hpp"
|
#include "omath/linear_algebra/vector2.hpp"
|
||||||
@@ -15,18 +15,18 @@
|
|||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
|
|
||||||
// Matrix classes
|
// Matrix classes
|
||||||
#include "linear_algebra/matrix.hpp"
|
|
||||||
#include "omath/linear_algebra/mat.hpp"
|
#include "omath/linear_algebra/mat.hpp"
|
||||||
|
|
||||||
// Color functionality
|
// Color functionality
|
||||||
#include "omath/color.hpp"
|
#include "omath/utility/color.hpp"
|
||||||
|
|
||||||
// Geometric primitives
|
// Geometric primitives
|
||||||
#include "omath/triangle.hpp"
|
#include "omath/linear_algebra/triangle.hpp"
|
||||||
#include "omath/view_angles.hpp"
|
#include "omath/trigonometry/view_angles.hpp"
|
||||||
|
|
||||||
// 3D primitives
|
// 3D primitives
|
||||||
#include "omath/3d_primitives/box.hpp"
|
#include "omath/3d_primitives/box.hpp"
|
||||||
|
#include "omath/3d_primitives/plane.hpp"
|
||||||
|
|
||||||
// Collision detection
|
// Collision detection
|
||||||
#include "omath/collision/line_tracer.hpp"
|
#include "omath/collision/line_tracer.hpp"
|
||||||
@@ -81,4 +81,11 @@
|
|||||||
#include "omath/engines/unreal_engine/formulas.hpp"
|
#include "omath/engines/unreal_engine/formulas.hpp"
|
||||||
#include "omath/engines/unreal_engine/camera.hpp"
|
#include "omath/engines/unreal_engine/camera.hpp"
|
||||||
#include "omath/engines/unreal_engine/traits/camera_trait.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"
|
||||||
|
|
||||||
|
// Reverse Engineering
|
||||||
|
#include "omath/rev_eng/external_rev_object.hpp"
|
||||||
|
#include "omath/rev_eng/internal_rev_object.hpp"
|
||||||
|
|
||||||
|
// Utility
|
||||||
|
#include "omath/utility/pattern_scan.hpp"
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
|
||||||
#include "omath/engines/source_engine/traits/pred_engine_trait.hpp"
|
#include "omath/engines/source_engine/traits/pred_engine_trait.hpp"
|
||||||
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include "omath/projectile_prediction/proj_pred_engine.hpp"
|
#include "omath/projectile_prediction/proj_pred_engine.hpp"
|
||||||
#include "omath/projectile_prediction/projectile.hpp"
|
#include "omath/projectile_prediction/projectile.hpp"
|
||||||
#include "omath/projectile_prediction/target.hpp"
|
#include "omath/projectile_prediction/target.hpp"
|
||||||
@@ -20,7 +20,9 @@ namespace omath::projectile_prediction
|
|||||||
Vector3<float> v3, // by-value for calc_viewpoint_from_angles
|
Vector3<float> v3, // by-value for calc_viewpoint_from_angles
|
||||||
float pitch, float yaw, float time, float gravity, std::optional<float> maybe_pitch) {
|
float pitch, float yaw, float time, float gravity, std::optional<float> maybe_pitch) {
|
||||||
// Presence + return types
|
// Presence + return types
|
||||||
{ T::predict_projectile_position(projectile, pitch, yaw, time, gravity) } -> std::same_as<Vector3<float>>;
|
{
|
||||||
|
T::predict_projectile_position(projectile, pitch, yaw, time, gravity)
|
||||||
|
} -> std::same_as<Vector3<float>>;
|
||||||
{ T::predict_target_position(target, time, gravity) } -> std::same_as<Vector3<float>>;
|
{ T::predict_target_position(target, time, gravity) } -> std::same_as<Vector3<float>>;
|
||||||
{ T::calc_vector_2d_distance(vec_a) } -> std::same_as<float>;
|
{ T::calc_vector_2d_distance(vec_a) } -> std::same_as<float>;
|
||||||
{ T::get_vector_height_coordinate(vec_b) } -> std::same_as<float>;
|
{ T::get_vector_height_coordinate(vec_b) } -> std::same_as<float>;
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
#include "omath/linear_algebra/mat.hpp"
|
#include "omath/linear_algebra/mat.hpp"
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include "omath/projection/error_codes.hpp"
|
#include "omath/projection/error_codes.hpp"
|
||||||
|
#include <omath/trigonometry/angle.hpp>
|
||||||
#include <expected>
|
#include <expected>
|
||||||
#include <omath/angle.hpp>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#ifdef OMATH_BUILD_TESTS
|
#ifdef OMATH_BUILD_TESTS
|
||||||
@@ -62,12 +62,13 @@ namespace omath::projection
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
void look_at(const Vector3<float>& target)
|
void look_at(const Vector3<float>& target)
|
||||||
{
|
{
|
||||||
m_view_angles = TraitClass::calc_look_at_angle(m_origin, 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
|
[[nodiscard]] Mat4X4Type calc_view_projection_matrix() const noexcept
|
||||||
{
|
{
|
||||||
return TraitClass::calc_projection_matrix(m_field_of_view, m_view_port, m_near_plane_distance,
|
return TraitClass::calc_projection_matrix(m_field_of_view, m_view_port, m_near_plane_distance,
|
||||||
@@ -195,7 +196,14 @@ namespace omath::projection
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::expected<Vector3<float>, Error> screen_to_world(const Vector3<float>& screen_pos) const noexcept
|
std::expected<Vector3<float>, Error> screen_to_world(const Vector3<float>& screen_pos) const noexcept
|
||||||
{
|
{
|
||||||
return view_port_to_screen(screen_to_dnc(screen_pos));
|
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:
|
protected:
|
||||||
@@ -234,7 +242,7 @@ namespace omath::projection
|
|||||||
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};
|
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_dnc(const Vector3<float>& screen_pos) const noexcept
|
[[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,
|
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};
|
screen_pos.z};
|
||||||
|
|||||||
35
include/omath/rev_eng/external_rev_object.hpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 10/4/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace omath::rev_eng
|
||||||
|
{
|
||||||
|
template<class ExternalMemoryManagementTrait>
|
||||||
|
class ExternalReverseEngineeredObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ExternalReverseEngineeredObject(const std::uintptr_t addr): m_object_address(addr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::uintptr_t m_object_address{};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
template<class Type>
|
||||||
|
[[nodiscard]]
|
||||||
|
Type get_by_offset(const std::ptrdiff_t offset) const
|
||||||
|
{
|
||||||
|
return ExternalMemoryManagementTrait::read_memory(m_object_address+offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void set_by_offset(const std::ptrdiff_t offset, const Type& value) const
|
||||||
|
{
|
||||||
|
return ExternalMemoryManagementTrait::write_memory(m_object_address+offset, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace omath::rev_eng
|
||||||
37
include/omath/rev_eng/internal_rev_object.hpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 8/8/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace omath::rev_eng
|
||||||
|
{
|
||||||
|
class InternalReverseEngineeredObject
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
template<class Type>
|
||||||
|
[[nodiscard]] Type& get_by_offset(const std::ptrdiff_t offset)
|
||||||
|
{
|
||||||
|
return *reinterpret_cast<Type*>(reinterpret_cast<std::uintptr_t>(this) + offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
[[nodiscard]] const Type& get_by_offset(const std::ptrdiff_t offset) const
|
||||||
|
{
|
||||||
|
return *reinterpret_cast<Type*>(reinterpret_cast<std::uintptr_t>(this) + offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t id, class ReturnType>
|
||||||
|
ReturnType call_virtual_method(auto... arg_list)
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
using VirtualMethodType = ReturnType(__thiscall*)(void*, decltype(arg_list)...);
|
||||||
|
#else
|
||||||
|
using VirtualMethodType = ReturnType(*)(void*, decltype(arg_list)...);
|
||||||
|
#endif
|
||||||
|
return (*reinterpret_cast<VirtualMethodType**>(this))[id](this, arg_list...);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace omath::rev_eng
|
||||||
@@ -3,10 +3,10 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "omath/angles.hpp"
|
#include "omath/trigonometry/angles.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
|
||||||
#include <format>
|
#include <format>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
@@ -150,17 +150,62 @@ namespace omath
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
template<class Type, Type min, Type max, omath::AngleFlags flags>
|
|
||||||
struct std::formatter<omath::Angle<Type, min, max, flags>> // NOLINT(*-dcl58-cpp)
|
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)
|
static constexpr auto parse(std::format_parse_context& ctx)
|
||||||
{
|
{
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class FormatContext>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static auto format(const omath::Angle<Type, min, max, flags>& deg, std::format_context& ctx)
|
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>
|
||||||
|
[[nodiscard]]
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// wchar_t formatter
|
||||||
|
template<class T, T MinV, T MaxV, omath::AngleFlags F>
|
||||||
|
struct std::formatter<omath::Angle<T, MinV, MaxV, F>, char8_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>
|
||||||
|
[[nodiscard]]
|
||||||
|
auto format(const AngleT& a, FormatContext& ctx) const
|
||||||
|
{
|
||||||
|
static_assert(std::is_same_v<typename FormatContext::char_type, char8_t>);
|
||||||
|
return std::format_to(ctx.out(), u8"{}deg", a.as_degrees());
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "linear_algebra/vector4.hpp"
|
#include "omath/linear_algebra/vector4.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
@@ -95,7 +95,7 @@ namespace omath
|
|||||||
hsv_data.hue = 0.f;
|
hsv_data.hue = 0.f;
|
||||||
|
|
||||||
else if (max == red)
|
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)
|
else if (max == green)
|
||||||
hsv_data.hue = 60.f * (((blue - red) / delta) + 2.f);
|
hsv_data.hue = 60.f * (((blue - red) / delta) + 2.f);
|
||||||
else if (max == blue)
|
else if (max == blue)
|
||||||
@@ -164,6 +164,26 @@ namespace omath
|
|||||||
return {to_im_vec4()};
|
return {to_im_vec4()};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
[[nodiscard]] std::string to_string() const noexcept
|
||||||
|
{
|
||||||
|
return std::format("[r:{}, g:{}, b:{}, a:{}]",
|
||||||
|
static_cast<int>(x * 255.f),
|
||||||
|
static_cast<int>(y * 255.f),
|
||||||
|
static_cast<int>(z * 255.f),
|
||||||
|
static_cast<int>(w * 255.f));
|
||||||
|
}
|
||||||
|
[[nodiscard]] std::wstring to_wstring() const noexcept
|
||||||
|
{
|
||||||
|
const auto ascii_string = to_string();
|
||||||
|
return {ascii_string.cbegin(), ascii_string.cend()};
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReSharper disable once CppInconsistentNaming
|
||||||
|
[[nodiscard]] std::u8string to_u8string() const noexcept
|
||||||
|
{
|
||||||
|
const auto ascii_string = to_string();
|
||||||
|
return {ascii_string.cbegin(), ascii_string.cend()};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
template<>
|
template<>
|
||||||
@@ -174,13 +194,19 @@ struct std::formatter<omath::Color> // NOLINT(*-dcl58-cpp)
|
|||||||
{
|
{
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class FormatContext>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static auto format(const omath::Color& col, std::format_context& ctx)
|
static auto format(const omath::Color& col, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
return std::format_to(ctx.out(), "[r:{}, g:{}, b:{}, a:{}]",
|
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||||
static_cast<int>(col.x * 255.f),
|
return std::format_to(ctx.out(), "{}", col.to_string());
|
||||||
static_cast<int>(col.y * 255.f),
|
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
|
||||||
static_cast<int>(col.z * 255.f),
|
return std::format_to(ctx.out(), L"{}", col.to_wstring());
|
||||||
static_cast<int>(col.w * 255.f));
|
|
||||||
|
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
|
||||||
|
return std::format_to(ctx.out(), u8"{}", col.to_u8string());
|
||||||
|
|
||||||
|
return std::unreachable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
82
include/omath/utility/pattern_scan.hpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 10/4/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <expected>
|
||||||
|
#include <optional>
|
||||||
|
#include <span>
|
||||||
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// ReSharper disable once CppInconsistentNaming
|
||||||
|
class unit_test_pattern_scan_read_test_Test;
|
||||||
|
// ReSharper disable once CppInconsistentNaming
|
||||||
|
class unit_test_pattern_scan_corner_case_1_Test;
|
||||||
|
// ReSharper disable once CppInconsistentNaming
|
||||||
|
class unit_test_pattern_scan_corner_case_2_Test;
|
||||||
|
// ReSharper disable once CppInconsistentNaming
|
||||||
|
class unit_test_pattern_scan_corner_case_3_Test;
|
||||||
|
// ReSharper disable once CppInconsistentNaming
|
||||||
|
class unit_test_pattern_scan_corner_case_4_Test;
|
||||||
|
|
||||||
|
namespace omath
|
||||||
|
{
|
||||||
|
enum class PatternScanError
|
||||||
|
{
|
||||||
|
INVALID_PATTERN_STRING
|
||||||
|
};
|
||||||
|
class PatternScanner final
|
||||||
|
{
|
||||||
|
friend unit_test_pattern_scan_read_test_Test;
|
||||||
|
friend unit_test_pattern_scan_corner_case_1_Test;
|
||||||
|
friend unit_test_pattern_scan_corner_case_2_Test;
|
||||||
|
friend unit_test_pattern_scan_corner_case_3_Test;
|
||||||
|
friend unit_test_pattern_scan_corner_case_4_Test;
|
||||||
|
|
||||||
|
public:
|
||||||
|
[[nodiscard]]
|
||||||
|
static std::span<std::byte>::iterator scan_for_pattern(const std::span<std::byte>& range,
|
||||||
|
const std::string_view& pattern);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
static std::span<std::byte>::iterator scan_for_pattern(std::span<std::byte>&& range,
|
||||||
|
const std::string_view& pattern) = delete;
|
||||||
|
|
||||||
|
template<class IteratorType>
|
||||||
|
requires std::input_or_output_iterator<std::remove_cvref_t<IteratorType>>
|
||||||
|
static IteratorType scan_for_pattern(const IteratorType& begin, const IteratorType& end,
|
||||||
|
const std::string_view& pattern)
|
||||||
|
{
|
||||||
|
const auto parsed_pattern = parse_pattern(pattern);
|
||||||
|
|
||||||
|
if (!parsed_pattern) [[unlikely]]
|
||||||
|
return end;
|
||||||
|
|
||||||
|
const auto whole_range_size = static_cast<std::ptrdiff_t>(std::distance(begin, end));
|
||||||
|
|
||||||
|
const std::ptrdiff_t scan_size = whole_range_size - static_cast<std::ptrdiff_t>(pattern.size());
|
||||||
|
|
||||||
|
for (std::ptrdiff_t i = 0; i < scan_size; i++)
|
||||||
|
{
|
||||||
|
bool found = true;
|
||||||
|
|
||||||
|
for (std::ptrdiff_t j = 0; j < static_cast<std::ptrdiff_t>(parsed_pattern->size()); j++)
|
||||||
|
{
|
||||||
|
found = parsed_pattern->at(j) == std::nullopt || parsed_pattern->at(j) == *(begin + i + j);
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (found)
|
||||||
|
return begin + i;
|
||||||
|
}
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
[[nodiscard]]
|
||||||
|
static std::expected<std::vector<std::optional<std::byte>>, PatternScanError>
|
||||||
|
parse_pattern(const std::string_view& pattern_string);
|
||||||
|
};
|
||||||
|
} // namespace omath
|
||||||
30
include/omath/utility/pe_pattern_scan.hpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 10/7/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <optional>
|
||||||
|
#include <string_view>
|
||||||
|
namespace omath
|
||||||
|
{
|
||||||
|
struct PeSectionScanResult
|
||||||
|
{
|
||||||
|
std::uint64_t virtual_base_addr;
|
||||||
|
std::uint64_t raw_base_addr;
|
||||||
|
std::ptrdiff_t target_offset;
|
||||||
|
};
|
||||||
|
class PePatternScanner final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
[[nodiscard]]
|
||||||
|
static std::optional<std::uintptr_t> scan_for_pattern_in_loaded_module(const void* module_base_address,
|
||||||
|
const std::string_view& pattern);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
static std::optional<PeSectionScanResult>
|
||||||
|
scan_for_pattern_in_file(const std::filesystem::path& path_to_file, const std::string_view& pattern,
|
||||||
|
const std::string_view& target_section_name = ".text");
|
||||||
|
};
|
||||||
|
} // namespace omath
|
||||||
1
mkdocs.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
site_name: My Docs
|
||||||
@@ -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
|
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 direction = (look_at - cam_origin).normalized();
|
||||||
const auto delta = cam_origin - look_at;
|
|
||||||
|
|
||||||
return {PitchAngle::from_radians(-std::asin(delta.z / distance)),
|
return {PitchAngle::from_radians(-std::asin(direction.z)),
|
||||||
YawAngle::from_radians(std::atan2(delta.y, delta.x)), RollAngle::from_radians(0.f)};
|
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
|
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
|
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),
|
return mat_look_at_right_handed(cam_origin, cam_origin+forward_vector(angles), up_vector(angles));
|
||||||
up_vector(angles), cam_origin);
|
|
||||||
}
|
}
|
||||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
return mat_rotation_axis_x<float, MatStoreType::COLUMN_MAJOR>(-angles.pitch)
|
return mat_rotation_axis_z<float, MatStoreType::COLUMN_MAJOR>(angles.roll)
|
||||||
* mat_rotation_axis_y<float, MatStoreType::COLUMN_MAJOR>(-angles.yaw)
|
* mat_rotation_axis_y<float, MatStoreType::COLUMN_MAJOR>(angles.yaw)
|
||||||
* mat_rotation_axis_z<float, MatStoreType::COLUMN_MAJOR>(angles.roll);
|
* 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,
|
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||||
const float far) noexcept
|
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
|
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 direction = (look_at - cam_origin).normalized();
|
||||||
const auto delta = cam_origin - look_at;
|
|
||||||
|
|
||||||
return {PitchAngle::from_radians(-std::asin(delta.y / distance)),
|
return {PitchAngle::from_radians(std::asin(direction.y)),
|
||||||
YawAngle::from_radians(std::atan2(delta.z, delta.x)), RollAngle::from_radians(0.f)};
|
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
|
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
|
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 direction = (look_at - cam_origin).normalized();
|
||||||
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)};
|
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
|
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
|
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_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,
|
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||||
const float far) noexcept
|
const float far) noexcept
|
||||||
|
|||||||
@@ -8,11 +8,10 @@ namespace omath::unity_engine
|
|||||||
|
|
||||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
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 direction = (look_at - cam_origin).normalized();
|
||||||
const auto delta = cam_origin - look_at;
|
|
||||||
|
|
||||||
return {PitchAngle::from_radians(-std::asin(delta.y / distance)),
|
return {PitchAngle::from_radians(-std::asin(direction.y)),
|
||||||
YawAngle::from_radians(std::atan2(delta.z, delta.x)), RollAngle::from_radians(0.f)};
|
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
|
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
|
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
return mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.roll)
|
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,
|
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||||
const float far) noexcept
|
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
|
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 direction = (look_at - cam_origin).normalized();
|
||||||
const auto delta = cam_origin - look_at;
|
|
||||||
|
|
||||||
return {PitchAngle::from_radians(-std::asin(delta.z / distance)),
|
return {PitchAngle::from_radians(-std::asin(direction.z)),
|
||||||
YawAngle::from_radians(std::atan2(delta.x, delta.y)), RollAngle::from_radians(0.f)};
|
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
|
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||||
{
|
{
|
||||||
|
|||||||
75
source/utility/pattern_scan.cpp
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 10/4/2025.
|
||||||
|
//
|
||||||
|
#include "omath/utility/pattern_scan.hpp"
|
||||||
|
#include <charconv>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr bool is_wildcard(const std::string_view& byte_str)
|
||||||
|
{
|
||||||
|
return byte_str == "?" || byte_str == "??";
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr bool invalid_byte_str_size(const std::string_view& byte_str)
|
||||||
|
{
|
||||||
|
return byte_str.empty() || byte_str.size() >= 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace omath
|
||||||
|
{
|
||||||
|
|
||||||
|
std::span<std::byte>::iterator
|
||||||
|
PatternScanner::scan_for_pattern(const std::span<std::byte>& range, const std::string_view& pattern)
|
||||||
|
{
|
||||||
|
return scan_for_pattern(range.begin(), range.end(), pattern);
|
||||||
|
}
|
||||||
|
std::expected<std::vector<std::optional<std::byte>>, PatternScanError>
|
||||||
|
PatternScanner::parse_pattern(const std::string_view& pattern_string)
|
||||||
|
{
|
||||||
|
std::vector<std::optional<std::byte>> pattern;
|
||||||
|
|
||||||
|
auto start = pattern_string.cbegin();
|
||||||
|
|
||||||
|
while (start != pattern_string.cend())
|
||||||
|
{
|
||||||
|
const auto end = std::ranges::find(start, pattern_string.cend(), ' ');
|
||||||
|
|
||||||
|
const auto sting_view_start = std::distance(pattern_string.cbegin(), start);
|
||||||
|
const auto sting_view_end = std::distance(start, end);
|
||||||
|
|
||||||
|
const std::string_view byte_str = pattern_string.substr(sting_view_start, sting_view_end);
|
||||||
|
|
||||||
|
if (invalid_byte_str_size(byte_str)) [[unlikely]]
|
||||||
|
{
|
||||||
|
start = end != pattern_string.end() ? std::next(end) : end;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_wildcard(byte_str))
|
||||||
|
{
|
||||||
|
pattern.emplace_back(std::nullopt);
|
||||||
|
|
||||||
|
start = end != pattern_string.end() ? std::next(end) : end;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uint8_t value = 0;
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto [_, error_code] = std::from_chars(byte_str.data(), byte_str.data() + byte_str.size(), value, 16);
|
||||||
|
|
||||||
|
if (error_code != std::errc{}) [[unlikely]]
|
||||||
|
return std::unexpected(PatternScanError::INVALID_PATTERN_STRING);
|
||||||
|
|
||||||
|
pattern.emplace_back(static_cast<std::byte>(value));
|
||||||
|
|
||||||
|
start = end != pattern_string.end() ? std::next(end) : end;
|
||||||
|
}
|
||||||
|
return pattern;
|
||||||
|
}
|
||||||
|
} // namespace omath
|
||||||
359
source/utility/pe_pattern_scan.cpp
Normal file
@@ -0,0 +1,359 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 10/7/2025.
|
||||||
|
//
|
||||||
|
#include "omath/utility/pe_pattern_scan.hpp"
|
||||||
|
#include "omath/utility/pattern_scan.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
#include <span>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
// Internal PE shit defines
|
||||||
|
// Big thx for linuxpe sources as ref
|
||||||
|
// Link: https://github.com/can1357/linux-pe
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr std::uint16_t opt_hdr32_magic = 0x010B;
|
||||||
|
constexpr std::uint16_t opt_hdr64_magic = 0x020B;
|
||||||
|
|
||||||
|
// Standard fields.
|
||||||
|
// ReSharper disable CppDeclaratorNeverUsed
|
||||||
|
struct DataDirectory final
|
||||||
|
{
|
||||||
|
std::uint32_t rva;
|
||||||
|
std::uint32_t size;
|
||||||
|
};
|
||||||
|
struct OptionalHeaderX64 final
|
||||||
|
{
|
||||||
|
std::uint16_t magic;
|
||||||
|
|
||||||
|
std::uint16_t linker_version;
|
||||||
|
|
||||||
|
std::uint32_t size_code;
|
||||||
|
std::uint32_t size_init_data;
|
||||||
|
std::uint32_t size_uninit_data;
|
||||||
|
|
||||||
|
std::uint32_t entry_point;
|
||||||
|
std::uint32_t base_of_code;
|
||||||
|
|
||||||
|
// NT additional fields.
|
||||||
|
std::uint64_t image_base;
|
||||||
|
std::uint32_t section_alignment;
|
||||||
|
std::uint32_t file_alignment;
|
||||||
|
|
||||||
|
std::uint32_t os_version;
|
||||||
|
std::uint32_t img_version;
|
||||||
|
std::uint32_t subsystem_version;
|
||||||
|
std::uint32_t win32_version_value;
|
||||||
|
|
||||||
|
std::uint32_t size_image;
|
||||||
|
std::uint32_t size_headers;
|
||||||
|
|
||||||
|
std::uint32_t checksum;
|
||||||
|
std::uint16_t subsystem;
|
||||||
|
std::uint16_t characteristics;
|
||||||
|
|
||||||
|
std::uint64_t size_stack_reserve;
|
||||||
|
std::uint64_t size_stack_commit;
|
||||||
|
std::uint64_t size_heap_reserve;
|
||||||
|
std::uint64_t size_heap_commit;
|
||||||
|
|
||||||
|
std::uint32_t ldr_flags;
|
||||||
|
|
||||||
|
std::uint32_t num_data_directories;
|
||||||
|
DataDirectory data_directories[16];
|
||||||
|
};
|
||||||
|
struct OptionalHeaderX86 final
|
||||||
|
{
|
||||||
|
// Standard fields.
|
||||||
|
std::uint16_t magic{};
|
||||||
|
std::uint16_t linker_version{};
|
||||||
|
|
||||||
|
std::uint32_t size_code{};
|
||||||
|
std::uint32_t size_init_data{};
|
||||||
|
std::uint32_t size_uninit_data{};
|
||||||
|
|
||||||
|
std::uint32_t entry_point{};
|
||||||
|
std::uint32_t base_of_code{};
|
||||||
|
std::uint32_t base_of_data{};
|
||||||
|
|
||||||
|
// NT additional fields.
|
||||||
|
std::uint32_t image_base{};
|
||||||
|
std::uint32_t section_alignment{};
|
||||||
|
std::uint32_t file_alignment{};
|
||||||
|
|
||||||
|
std::uint32_t os_version{};
|
||||||
|
std::uint32_t img_version{};
|
||||||
|
std::uint32_t subsystem_version{};
|
||||||
|
std::uint32_t win32_version_value{};
|
||||||
|
|
||||||
|
std::uint32_t size_image{};
|
||||||
|
std::uint32_t size_headers{};
|
||||||
|
|
||||||
|
std::uint32_t checksum{};
|
||||||
|
std::uint16_t subsystem{};
|
||||||
|
std::uint16_t characteristics{};
|
||||||
|
|
||||||
|
std::uint32_t size_stack_reserve{};
|
||||||
|
std::uint32_t size_stack_commit{};
|
||||||
|
std::uint32_t size_heap_reserve{};
|
||||||
|
std::uint32_t size_heap_commit{};
|
||||||
|
|
||||||
|
std::uint32_t ldr_flags{};
|
||||||
|
|
||||||
|
std::uint32_t num_data_directories{};
|
||||||
|
DataDirectory data_directories[16]{};
|
||||||
|
};
|
||||||
|
template<bool x64 = true>
|
||||||
|
using OptionalHeader = std::conditional_t<x64, OptionalHeaderX64, OptionalHeaderX86>;
|
||||||
|
|
||||||
|
struct FileHeader final
|
||||||
|
{
|
||||||
|
std::uint16_t machine;
|
||||||
|
std::uint16_t num_sections;
|
||||||
|
std::uint32_t timedate_stamp;
|
||||||
|
std::uint32_t ptr_symbols;
|
||||||
|
std::uint32_t num_symbols;
|
||||||
|
std::uint16_t size_optional_header;
|
||||||
|
std::uint16_t characteristics;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DosHeader final
|
||||||
|
{
|
||||||
|
std::uint16_t e_magic;
|
||||||
|
std::uint16_t e_cblp;
|
||||||
|
std::uint16_t e_cp;
|
||||||
|
std::uint16_t e_crlc;
|
||||||
|
std::uint16_t e_cparhdr;
|
||||||
|
std::uint16_t e_minalloc;
|
||||||
|
std::uint16_t e_maxalloc;
|
||||||
|
std::uint16_t e_ss;
|
||||||
|
std::uint16_t e_sp;
|
||||||
|
std::uint16_t e_csum;
|
||||||
|
std::uint16_t e_ip;
|
||||||
|
std::uint16_t e_cs;
|
||||||
|
std::uint16_t e_lfarlc;
|
||||||
|
std::uint16_t e_ovno;
|
||||||
|
std::uint16_t e_res[4];
|
||||||
|
std::uint16_t e_oemid;
|
||||||
|
std::uint16_t e_oeminfo;
|
||||||
|
std::uint16_t e_res2[10];
|
||||||
|
std::uint32_t e_lfanew;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class NtArchitecture
|
||||||
|
{
|
||||||
|
x32_bit,
|
||||||
|
x64_bit,
|
||||||
|
};
|
||||||
|
template<NtArchitecture architecture>
|
||||||
|
struct ImageNtHeaders final
|
||||||
|
{
|
||||||
|
std::uint32_t signature;
|
||||||
|
FileHeader file_header;
|
||||||
|
OptionalHeader<architecture == NtArchitecture::x64_bit> optional_header;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SectionHeader final
|
||||||
|
{
|
||||||
|
char name[8];
|
||||||
|
union
|
||||||
|
{
|
||||||
|
std::uint32_t physical_address;
|
||||||
|
std::uint32_t virtual_size;
|
||||||
|
};
|
||||||
|
std::uint32_t virtual_address;
|
||||||
|
|
||||||
|
std::uint32_t size_raw_data;
|
||||||
|
std::uint32_t ptr_raw_data;
|
||||||
|
|
||||||
|
std::uint32_t ptr_relocs;
|
||||||
|
std::uint32_t ptr_line_numbers;
|
||||||
|
std::uint32_t num_relocs;
|
||||||
|
std::uint32_t num_line_numbers;
|
||||||
|
|
||||||
|
std::uint32_t characteristics;
|
||||||
|
};
|
||||||
|
// ReSharper restore CppDeclaratorNeverUsed
|
||||||
|
|
||||||
|
using NtHeaderVariant =
|
||||||
|
std::variant<ImageNtHeaders<NtArchitecture::x64_bit>, ImageNtHeaders<NtArchitecture::x32_bit>>;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// Internal PE scanner functions
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
std::optional<NtHeaderVariant> get_nt_header_from_file(std::fstream& file, const DosHeader& dos_header)
|
||||||
|
{
|
||||||
|
ImageNtHeaders<NtArchitecture::x32_bit> x86_headers{};
|
||||||
|
file.seekg(dos_header.e_lfanew, std::ios::beg);
|
||||||
|
file.read(reinterpret_cast<char*>(&x86_headers), sizeof(x86_headers));
|
||||||
|
|
||||||
|
if (x86_headers.optional_header.magic == opt_hdr32_magic)
|
||||||
|
return x86_headers;
|
||||||
|
|
||||||
|
if (x86_headers.optional_header.magic != opt_hdr64_magic)
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
ImageNtHeaders<NtArchitecture::x64_bit> x64_headers{};
|
||||||
|
file.seekg(dos_header.e_lfanew, std::ios::beg);
|
||||||
|
file.read(reinterpret_cast<char*>(&x64_headers), sizeof(x64_headers));
|
||||||
|
|
||||||
|
return x64_headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
std::optional<NtHeaderVariant> get_nt_header_from_loaded_module(const void* module_base_address)
|
||||||
|
{
|
||||||
|
const auto module_byte_ptr = static_cast<const std::byte*>(module_base_address);
|
||||||
|
ImageNtHeaders<NtArchitecture::x32_bit> x86_headers{};
|
||||||
|
const auto dos_header = static_cast<const DosHeader*>(module_base_address);
|
||||||
|
|
||||||
|
x86_headers = *reinterpret_cast<const ImageNtHeaders<NtArchitecture::x32_bit>*>(module_byte_ptr
|
||||||
|
+ dos_header->e_lfanew);
|
||||||
|
|
||||||
|
if (x86_headers.optional_header.magic == opt_hdr32_magic)
|
||||||
|
return x86_headers;
|
||||||
|
|
||||||
|
if (x86_headers.optional_header.magic != opt_hdr64_magic)
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
return *reinterpret_cast<const ImageNtHeaders<NtArchitecture::x64_bit>*>(module_byte_ptr
|
||||||
|
+ dos_header->e_lfanew);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr bool invalid_dos_header_file(const DosHeader& dos_header)
|
||||||
|
{
|
||||||
|
constexpr std::uint16_t dos_hdr_magic = 0x5A4D;
|
||||||
|
return dos_header.e_magic != dos_hdr_magic;
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr bool invalid_nt_header_file(const NtHeaderVariant& variant)
|
||||||
|
{
|
||||||
|
constexpr std::uint32_t nt_hdr_magic = 0x4550;
|
||||||
|
return std::visit([](const auto& header) -> bool { return header.signature != nt_hdr_magic; }, variant);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ExtractedSection
|
||||||
|
{
|
||||||
|
std::uint64_t virtual_base_addr;
|
||||||
|
std::uint64_t raw_base_addr;
|
||||||
|
std::vector<std::byte> data;
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
std::optional<ExtractedSection> extract_section_from_pe_file(const std::filesystem::path& path_to_file,
|
||||||
|
const std::string_view& section_name)
|
||||||
|
{
|
||||||
|
std::fstream file(path_to_file, std::ios::binary | std::ios::in);
|
||||||
|
|
||||||
|
if (!file.is_open()) [[unlikely]]
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
DosHeader dos_header{};
|
||||||
|
file.read(reinterpret_cast<char*>(&dos_header), sizeof(dos_header));
|
||||||
|
|
||||||
|
if (invalid_dos_header_file(dos_header)) [[unlikely]]
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
const auto nt_headers = get_nt_header_from_file(file, dos_header);
|
||||||
|
|
||||||
|
if (!nt_headers)
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
if (invalid_nt_header_file(nt_headers.value())) [[unlikely]]
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
return std::visit(
|
||||||
|
[&file, &dos_header, §ion_name](auto& concrete_headers) -> std::optional<ExtractedSection>
|
||||||
|
{
|
||||||
|
constexpr std::size_t size_of_signature = sizeof(concrete_headers.signature);
|
||||||
|
const auto offset_to_segment_table = dos_header.e_lfanew
|
||||||
|
+ concrete_headers.file_header.size_optional_header
|
||||||
|
+ sizeof(FileHeader) + size_of_signature;
|
||||||
|
|
||||||
|
file.seekg(static_cast<std::fstream::off_type>(offset_to_segment_table), std::ios::beg);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < concrete_headers.file_header.num_sections; i++)
|
||||||
|
{
|
||||||
|
SectionHeader current_section{};
|
||||||
|
file.read(reinterpret_cast<char*>(¤t_section), sizeof(current_section));
|
||||||
|
|
||||||
|
if (std::string_view(current_section.name) != section_name)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::vector<std::byte> section_data(current_section.size_raw_data);
|
||||||
|
|
||||||
|
file.seekg(current_section.ptr_raw_data, std::ios::beg);
|
||||||
|
file.read(reinterpret_cast<char*>(section_data.data()),
|
||||||
|
static_cast<std::streamsize>(section_data.size()));
|
||||||
|
return ExtractedSection{.virtual_base_addr = current_section.virtual_address
|
||||||
|
+ concrete_headers.optional_header.image_base,
|
||||||
|
.raw_base_addr = current_section.ptr_raw_data,
|
||||||
|
.data = std::move(section_data)};
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
},
|
||||||
|
nt_headers.value());
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace omath
|
||||||
|
{
|
||||||
|
|
||||||
|
std::optional<std::uintptr_t> PePatternScanner::scan_for_pattern_in_loaded_module(const void* module_base_address,
|
||||||
|
const std::string_view& pattern)
|
||||||
|
{
|
||||||
|
const auto base_address = reinterpret_cast<std::uintptr_t>(module_base_address);
|
||||||
|
|
||||||
|
if (!base_address)
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
auto nt_header_variant = get_nt_header_from_loaded_module(module_base_address);
|
||||||
|
|
||||||
|
if (!nt_header_variant)
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
return std::visit(
|
||||||
|
[base_address, &pattern](const auto& nt_header) -> std::optional<std::uintptr_t>
|
||||||
|
{
|
||||||
|
// Define .code segment as scan area
|
||||||
|
const auto start = nt_header.optional_header.base_of_code;
|
||||||
|
const auto scan_size = nt_header.optional_header.size_code;
|
||||||
|
|
||||||
|
const auto scan_range = std::span{reinterpret_cast<std::byte*>(base_address) + start, scan_size};
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto result = PatternScanner::scan_for_pattern(scan_range, pattern);
|
||||||
|
|
||||||
|
if (result != scan_range.cend())
|
||||||
|
return reinterpret_cast<std::uintptr_t>(&*result);
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
},
|
||||||
|
nt_header_variant.value());
|
||||||
|
}
|
||||||
|
std::optional<PeSectionScanResult>
|
||||||
|
PePatternScanner::scan_for_pattern_in_file(const std::filesystem::path& path_to_file,
|
||||||
|
const std::string_view& pattern,
|
||||||
|
const std::string_view& target_section_name)
|
||||||
|
{
|
||||||
|
const auto pe_section = extract_section_from_pe_file(path_to_file, target_section_name);
|
||||||
|
|
||||||
|
if (!pe_section.has_value())
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
const auto scan_result =
|
||||||
|
PatternScanner::scan_for_pattern(pe_section->data.cbegin(), pe_section->data.cend(), pattern);
|
||||||
|
|
||||||
|
if (scan_result == pe_section->data.cend())
|
||||||
|
return std::nullopt;
|
||||||
|
const auto offset = std::distance(pe_section->data.begin(), scan_result);
|
||||||
|
|
||||||
|
return PeSectionScanResult{.virtual_base_addr = pe_section->virtual_base_addr,
|
||||||
|
.raw_base_addr = pe_section->raw_base_addr,
|
||||||
|
.target_offset = offset};
|
||||||
|
}
|
||||||
|
} // namespace omath
|
||||||
@@ -7,16 +7,13 @@ include(GoogleTest)
|
|||||||
file(GLOB_RECURSE UNIT_TESTS_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
file(GLOB_RECURSE UNIT_TESTS_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||||
add_executable(${PROJECT_NAME} ${UNIT_TESTS_SOURCES})
|
add_executable(${PROJECT_NAME} ${UNIT_TESTS_SOURCES})
|
||||||
|
|
||||||
set_target_properties(unit_tests PROPERTIES
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
LIBRARY_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}"
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
UNITY_BUILD ON
|
|
||||||
UNITY_BUILD_BATCH_SIZE 20
|
|
||||||
CXX_STANDARD 23
|
CXX_STANDARD 23
|
||||||
CXX_STANDARD_REQUIRED ON)
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE gtest gtest_main omath::omath)
|
target_link_libraries(${PROJECT_NAME} PRIVATE gtest gtest_main omath::omath)
|
||||||
|
|
||||||
gtest_discover_tests(${PROJECT_NAME})
|
gtest_discover_tests(${PROJECT_NAME})
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <omath/engines/iw_engine/camera.hpp>
|
#include <omath/engines/iw_engine/camera.hpp>
|
||||||
#include <omath/engines/iw_engine/constants.hpp>
|
#include <omath/engines/iw_engine/constants.hpp>
|
||||||
#include <omath/engines/iw_engine/formulas.hpp>
|
#include <omath/engines/iw_engine/formulas.hpp>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
TEST(unit_test_iw_engine, ForwardVector)
|
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);
|
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);
|
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)
|
for (float distance = 0.02f; distance < 1000.f; distance += 0.01f)
|
||||||
{
|
{
|
||||||
const auto projected = cam.world_to_screen({distance, 0, 0});
|
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));
|
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||||
|
|
||||||
EXPECT_EQ(cam.get_field_of_view().as_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/camera.hpp>
|
||||||
#include <omath/engines/opengl_engine/constants.hpp>
|
#include <omath/engines/opengl_engine/constants.hpp>
|
||||||
#include <omath/engines/opengl_engine/formulas.hpp>
|
#include <omath/engines/opengl_engine/formulas.hpp>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
TEST(unit_test_opengl, ForwardVector)
|
TEST(unit_test_opengl, ForwardVector)
|
||||||
{
|
{
|
||||||
@@ -29,7 +29,7 @@ TEST(unit_test_opengl, ForwardVectorRotationYaw)
|
|||||||
{
|
{
|
||||||
omath::opengl_engine::ViewAngles angles;
|
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);
|
const auto forward = omath::opengl_engine::forward_vector(angles);
|
||||||
EXPECT_NEAR(forward.x, omath::opengl_engine::k_abs_right.x, 0.00001f);
|
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);
|
EXPECT_NEAR(forward.z, omath::opengl_engine::k_abs_right.z, 0.00001f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST(unit_test_opengl, ForwardVectorRotationPitch)
|
TEST(unit_test_opengl, ForwardVectorRotationPitch)
|
||||||
{
|
{
|
||||||
omath::opengl_engine::ViewAngles angles;
|
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);
|
const auto forward = omath::opengl_engine::forward_vector(angles);
|
||||||
EXPECT_NEAR(forward.x, omath::opengl_engine::k_abs_up.x, 0.00001f);
|
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);
|
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);
|
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)
|
for (float distance = -10.f; distance > -1000.f; distance -= 0.01f)
|
||||||
{
|
{
|
||||||
const auto projected = cam.world_to_screen({0, 0, distance});
|
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));
|
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||||
|
|
||||||
EXPECT_EQ(cam.get_field_of_view().as_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/camera.hpp>
|
||||||
#include <omath/engines/source_engine/constants.hpp>
|
#include <omath/engines/source_engine/constants.hpp>
|
||||||
#include <omath/engines/source_engine/formulas.hpp>
|
#include <omath/engines/source_engine/formulas.hpp>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
TEST(unit_test_source_engine, ForwardVector)
|
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);
|
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);
|
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)
|
for (float distance = 0.02f; distance < 1000.f; distance += 0.01f)
|
||||||
{
|
{
|
||||||
const auto projected = cam.world_to_screen({distance, 0, 0});
|
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));
|
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||||
|
|
||||||
EXPECT_EQ(cam.get_field_of_view().as_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/constants.hpp>
|
||||||
#include <omath/engines/unity_engine/formulas.hpp>
|
#include <omath/engines/unity_engine/formulas.hpp>
|
||||||
#include <print>
|
#include <print>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
TEST(unit_test_unity_engine, ForwardVector)
|
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);
|
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);
|
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)
|
for (float distance = 0.02f; distance < 100.f; distance += 0.01f)
|
||||||
{
|
{
|
||||||
const auto projected = cam.world_to_screen({0, 0, distance});
|
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));
|
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||||
|
|
||||||
EXPECT_EQ(cam.get_field_of_view().as_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/constants.hpp>
|
||||||
#include <omath/engines/unreal_engine/formulas.hpp>
|
#include <omath/engines/unreal_engine/formulas.hpp>
|
||||||
#include <print>
|
#include <print>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
TEST(unit_test_unreal_engine, ForwardVector)
|
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);
|
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);
|
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)
|
for (float distance = 0.02f; distance < 100.f; distance += 0.01f)
|
||||||
{
|
{
|
||||||
const auto projected = cam.world_to_screen({distance, 0, 0});
|
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));
|
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||||
|
|
||||||
EXPECT_EQ(cam.get_field_of_view().as_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);
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
// Created by Orange on 11/30/2024.
|
// Created by Orange on 11/30/2024.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <omath/trigonometry/angle.hpp>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
#include <omath/angle.hpp>
|
|
||||||
|
|
||||||
using namespace omath;
|
using namespace omath;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
//
|
//
|
||||||
// Created by Orange on 11/30/2024.
|
// Created by Orange on 11/30/2024.
|
||||||
//
|
//
|
||||||
|
#include <omath/trigonometry/angles.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <omath/angles.hpp>
|
|
||||||
|
|
||||||
TEST(unit_test_angles, radians_to_deg)
|
TEST(unit_test_angles, radians_to_deg)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
//
|
//
|
||||||
// Created by Vlad on 01.09.2024.
|
// Created by Vlad on 01.09.2024.
|
||||||
//
|
//
|
||||||
|
#include <omath/utility/color.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <omath/color.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace omath;
|
using namespace omath;
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
// Revised unit‑test suite for LineTracer (segment‑based Möller–Trumbore)
|
// Revised unit‑test suite for LineTracer (segment‑based Möller–Trumbore)
|
||||||
// Pure ASCII: avoids non‑standard characters that MSVC rejects.
|
// Pure ASCII: avoids non‑standard characters that MSVC rejects.
|
||||||
//
|
//
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/triangle.hpp"
|
||||||
#include "omath/collision/line_tracer.hpp"
|
#include "omath/collision/line_tracer.hpp"
|
||||||
#include "omath/triangle.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
|||||||
53
tests/general/unit_test_pattern_scan.cpp
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 10/4/2025.
|
||||||
|
//
|
||||||
|
#include "omath/utility/pe_pattern_scan.hpp"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include <omath/utility/pattern_scan.hpp>
|
||||||
|
#include <source_location>
|
||||||
|
#include <print>
|
||||||
|
TEST(unit_test_pattern_scan, read_test)
|
||||||
|
{
|
||||||
|
const auto result = omath::PatternScanner::parse_pattern("FF ? ?? E9");
|
||||||
|
|
||||||
|
EXPECT_EQ(result->at(0), static_cast<std::byte>(0xFF));
|
||||||
|
EXPECT_EQ(result->at(1), std::nullopt);
|
||||||
|
EXPECT_EQ(result->at(2), std::nullopt);
|
||||||
|
EXPECT_EQ(result->at(3), static_cast<std::byte>(0xE9));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_pattern_scan, corner_case_1)
|
||||||
|
{
|
||||||
|
const auto result = omath::PatternScanner::parse_pattern(" FF ? ?? E9");
|
||||||
|
|
||||||
|
EXPECT_EQ(result->at(0), static_cast<std::byte>(0xFF));
|
||||||
|
EXPECT_EQ(result->at(1), std::nullopt);
|
||||||
|
EXPECT_EQ(result->at(2), std::nullopt);
|
||||||
|
EXPECT_EQ(result->at(3), static_cast<std::byte>(0xE9));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_pattern_scan, corner_case_2)
|
||||||
|
{
|
||||||
|
const auto result = omath::PatternScanner::parse_pattern(" FF ? ?? E9 ");
|
||||||
|
|
||||||
|
EXPECT_EQ(result->at(0), static_cast<std::byte>(0xFF));
|
||||||
|
EXPECT_EQ(result->at(1), std::nullopt);
|
||||||
|
EXPECT_EQ(result->at(2), std::nullopt);
|
||||||
|
EXPECT_EQ(result->at(3), static_cast<std::byte>(0xE9));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_pattern_scan, corner_case_3)
|
||||||
|
{
|
||||||
|
const auto result = omath::PatternScanner::parse_pattern(" FF ? ?? E9 ");
|
||||||
|
|
||||||
|
EXPECT_EQ(result->at(0), static_cast<std::byte>(0xFF));
|
||||||
|
EXPECT_EQ(result->at(1), std::nullopt);
|
||||||
|
EXPECT_EQ(result->at(2), std::nullopt);
|
||||||
|
EXPECT_EQ(result->at(3), static_cast<std::byte>(0xE9));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_pattern_scan, corner_case_4)
|
||||||
|
{
|
||||||
|
const auto result = omath::PatternScanner::parse_pattern("X ? ?? E9 ");
|
||||||
|
EXPECT_FALSE(result.has_value());
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <omath/projectile_prediction/proj_pred_engine_legacy.hpp>
|
#include <omath/projectile_prediction/proj_pred_engine_legacy.hpp>
|
||||||
|
#include <omath/engines/source_engine/traits/camera_trait.hpp>
|
||||||
TEST(UnitTestPrediction, PredictionTest)
|
TEST(UnitTestPrediction, PredictionTest)
|
||||||
{
|
{
|
||||||
constexpr omath::projectile_prediction::Target target{
|
constexpr omath::projectile_prediction::Target target{
|
||||||
@@ -10,8 +10,9 @@ TEST(UnitTestPrediction, PredictionTest)
|
|||||||
const auto viewPoint =
|
const auto viewPoint =
|
||||||
omath::projectile_prediction::ProjPredEngineLegacy(400, 1.f / 1000.f, 50, 5.f).maybe_calculate_aim_point(proj, target);
|
omath::projectile_prediction::ProjPredEngineLegacy(400, 1.f / 1000.f, 50, 5.f).maybe_calculate_aim_point(proj, target);
|
||||||
|
|
||||||
const auto [pitch, yaw, _] = proj.m_origin.view_angle_to(viewPoint.value()).as_tuple();
|
|
||||||
|
|
||||||
EXPECT_NEAR(42.547142, pitch, 0.01f);
|
const auto [pitch, yaw, _] =omath::source_engine::CameraTrait::calc_look_at_angle(proj.m_origin, viewPoint.value());
|
||||||
EXPECT_NEAR(-1.181189, yaw, 0.01f);
|
|
||||||
|
EXPECT_NEAR(-42.547142, pitch.as_degrees(), 0.01f);
|
||||||
|
EXPECT_NEAR(-1.181189, yaw.as_degrees(), 0.01f);
|
||||||
}
|
}
|
||||||
|
|||||||
50
tests/general/unit_test_reverse_enineering.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 10/4/2025.
|
||||||
|
//
|
||||||
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <omath/rev_eng/internal_rev_object.hpp>
|
||||||
|
|
||||||
|
class Player final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual int foo() {return 1;}
|
||||||
|
virtual int bar() {return 2;}
|
||||||
|
omath::Vector3<float> m_origin{1.f, 2.f, 3.f};
|
||||||
|
int m_health{123};
|
||||||
|
};
|
||||||
|
|
||||||
|
class RevPlayer : omath::rev_eng::InternalReverseEngineeredObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
omath::Vector3<float> get_origin()
|
||||||
|
{
|
||||||
|
return get_by_offset<omath::Vector3<float>>(sizeof(std::uintptr_t));
|
||||||
|
}
|
||||||
|
int get_health()
|
||||||
|
{
|
||||||
|
return get_by_offset<int>(sizeof(std::uintptr_t)+sizeof(omath::Vector3<float>));
|
||||||
|
}
|
||||||
|
|
||||||
|
int rev_foo()
|
||||||
|
{
|
||||||
|
return call_virtual_method<0, int>();
|
||||||
|
}
|
||||||
|
int rev_bar()
|
||||||
|
{
|
||||||
|
return call_virtual_method<1, int>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
TEST(unit_test_reverse_enineering, read_test)
|
||||||
|
{
|
||||||
|
Player player_original;
|
||||||
|
const auto player_reversed = reinterpret_cast<RevPlayer*>(&player_original);
|
||||||
|
|
||||||
|
EXPECT_EQ(player_original.m_origin, player_reversed->get_origin());
|
||||||
|
EXPECT_EQ(player_original.m_health, player_reversed->get_health());
|
||||||
|
|
||||||
|
EXPECT_EQ(player_original.bar(), player_reversed->rev_bar());
|
||||||
|
EXPECT_EQ(player_original.foo(), player_reversed->rev_foo());
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Created by Orange on 1/6/2025.
|
// Created by Orange on 1/6/2025.
|
||||||
//
|
//
|
||||||
#include "omath/triangle.hpp"
|
#include "omath/linear_algebra/triangle.hpp"
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
#include <cmath> // For std::sqrt, std::isinf, std::isnan
|
#include <cmath> // For std::sqrt, std::isinf, std::isnan
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//
|
//
|
||||||
// Created by Orange on 11/30/2024.
|
// Created by Orange on 11/30/2024.
|
||||||
//
|
//
|
||||||
#include <omath/view_angles.hpp>
|
#include <omath/trigonometry/view_angles.hpp>
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE categories
|
|
||||||
SYSTEM "https://resources.jetbrains.com/writerside/1.0/categories.dtd">
|
|
||||||
<categories>
|
|
||||||
<category id="wrs" name="Writerside documentation" order="1"/>
|
|
||||||
<category id="inf" name="Learn more" order="2"/>
|
|
||||||
</categories>
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE buildprofiles SYSTEM "https://resources.jetbrains.com/writerside/1.0/build-profiles.dtd">
|
|
||||||
<buildprofiles xsi:noNamespaceSchemaLocation="https://resources.jetbrains.com/writerside/1.0/build-profiles.xsd"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
||||||
|
|
||||||
<variables></variables>
|
|
||||||
<build-profile instance="o">
|
|
||||||
<variables>
|
|
||||||
<noindex-content>true</noindex-content>
|
|
||||||
</variables>
|
|
||||||
</build-profile>
|
|
||||||
|
|
||||||
</buildprofiles>
|
|
||||||
|
Before Width: | Height: | Size: 125 KiB |
|
Before Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 341 KiB |
|
Before Width: | Height: | Size: 119 KiB |
|
Before Width: | Height: | Size: 306 KiB |
|
Before Width: | Height: | Size: 274 KiB |
@@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE instance-profile
|
|
||||||
SYSTEM "https://resources.jetbrains.com/writerside/1.0/product-profile.dtd">
|
|
||||||
|
|
||||||
<instance-profile id="o"
|
|
||||||
name="OMATH"
|
|
||||||
start-page="starter-topic.md">
|
|
||||||
|
|
||||||
<toc-element topic="starter-topic.md"/>
|
|
||||||
<toc-element topic="Documentation.md"/>
|
|
||||||
<toc-element topic="Code-Of-Conduct.md"/>
|
|
||||||
<toc-element topic="Community.md"/>
|
|
||||||
<toc-element topic="License.md"/>
|
|
||||||
</instance-profile>
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE rules SYSTEM "https://resources.jetbrains.com/writerside/1.0/redirection-rules.dtd">
|
|
||||||
<rules>
|
|
||||||
<!-- format is as follows
|
|
||||||
<rule id="<unique id>">
|
|
||||||
<accepts>page.html</accepts>
|
|
||||||
</rule>
|
|
||||||
-->
|
|
||||||
<rule id="4e037516">
|
|
||||||
<description><![CDATA[Created after removal of "<Empty-MD-Topic.md>" from OMATH]]></description>
|
|
||||||
<accepts>Empty-MD-Topic.html</accepts>
|
|
||||||
</rule>
|
|
||||||
</rules>
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
# Code Of Conduct
|
|
||||||
|
|
||||||
## 🎯 Goal
|
|
||||||
|
|
||||||
My goal is to provide a space where it is safe for everyone to contribute to,
|
|
||||||
and get support for, open-source software in a respectful and cooperative
|
|
||||||
manner.
|
|
||||||
|
|
||||||
I value all contributions and want to make this project and its
|
|
||||||
surrounding community a place for everyone.
|
|
||||||
|
|
||||||
As members, contributors, and everyone else who may participate in the
|
|
||||||
development, I strive to keep the entire experience civil.
|
|
||||||
|
|
||||||
## 📜 Standards
|
|
||||||
|
|
||||||
Our community standards exist in order to make sure everyone feels comfortable
|
|
||||||
contributing to the project(s) together.
|
|
||||||
|
|
||||||
Our standards are:
|
|
||||||
- Do not harass, attack, or in any other way discriminate against anyone, including
|
|
||||||
for their protected traits, including, but not limited to, sex, religion, race,
|
|
||||||
appearance, gender, identity, nationality, sexuality, etc.
|
|
||||||
- Do not go off-topic, do not post spam.
|
|
||||||
- Treat everyone with respect.
|
|
||||||
|
|
||||||
Examples of breaking each rule respectively include:
|
|
||||||
- Harassment, bullying or inappropriate jokes about another person.
|
|
||||||
- Posting distasteful imagery, trolling, or posting things unrelated to the topic at hand.
|
|
||||||
- Treating someone as worse because of their lack of understanding of an issue.
|
|
||||||
|
|
||||||
## ⚡ Enforcement
|
|
||||||
|
|
||||||
Enforcement of this CoC is done by Orange++ and/or other core contributors.
|
|
||||||
|
|
||||||
I, as the core developer, will strive my best to keep this community civil and
|
|
||||||
following the standards outlined above.
|
|
||||||
|
|
||||||
### 🚩 Reporting incidents
|
|
||||||
|
|
||||||
If you believe an incident of breaking these standards has occurred, but nobody has
|
|
||||||
taken appropriate action, you can privately contact the people responsible for dealing
|
|
||||||
with such incidents in multiple ways:
|
|
||||||
|
|
||||||
***E-Mail***
|
|
||||||
- `orange-cpp@yandex.ru`
|
|
||||||
|
|
||||||
***Discord***
|
|
||||||
- `@orange_cpp`
|
|
||||||
|
|
||||||
***Telegram***
|
|
||||||
- `@orange_cpp`
|
|
||||||
|
|
||||||
I guarantee your privacy and will not share those reports with anyone.
|
|
||||||
|
|
||||||
## ⚖️ Enforcement Strategy
|
|
||||||
|
|
||||||
Depending on the severity of the infraction, any action from the list below may be applied.
|
|
||||||
Please keep in mind cases are reviewed on a per-case basis and members are the ultimate
|
|
||||||
deciding factor in the type of punishment.
|
|
||||||
|
|
||||||
If the matter benefited from an outside opinion, a member might reach for more opinions
|
|
||||||
from people unrelated, however, the final decision regarding the action
|
|
||||||
to be taken is still up to the member.
|
|
||||||
|
|
||||||
For example, if the matter at hand regards a representative of a marginalized group or minority,
|
|
||||||
the member might ask for a first-hand opinion from another representative of such group.
|
|
||||||
|
|
||||||
### ✏️ Correction/Edit
|
|
||||||
|
|
||||||
If your message is found to be misleading or poorly worded, a member might
|
|
||||||
edit your message.
|
|
||||||
|
|
||||||
### ⚠️ Warning/Deletion
|
|
||||||
|
|
||||||
If your message is found inappropriate, a member might give you a public or private warning,
|
|
||||||
and/or delete your message.
|
|
||||||
|
|
||||||
### 🔇 Mute
|
|
||||||
|
|
||||||
If your message is disruptive, or you have been repeatedly violating the standards,
|
|
||||||
a member might mute (or temporarily ban) you.
|
|
||||||
|
|
||||||
### ⛔ Ban
|
|
||||||
|
|
||||||
If your message is hateful, very disruptive, or other, less serious infractions are repeated
|
|
||||||
ignoring previous punishments, a member might ban you permanently.
|
|
||||||
|
|
||||||
## 🔎 Scope
|
|
||||||
|
|
||||||
This CoC shall apply to all projects ran under the Orange++ lead and all _official_ communities
|
|
||||||
outside of GitHub.
|
|
||||||
|
|
||||||
However, it is worth noting that official communities outside of GitHub might have their own,
|
|
||||||
additional sets of rules.
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
# Credits
|
|
||||||
|
|
||||||
Thanks to everyone who made this possible, including:
|
|
||||||
|
|
||||||
- Saikari aka luadebug for VCPKG port.
|
|
||||||
|
|
||||||
And a big hand to everyone else who has contributed over the past!
|
|
||||||
|
|
||||||
THANKS! <3
|
|
||||||
|
|
||||||
-- Orange++ <orange-cpp@yandex.ru>
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
# 📥Installation Guide
|
|
||||||
|
|
||||||
## 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).
|
|
||||||
|
|
||||||
## 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 |
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# License
|
|
||||||
|
|
||||||
Copyright (c) 2025 Orange++
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
# Intro
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
## 👁🗨 Features
|
|
||||||
- **Efficiency**: Optimized for performance, ensuring quick computations using AVX2.
|
|
||||||
- **Versatility**: Includes a wide array of mathematical functions and algorithms.
|
|
||||||
- **Ease of Use**: Simplified interface for convenient integration into various projects.
|
|
||||||
- **Projectile Prediction**: Projectile prediction engine with O(N) algo complexity, that can power you projectile aim-bot.
|
|
||||||
- **3D Projection**: No need to find view-projection matrix anymore you can make your own projection pipeline.
|
|
||||||
- **Collision Detection**: Production ready code to handle collision detection by using simple interfaces.
|
|
||||||
- **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!
|
|
||||||
|
|
||||||
## Supported Render Pipelines
|
|
||||||
| ENGINE | SUPPORT |
|
|
||||||
|----------|---------|
|
|
||||||
| Source | ✅YES |
|
|
||||||
| Unity | ✅YES |
|
|
||||||
| IWEngine | ✅YES |
|
|
||||||
| Unreal | ❌NO |
|
|
||||||
|
|
||||||
## Supported Operating Systems
|
|
||||||
|
|
||||||
| OS | SUPPORT |
|
|
||||||
|----------------|---------|
|
|
||||||
| Windows 10/11 | ✅YES |
|
|
||||||
| 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
|
|
||||||
Simple world to screen function
|
|
||||||
```c++
|
|
||||||
TEST(UnitTestProjection, IsPointOnScreen)
|
|
||||||
{
|
|
||||||
const omath::projection::Camera camera({0.f, 0.f, 0.f}, {0, 0.f, 0.f} , {1920.f, 1080.f}, 110.f, 0.1f, 500.f);
|
|
||||||
|
|
||||||
const auto proj = camera.WorldToScreen({100, 0, 15});
|
|
||||||
EXPECT_TRUE(proj.has_value());
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Showcase
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
## 🫵🏻 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 MIT - see the `LICENSE` file for details.
|
|
||||||
|
|
||||||
## 💘 Acknowledgments
|
|
||||||
- [All contributors](https://github.com/orange-cpp/omath/graphs/contributors)
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE vars SYSTEM "https://resources.jetbrains.com/writerside/1.0/vars.dtd">
|
|
||||||
<vars>
|
|
||||||
<var name="product" value="Writerside"/>
|
|
||||||
</vars>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE ihp SYSTEM "https://resources.jetbrains.com/writerside/1.0/ihp.dtd">
|
|
||||||
|
|
||||||
<ihp version="2.0">
|
|
||||||
<topics dir="topics" web-path="topics"/>
|
|
||||||
<images dir="images" web-path="images"/>
|
|
||||||
<instance src="o.tree"/>
|
|
||||||
</ihp>
|
|
||||||