Compare commits
68 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d238bd137f | |||
| 17b150499d | |||
| c7228c9674 | |||
| 7a9f5d4966 | |||
| a16050242a | |||
| ea8f3d8d51 | |||
| 08d2ccc03a | |||
| 21ec23d77b | |||
| 2c4ff37062 | |||
| 695a8035b5 | |||
| d12b236e56 | |||
| 7a5090d9f6 | |||
| ec76a7239c | |||
| 2758f549a3 | |||
| 493931ef0f | |||
| 9e1990942b | |||
| f1984fbe46 | |||
| f1fbea21a7 | |||
| 4b44ce0667 | |||
| 231ef35a0a | |||
| 1aa62cb396 | |||
| 8e411771c2 | |||
| d65852d1a4 | |||
| 21f5e82a20 | |||
|
|
851ec37350 | ||
| f1cd9dbeb3 | |||
| 7a1c7d6cc4 | |||
| cb704b3621 | |||
|
|
646d295876 | ||
| 8e09556c25 | |||
| 7dbebc996d | |||
| 278ffba0ff | |||
| 647cf02a38 | |||
| 4be2986681 | |||
| 06d9b4c910 | |||
| a074fdcb92 | |||
|
|
8241d9c355 | ||
| 66258f0f6d | |||
| 65541fa2c7 | |||
| 7e4a6134bf | |||
| a54a537239 | |||
| f01bbde537 | |||
| 2c710555d6 | |||
| 9c2be6306c | |||
| d37840d4ef | |||
| b4a3b5d529 | |||
| c2a772142c | |||
| 76fca7f527 | |||
| 73ccd24e3e | |||
| a642feafb5 | |||
| faf9f34af8 | |||
| b56801ac91 | |||
| a81d12d480 | |||
| 17eb0cd0dc | |||
| 52024285d2 | |||
| f179aea4d7 | |||
| 1196bb86b4 | |||
| 5489c296e9 | |||
| 50ddf2d31e | |||
| a6e4c0461d | |||
| 6749f9f759 | |||
| 9a38d47b0d | |||
| f6f8bba032 | |||
| ce08fcdd29 | |||
| 49ea113348 | |||
| af21f9a946 | |||
| f096f7179f | |||
| e025e99d18 |
@@ -33,7 +33,7 @@ BraceWrapping:
|
||||
BeforeWhile: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: All
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeConceptDeclarations: false
|
||||
ColumnLimit: 120
|
||||
IncludeBlocks: Merge
|
||||
|
||||
BIN
.github/images/banner.png
vendored
Normal file
|
After Width: | Height: | Size: 137 KiB |
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
/cmake-build/
|
||||
/.idea
|
||||
/out
|
||||
*.DS_Store
|
||||
*.DS_Store
|
||||
/extlibs/vcpkg
|
||||
@@ -1,11 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(omath VERSION 1.0.1 LANGUAGES CXX)
|
||||
project(omath VERSION 3.0.4.1 LANGUAGES CXX)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
|
||||
option(OMATH_BUILD_TESTS "Build unit tests" OFF)
|
||||
option(OMATH_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL})
|
||||
option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON)
|
||||
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)
|
||||
@@ -14,26 +14,29 @@ option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" O
|
||||
option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OFF)
|
||||
option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build to improve general performance" ON)
|
||||
option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" ON)
|
||||
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" OFF)
|
||||
|
||||
|
||||
file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
|
||||
file(GLOB_RECURSE OMATH_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
|
||||
|
||||
|
||||
if (OMATH_BUILD_AS_SHARED_LIBRARY)
|
||||
add_library(omath SHARED ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||
add_library(${PROJECT_NAME} SHARED ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||
else ()
|
||||
add_library(omath STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||
endif ()
|
||||
|
||||
message(STATUS "Building on ${CMAKE_HOST_SYSTEM_NAME}")
|
||||
add_library(omath::omath ALIAS omath)
|
||||
message(STATUS "[OMATH]: Building on ${CMAKE_HOST_SYSTEM_NAME}")
|
||||
|
||||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||
|
||||
if (OMATH_IMGUI_INTEGRATION)
|
||||
target_compile_definitions(omath PUBLIC OMATH_IMGUI_INTEGRATION)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_IMGUI_INTEGRATION)
|
||||
|
||||
# IMGUI is being linked as submodule
|
||||
if (TARGET imgui)
|
||||
target_link_libraries(omath PUBLIC imgui)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC imgui)
|
||||
install(TARGETS imgui
|
||||
EXPORT omathTargets
|
||||
ARCHIVE DESTINATION lib
|
||||
@@ -42,42 +45,46 @@ if (OMATH_IMGUI_INTEGRATION)
|
||||
else ()
|
||||
# Assume that IMGUI linked via VCPKG.
|
||||
find_package(imgui CONFIG REQUIRED)
|
||||
target_link_libraries(omath PUBLIC imgui::imgui)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC imgui::imgui)
|
||||
endif ()
|
||||
|
||||
endif ()
|
||||
|
||||
if (OMATH_USE_AVX2)
|
||||
target_compile_definitions(omath PUBLIC OMATH_USE_AVX2)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_USE_AVX2)
|
||||
endif ()
|
||||
|
||||
if (OMATH_SUPRESS_SAFETY_CHECKS)
|
||||
target_compile_definitions(omath PUBLIC OMATH_SUPRESS_SAFETY_CHECKS)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_SUPRESS_SAFETY_CHECKS)
|
||||
endif ()
|
||||
|
||||
set_target_properties(omath PROPERTIES
|
||||
if (OMATH_ENABLE_LEGACY)
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LEGACY)
|
||||
endif ()
|
||||
|
||||
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}"
|
||||
CXX_STANDARD 23
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if (OMATH_USE_UNITY_BUILD)
|
||||
set_target_properties(omath PROPERTIES
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
UNITY_BUILD ON
|
||||
UNITY_BUILD_BATCH_SIZE 20)
|
||||
endif ()
|
||||
|
||||
if (OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
|
||||
set_target_properties(omath PROPERTIES
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
target_compile_options(omath PRIVATE -mavx2 -mfma)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE -mavx2 -mfma)
|
||||
endif ()
|
||||
|
||||
target_compile_features(omath PUBLIC cxx_std_23)
|
||||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
|
||||
|
||||
|
||||
if (OMATH_BUILD_TESTS)
|
||||
@@ -90,12 +97,12 @@ if (OMATH_BUILD_EXAMPLES)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR)
|
||||
target_compile_options(omath PRIVATE /W4 /WX)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
|
||||
elseif (OMATH_THREAT_WARNING_AS_ERROR)
|
||||
target_compile_options(omath PRIVATE -Wall -Wextra -Wpedantic -Werror)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror)
|
||||
endif ()
|
||||
|
||||
target_include_directories(omath
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> # Use this path when building the project
|
||||
$<INSTALL_INTERFACE:include> # Use this path when the project is installed
|
||||
@@ -105,21 +112,21 @@ target_include_directories(omath
|
||||
# Installation rules
|
||||
|
||||
# Install the library
|
||||
install(TARGETS omath
|
||||
EXPORT omathTargets
|
||||
ARCHIVE DESTINATION lib COMPONENT omath # For static libraries
|
||||
LIBRARY DESTINATION lib COMPONENT omath # For shared libraries
|
||||
RUNTIME DESTINATION bin COMPONENT omath # For executables (on Windows)
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
ARCHIVE DESTINATION lib COMPONENT ${PROJECT_NAME} # For static libraries
|
||||
LIBRARY DESTINATION lib COMPONENT ${PROJECT_NAME} # For shared libraries
|
||||
RUNTIME DESTINATION bin COMPONENT ${PROJECT_NAME} # For executables (on Windows)
|
||||
)
|
||||
|
||||
# Install headers as part of omath_component
|
||||
install(DIRECTORY include/ DESTINATION include COMPONENT omath)
|
||||
install(DIRECTORY include/ DESTINATION include COMPONENT ${PROJECT_NAME})
|
||||
|
||||
# Export omath target for CMake find_package support, also under omath_component
|
||||
install(EXPORT omathTargets
|
||||
FILE omathTargets.cmake
|
||||
NAMESPACE omath::
|
||||
DESTINATION lib/cmake/omath COMPONENT omath
|
||||
install(EXPORT ${PROJECT_NAME}Targets
|
||||
FILE ${PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION lib/cmake/${PROJECT_NAME} COMPONENT ${PROJECT_NAME}
|
||||
)
|
||||
|
||||
|
||||
@@ -134,12 +141,12 @@ write_basic_package_version_file(
|
||||
configure_package_config_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/omathConfig.cmake.in" # Path to the .in file
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/omathConfig.cmake" # Output path for the generated file
|
||||
INSTALL_DESTINATION lib/cmake/omath
|
||||
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
# Install the generated config files
|
||||
install(FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/omathConfig.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/omathConfigVersion.cmake"
|
||||
DESTINATION lib/cmake/omath
|
||||
DESTINATION lib/cmake/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
32
CONTRIBUTING.md
Normal file
@@ -0,0 +1,32 @@
|
||||
## 🤝 Contributing to OMath or other Orange's Projects
|
||||
|
||||
### ❕ Prerequisites
|
||||
|
||||
- A working up-to-date OMath installation
|
||||
- C++ knowledge
|
||||
- Git knowledge
|
||||
- Ability to ask for help (Feel free to create empty pull-request or PM a maintainer
|
||||
in [Telegram](https://t.me/orange_cpp))
|
||||
|
||||
### ⏬ Setting up OMath
|
||||
|
||||
Please read INSTALL.md file in repository
|
||||
|
||||
### 🔀 Pull requests and Branches
|
||||
|
||||
In order to send code back to the official OMath repository, you must first create a copy of OMath on your github
|
||||
account ([fork](https://help.github.com/articles/creating-a-pull-request-from-a-fork/)) and
|
||||
then [create a pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) back to OMath.
|
||||
|
||||
OMath developement is performed on multiple branches. Changes are then pull requested into master. By default, changes
|
||||
merged into master will not roll out to stable build users unless the `stable` tag is updated.
|
||||
|
||||
### 📜 Code-Style
|
||||
|
||||
The orange code-style can be found in `.clang-format`.
|
||||
|
||||
### 📦 Building
|
||||
|
||||
OMath has already created the `cmake-build` and `out` directories where cmake/bin files are located. By default, you
|
||||
can build OMath by running `cmake --build cmake-build/build/windows-release --target omath -j 6` in the source
|
||||
directory.
|
||||
14
INSTALL.md
@@ -14,6 +14,20 @@ target_link_libraries(main PRIVATE omath::omath)
|
||||
```
|
||||
For detailed commands on installing different versions and more information, please refer to Microsoft's [official instructions](https://learn.microsoft.com/en-us/vcpkg/get_started/overview).
|
||||
|
||||
## <img width="28px" src="https://xmake.io/assets/img/logo.svg" /> Using xrepo
|
||||
**Note**: Support xrepo for package management
|
||||
1. Install [xmake](https://xmake.io/)
|
||||
2. Run the following command to install the omath package:
|
||||
```
|
||||
xrepo install omath
|
||||
```
|
||||
xmake.lua
|
||||
```xmake
|
||||
add_requires("omath")
|
||||
target("...")
|
||||
add_packages("omath")
|
||||
```
|
||||
|
||||
## <img width="28px" src="https://upload.wikimedia.org/wikipedia/commons/e/ef/CMake_logo.svg?" /> Build from source using CMake
|
||||
1. **Preparation**
|
||||
|
||||
|
||||
20
LICENSE
@@ -1,9 +1,17 @@
|
||||
The MIT License (MIT)
|
||||
Copyright (C) 2024-2025 Orange++ <orange-cpp@yandex.ru>
|
||||
|
||||
Copyright (c) 2024 Orange++
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
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:
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
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. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
19
README.md
@@ -1,16 +1,31 @@
|
||||
<div align = center>
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||

|
||||
[](https://www.codefactor.io/repository/github/orange-cpp/omath)
|
||||

|
||||
[](https://repology.org/project/orange-math/versions)
|
||||

|
||||
[](https://discord.gg/eDgdaWbqwZ)
|
||||
[](https://t.me/orangennotes)
|
||||
|
||||
</div>
|
||||
|
||||
Oranges's Math Library (omath) is a comprehensive, open-source library aimed at providing efficient, reliable, and versatile mathematical functions and algorithms. Developed primarily in C++, this library is designed to cater to a wide range of mathematical operations essential in scientific computing, engineering, and academic research.
|
||||
|
||||
<div align = center>
|
||||
<a href="https://www.star-history.com/#orange-cpp/omath&Date">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=orange-cpp/omath&type=Date&theme=dark" />
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=orange-cpp/omath&type=Date" />
|
||||
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=orange-cpp/omath&type=Date" />
|
||||
</picture>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
## 👁🗨 Features
|
||||
- **Efficiency**: Optimized for performance, ensuring quick computations using AVX2.
|
||||
- **Versatility**: Includes a wide array of mathematical functions and algorithms.
|
||||
@@ -70,7 +85,7 @@ Or even advanced projectile aimbot
|
||||
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.
|
||||
This project is licensed under the ZLIB - see the `LICENSE` file for details.
|
||||
|
||||
## 💘 Acknowledgments
|
||||
- [All contributors](https://github.com/orange-cpp/omath/graphs/contributors)
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
if (@OMATH_IMGUI_INTEGRATION@)
|
||||
find_dependency(imgui CONFIG)
|
||||
endif()
|
||||
|
||||
# Load the targets for the omath library
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/omathTargets.cmake")
|
||||
check_required_components(omath)
|
||||
|
||||
@@ -15,8 +15,8 @@ int main()
|
||||
float fov = 0;
|
||||
float near = 0;
|
||||
float far = 0;
|
||||
float viewPortWidth = 0;
|
||||
float viewPortHeight = 0;
|
||||
float view_port_width = 0;
|
||||
float view_port_height = 0;
|
||||
|
||||
std::print("Enter camera fov: ");
|
||||
std::cin >> fov;
|
||||
@@ -28,13 +28,13 @@ int main()
|
||||
std::cin >> far;
|
||||
|
||||
std::print("Enter camera screen width: ");
|
||||
std::cin >> viewPortWidth;
|
||||
std::cin >> view_port_width;
|
||||
|
||||
std::print("Enter camera screen height: ");
|
||||
std::cin >> viewPortHeight;
|
||||
std::cin >> view_port_height;
|
||||
|
||||
const auto mat =
|
||||
omath::opengl_engine::CalcPerspectiveProjectionMatrix(fov, viewPortWidth / viewPortHeight, near, far);
|
||||
omath::opengl_engine::calc_perspective_projection_matrix(fov, view_port_width / view_port_height, near, far);
|
||||
|
||||
std::print("{}", mat.ToString());
|
||||
std::print("{}", mat.to_string());
|
||||
};
|
||||
|
||||
@@ -13,5 +13,5 @@ namespace omath::primitives
|
||||
[[nodiscard]]
|
||||
std::array<Triangle<Vector3<float>>, 12> create_box(const Vector3<float>& top, const Vector3<float>& bottom,
|
||||
const Vector3<float>& dir_forward, const Vector3<float>& dir_right,
|
||||
float ratio = 4.f);
|
||||
float ratio = 4.f) noexcept;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace omath
|
||||
class Angle
|
||||
{
|
||||
Type m_angle;
|
||||
constexpr explicit Angle(const Type& degrees)
|
||||
constexpr explicit Angle(const Type& degrees) noexcept
|
||||
{
|
||||
if constexpr (flags == AngleFlags::Normalized)
|
||||
m_angle = angles::wrap_angle(degrees, min, max);
|
||||
@@ -36,68 +36,68 @@ namespace omath
|
||||
|
||||
public:
|
||||
[[nodiscard]]
|
||||
constexpr static Angle from_degrees(const Type& degrees)
|
||||
constexpr static Angle from_degrees(const Type& degrees) noexcept
|
||||
{
|
||||
return Angle{degrees};
|
||||
}
|
||||
constexpr Angle(): m_angle(0)
|
||||
constexpr Angle() noexcept: m_angle(0)
|
||||
{
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr static Angle from_radians(const Type& degrees)
|
||||
constexpr static Angle from_radians(const Type& degrees) noexcept
|
||||
{
|
||||
return Angle{angles::radians_to_degrees<Type>(degrees)};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const Type& operator*() const
|
||||
constexpr const Type& operator*() const noexcept
|
||||
{
|
||||
return m_angle;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Type as_degrees() const
|
||||
constexpr Type as_degrees() const noexcept
|
||||
{
|
||||
return m_angle;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Type as_radians() const
|
||||
constexpr Type as_radians() const noexcept
|
||||
{
|
||||
return angles::degrees_to_radians(m_angle);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Type sin() const
|
||||
Type sin() const noexcept
|
||||
{
|
||||
return std::sin(as_radians());
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Type cos() const
|
||||
Type cos() const noexcept
|
||||
{
|
||||
return std::cos(as_radians());
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Type tan() const
|
||||
Type tan() const noexcept
|
||||
{
|
||||
return std::tan(as_radians());
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Type atan() const
|
||||
Type atan() const noexcept
|
||||
{
|
||||
return std::atan(as_radians());
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Type cot() const
|
||||
Type cot() const noexcept
|
||||
{
|
||||
return cos() / sin();
|
||||
}
|
||||
|
||||
constexpr Angle& operator+=(const Angle& other)
|
||||
constexpr Angle& operator+=(const Angle& other) noexcept
|
||||
{
|
||||
if constexpr (flags == AngleFlags::Normalized)
|
||||
m_angle = angles::wrap_angle(m_angle + other.m_angle, min, max);
|
||||
@@ -114,16 +114,15 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::partial_ordering operator<=>(const Angle& other) const
|
||||
= default;
|
||||
constexpr std::partial_ordering operator<=>(const Angle& other) const noexcept = default;
|
||||
|
||||
constexpr Angle& operator-=(const Angle& other)
|
||||
constexpr Angle& operator-=(const Angle& other) noexcept
|
||||
{
|
||||
return operator+=(-other);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Angle& operator+(const Angle& other)
|
||||
constexpr Angle& operator+(const Angle& other) noexcept
|
||||
{
|
||||
if constexpr (flags == AngleFlags::Normalized)
|
||||
return {angles::wrap_angle(m_angle + other.m_angle, min, max)};
|
||||
@@ -138,13 +137,13 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Angle& operator-(const Angle& other)
|
||||
constexpr Angle& operator-(const Angle& other) noexcept
|
||||
{
|
||||
return operator+(-other);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Angle operator-() const
|
||||
constexpr Angle operator-() const noexcept
|
||||
{
|
||||
return Angle{-m_angle};
|
||||
}
|
||||
|
||||
@@ -10,21 +10,21 @@ namespace omath::angles
|
||||
{
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]] constexpr Type radians_to_degrees(const Type& radians)
|
||||
[[nodiscard]] constexpr Type radians_to_degrees(const Type& radians) noexcept
|
||||
{
|
||||
return radians * (static_cast<Type>(180) / std::numbers::pi_v<Type>);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]] constexpr Type degrees_to_radians(const Type& degrees)
|
||||
[[nodiscard]] constexpr Type degrees_to_radians(const Type& degrees) noexcept
|
||||
{
|
||||
return degrees * (std::numbers::pi_v<Type> / static_cast<Type>(180));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]] Type horizontal_fov_to_vertical(const Type& horizontal_fov, const Type& aspect)
|
||||
[[nodiscard]] Type horizontal_fov_to_vertical(const Type& horizontal_fov, const Type& aspect) noexcept
|
||||
{
|
||||
const auto fov_rad = degrees_to_radians(horizontal_fov);
|
||||
|
||||
@@ -35,19 +35,19 @@ namespace omath::angles
|
||||
|
||||
template<class Type>
|
||||
requires std::is_floating_point_v<Type>
|
||||
[[nodiscard]] Type vertical_fov_to_horizontal(const Type& vertical_fov, const Type& aspect)
|
||||
[[nodiscard]] Type vertical_fov_to_horizontal(const Type& vertical_fov, const Type& aspect) noexcept
|
||||
{
|
||||
const auto fov_as_radians = degrees_to_radians(vertical_fov);
|
||||
|
||||
const auto horizontal_fov
|
||||
= static_cast<Type>(2) * std::atan(std::tan(fov_as_radians / static_cast<Type>(2)) * aspect);
|
||||
const auto horizontal_fov =
|
||||
static_cast<Type>(2) * std::atan(std::tan(fov_as_radians / static_cast<Type>(2)) * aspect);
|
||||
|
||||
return radians_to_degrees(horizontal_fov);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
requires std::is_arithmetic_v<Type>
|
||||
[[nodiscard]] Type wrap_angle(const Type& angle, const Type& min, const Type& max)
|
||||
[[nodiscard]] Type wrap_angle(const Type& angle, const Type& min, const Type& max) noexcept
|
||||
{
|
||||
if (angle <= max && angle >= min)
|
||||
return angle;
|
||||
|
||||
@@ -16,10 +16,10 @@ namespace omath::collision
|
||||
bool infinite_length = false;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> direction_vector() const;
|
||||
Vector3<float> direction_vector() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> direction_vector_normalized() const;
|
||||
Vector3<float> direction_vector_normalized() const noexcept;
|
||||
};
|
||||
class LineTracer
|
||||
{
|
||||
@@ -27,11 +27,11 @@ namespace omath::collision
|
||||
LineTracer() = delete;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& triangle);
|
||||
static bool can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept;
|
||||
|
||||
// Realization of Möller–Trumbore intersection algorithm
|
||||
// https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
|
||||
[[nodiscard]]
|
||||
static Vector3<float> get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle);
|
||||
static Vector3<float> get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept;
|
||||
};
|
||||
} // namespace omath::collision
|
||||
|
||||
@@ -28,20 +28,20 @@ namespace omath
|
||||
class Color final : public Vector4<float>
|
||||
{
|
||||
public:
|
||||
constexpr Color(const float r, const float g, const float b, const float a): Vector4(r, g, b, a)
|
||||
constexpr Color(const float r, const float g, const float b, const float a) noexcept: Vector4(r, g, b, a)
|
||||
{
|
||||
clamp(0.f, 1.f);
|
||||
}
|
||||
|
||||
constexpr explicit Color() = default;
|
||||
constexpr explicit Color() noexcept = default;
|
||||
[[nodiscard]]
|
||||
constexpr static Color from_rgba(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a)
|
||||
constexpr static Color from_rgba(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a) noexcept
|
||||
{
|
||||
return Color{Vector4(r, g, b, a) / 255.f};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr static Color from_hsv(float hue, const float saturation, const float value)
|
||||
constexpr static Color from_hsv(float hue, const float saturation, const float value) noexcept
|
||||
{
|
||||
float r{}, g{}, b{};
|
||||
|
||||
@@ -82,13 +82,13 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr static Color from_hsv(const Hsv& hsv)
|
||||
constexpr static Color from_hsv(const Hsv& hsv) noexcept
|
||||
{
|
||||
return from_hsv(hsv.hue, hsv.saturation, hsv.value);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Hsv to_hsv() const
|
||||
constexpr Hsv to_hsv() const noexcept
|
||||
{
|
||||
Hsv hsv_data;
|
||||
|
||||
@@ -120,11 +120,11 @@ namespace omath
|
||||
return hsv_data;
|
||||
}
|
||||
|
||||
constexpr explicit Color(const Vector4& vec): Vector4(vec)
|
||||
constexpr explicit Color(const Vector4& vec) noexcept: Vector4(vec)
|
||||
{
|
||||
clamp(0.f, 1.f);
|
||||
}
|
||||
constexpr void set_hue(const float hue)
|
||||
constexpr void set_hue(const float hue) noexcept
|
||||
{
|
||||
auto hsv = to_hsv();
|
||||
hsv.hue = hue;
|
||||
@@ -132,7 +132,7 @@ namespace omath
|
||||
*this = from_hsv(hsv);
|
||||
}
|
||||
|
||||
constexpr void set_saturation(const float saturation)
|
||||
constexpr void set_saturation(const float saturation) noexcept
|
||||
{
|
||||
auto hsv = to_hsv();
|
||||
hsv.saturation = saturation;
|
||||
@@ -140,7 +140,7 @@ namespace omath
|
||||
*this = from_hsv(hsv);
|
||||
}
|
||||
|
||||
constexpr void set_value(const float value)
|
||||
constexpr void set_value(const float value) noexcept
|
||||
{
|
||||
auto hsv = to_hsv();
|
||||
hsv.value = value;
|
||||
@@ -148,7 +148,7 @@ namespace omath
|
||||
*this = from_hsv(hsv);
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr Color blend(const Color& other, float ratio) const
|
||||
constexpr Color blend(const Color& other, float ratio) const noexcept
|
||||
{
|
||||
ratio = std::clamp(ratio, 0.f, 1.f);
|
||||
return Color(*this * (1.f - ratio) + other * ratio);
|
||||
@@ -166,5 +166,12 @@ namespace omath
|
||||
{
|
||||
return {0.f, 0.f, 1.f, 1.f};
|
||||
}
|
||||
#ifdef OMATH_IMGUI_INTEGRATION
|
||||
[[nodiscard]]
|
||||
ImColor to_im_color() const noexcept
|
||||
{
|
||||
return {to_im_vec4()};
|
||||
}
|
||||
#endif
|
||||
};
|
||||
} // namespace omath
|
||||
|
||||
@@ -5,18 +5,9 @@
|
||||
#pragma once
|
||||
#include "omath/engines/iw_engine/constants.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
#include "traits/camera_trait.hpp"
|
||||
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
class Camera final : public projection::Camera<Mat4X4, ViewAngles>
|
||||
{
|
||||
public:
|
||||
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
||||
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
|
||||
void look_at(const Vector3<float>& target) override;
|
||||
|
||||
protected:
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix() const override;
|
||||
[[nodiscard]] Mat4X4 calc_projection_matrix() const override;
|
||||
};
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
|
||||
} // namespace omath::iw_engine
|
||||
@@ -8,19 +8,19 @@
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
Vector3<float> forward_vector(const ViewAngles& angles);
|
||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> right_vector(const ViewAngles& angles);
|
||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> up_vector(const ViewAngles& angles);
|
||||
Vector3<float> up_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles);
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far);
|
||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
|
||||
} // namespace omath::iw_engine
|
||||
|
||||
24
include/omath/engines/iw_engine/traits/camera_trait.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Vlad on 8/10/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/iw_engine/constants.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
class CameraTrait final
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||
[[nodiscard]]
|
||||
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
float near, float far) noexcept;
|
||||
};
|
||||
|
||||
} // namespace omath::iw_engine
|
||||
79
include/omath/engines/iw_engine/traits/pred_engine_trait.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// Created by Vlad on 8/6/2025.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "omath/engines/iw_engine/formulas.hpp"
|
||||
#include "omath/projectile_prediction/projectile.hpp"
|
||||
#include "omath/projectile_prediction/target.hpp"
|
||||
#include <optional>
|
||||
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
class PredEngineTrait final
|
||||
{
|
||||
public:
|
||||
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile& projectile,
|
||||
const float pitch, const float yaw,
|
||||
const float time, const float gravity) noexcept
|
||||
{
|
||||
auto current_pos = projectile.m_origin
|
||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||
RollAngle::from_degrees(0)})
|
||||
* projectile.m_launch_speed * time;
|
||||
current_pos.z -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;
|
||||
|
||||
return current_pos;
|
||||
}
|
||||
[[nodiscard]]
|
||||
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target& target,
|
||||
const float time, const float gravity) noexcept
|
||||
{
|
||||
auto predicted = target.m_origin + target.m_velocity * time;
|
||||
|
||||
if (target.m_is_airborne)
|
||||
predicted.z -= gravity * (time * time) * 0.5f;
|
||||
|
||||
return predicted;
|
||||
}
|
||||
[[nodiscard]]
|
||||
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
|
||||
{
|
||||
return std::sqrt(delta.x * delta.x + delta.y * delta.y);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
|
||||
{
|
||||
return vec.z;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
|
||||
Vector3<float> predicted_target_position,
|
||||
const std::optional<float> projectile_pitch) noexcept
|
||||
{
|
||||
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
||||
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
||||
|
||||
return {predicted_target_position.x, predicted_target_position.y, projectile.m_origin.z + height};
|
||||
}
|
||||
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
||||
// 89 look up, -89 look down
|
||||
[[nodiscard]]
|
||||
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 delta = view_to - origin;
|
||||
|
||||
return angles::radians_to_degrees(std::asin(delta.z / distance));
|
||||
}
|
||||
[[nodiscard]]
|
||||
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||
{
|
||||
const auto delta = view_to - origin;
|
||||
|
||||
return angles::radians_to_degrees(std::atan2(delta.y, delta.x));
|
||||
};
|
||||
};
|
||||
} // namespace omath::iw_engine
|
||||
@@ -4,16 +4,9 @@
|
||||
#pragma once
|
||||
#include "omath/engines/opengl_engine/constants.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
#include "traits/camera_trait.hpp"
|
||||
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
class Camera final : public projection::Camera<Mat4X4, ViewAngles>
|
||||
{
|
||||
public:
|
||||
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
||||
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
|
||||
void look_at(const Vector3<float>& target) override;
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix() const override;
|
||||
[[nodiscard]] Mat4X4 calc_projection_matrix() const override;
|
||||
};
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
|
||||
} // namespace omath::opengl_engine
|
||||
@@ -8,19 +8,19 @@
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
Vector3<float> forward_vector(const ViewAngles& angles);
|
||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> right_vector(const ViewAngles& angles);
|
||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> up_vector(const ViewAngles& angles);
|
||||
Vector3<float> up_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles);
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far);
|
||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
|
||||
} // namespace omath::opengl_engine
|
||||
|
||||
24
include/omath/engines/opengl_engine/traits/camera_trait.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Vlad on 8/10/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/opengl_engine/constants.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
class CameraTrait final
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||
[[nodiscard]]
|
||||
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
float near, float far) noexcept;
|
||||
};
|
||||
|
||||
} // namespace omath::opengl_engine
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Created by Vlad on 8/6/2025.
|
||||
//
|
||||
#pragma once
|
||||
#include "omath/engines/opengl_engine/formulas.hpp"
|
||||
#include "omath/projectile_prediction/projectile.hpp"
|
||||
#include "omath/projectile_prediction/target.hpp"
|
||||
#include <optional>
|
||||
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
class PredEngineTrait final
|
||||
{
|
||||
public:
|
||||
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile& projectile,
|
||||
const float pitch, const float yaw,
|
||||
const float time, const float gravity) noexcept
|
||||
{
|
||||
auto current_pos = projectile.m_origin
|
||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||
RollAngle::from_degrees(0)})
|
||||
* projectile.m_launch_speed * time;
|
||||
current_pos.y -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;
|
||||
|
||||
return current_pos;
|
||||
}
|
||||
[[nodiscard]]
|
||||
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target& target,
|
||||
const float time, const float gravity) noexcept
|
||||
{
|
||||
auto predicted = target.m_origin + target.m_velocity * time;
|
||||
|
||||
if (target.m_is_airborne)
|
||||
predicted.y -= gravity * (time * time) * 0.5f;
|
||||
|
||||
return predicted;
|
||||
}
|
||||
[[nodiscard]]
|
||||
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
|
||||
{
|
||||
return std::sqrt(delta.x * delta.x + delta.z * delta.z);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
|
||||
{
|
||||
return vec.y;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
|
||||
Vector3<float> predicted_target_position,
|
||||
const std::optional<float> projectile_pitch) noexcept
|
||||
{
|
||||
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
||||
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
||||
|
||||
return {predicted_target_position.x, predicted_target_position.y + height, projectile.m_origin.z};
|
||||
}
|
||||
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
||||
// 89 look up, -89 look down
|
||||
[[nodiscard]]
|
||||
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 delta = view_to - origin;
|
||||
|
||||
return angles::radians_to_degrees(std::asin(delta.y / distance));
|
||||
}
|
||||
[[nodiscard]]
|
||||
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||
{
|
||||
const auto delta = view_to - origin;
|
||||
|
||||
return angles::radians_to_degrees(std::atan2(delta.z, delta.x));
|
||||
};
|
||||
};
|
||||
} // namespace omath::opengl_engine
|
||||
@@ -4,18 +4,8 @@
|
||||
#pragma once
|
||||
#include "omath/engines/source_engine/constants.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
#include "traits/camera_trait.hpp"
|
||||
namespace omath::source_engine
|
||||
{
|
||||
class Camera final : public projection::Camera<Mat4X4, ViewAngles>
|
||||
{
|
||||
public:
|
||||
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
||||
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
|
||||
void look_at(const Vector3<float>& target) override;
|
||||
|
||||
protected:
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix() const override;
|
||||
[[nodiscard]] Mat4X4 calc_projection_matrix() const override;
|
||||
};
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
|
||||
} // namespace omath::source_engine
|
||||
@@ -7,19 +7,19 @@
|
||||
namespace omath::source_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
Vector3<float> forward_vector(const ViewAngles& angles);
|
||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles);
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> right_vector(const ViewAngles& angles);
|
||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> up_vector(const ViewAngles& angles);
|
||||
Vector3<float> up_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far);
|
||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
|
||||
} // namespace omath::source_engine
|
||||
|
||||
24
include/omath/engines/source_engine/traits/camera_trait.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Vlad on 8/10/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/source_engine/constants.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::source_engine
|
||||
{
|
||||
class CameraTrait final
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||
[[nodiscard]]
|
||||
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
float near, float far) noexcept;
|
||||
};
|
||||
|
||||
} // namespace omath::source_engine
|
||||
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// Created by Vlad on 8/3/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/source_engine/formulas.hpp"
|
||||
#include "omath/projectile_prediction/projectile.hpp"
|
||||
#include "omath/projectile_prediction/target.hpp"
|
||||
#include <optional>
|
||||
|
||||
namespace omath::source_engine
|
||||
{
|
||||
class PredEngineTrait final
|
||||
{
|
||||
public:
|
||||
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile& projectile,
|
||||
const float pitch, const float yaw,
|
||||
const float time, const float gravity) noexcept
|
||||
{
|
||||
auto current_pos = projectile.m_origin
|
||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||
RollAngle::from_degrees(0)})
|
||||
* projectile.m_launch_speed * time;
|
||||
current_pos.z -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;
|
||||
|
||||
return current_pos;
|
||||
}
|
||||
[[nodiscard]]
|
||||
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target& target,
|
||||
const float time, const float gravity) noexcept
|
||||
{
|
||||
auto predicted = target.m_origin + target.m_velocity * time;
|
||||
|
||||
if (target.m_is_airborne)
|
||||
predicted.z -= gravity * (time * time) * 0.5f;
|
||||
|
||||
return predicted;
|
||||
}
|
||||
[[nodiscard]]
|
||||
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
|
||||
{
|
||||
return std::sqrt(delta.x * delta.x + delta.y * delta.y);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
|
||||
{
|
||||
return vec.z;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
|
||||
Vector3<float> predicted_target_position,
|
||||
const std::optional<float> projectile_pitch) noexcept
|
||||
{
|
||||
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
||||
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
||||
|
||||
return {predicted_target_position.x, predicted_target_position.y, projectile.m_origin.z + height};
|
||||
}
|
||||
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
||||
// 89 look up, -89 look down
|
||||
[[nodiscard]]
|
||||
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 delta = view_to - origin;
|
||||
|
||||
return angles::radians_to_degrees(std::asin(delta.z / distance));
|
||||
}
|
||||
[[nodiscard]]
|
||||
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||
{
|
||||
const auto delta = view_to - origin;
|
||||
|
||||
return angles::radians_to_degrees(std::atan2(delta.y, delta.x));
|
||||
};
|
||||
};
|
||||
} // namespace omath::source_engine
|
||||
@@ -5,18 +5,9 @@
|
||||
#pragma once
|
||||
#include "omath/engines/unity_engine/constants.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
#include "traits/camera_trait.hpp"
|
||||
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
class Camera final : public projection::Camera<Mat4X4, ViewAngles>
|
||||
{
|
||||
public:
|
||||
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
||||
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
|
||||
void look_at(const Vector3<float>& target) override;
|
||||
|
||||
protected:
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix() const override;
|
||||
[[nodiscard]] Mat4X4 calc_projection_matrix() const override;
|
||||
};
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
|
||||
} // namespace omath::unity_engine
|
||||
@@ -8,19 +8,19 @@
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
[[nodiscard]]
|
||||
Vector3<float> forward_vector(const ViewAngles& angles);
|
||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> right_vector(const ViewAngles& angles);
|
||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> up_vector(const ViewAngles& angles);
|
||||
Vector3<float> up_vector(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles);
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far);
|
||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
|
||||
} // namespace omath::unity_engine
|
||||
|
||||
24
include/omath/engines/unity_engine/traits/camera_trait.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Vlad on 8/10/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "omath/engines/unity_engine/formulas.hpp"
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
class CameraTrait final
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||
[[nodiscard]]
|
||||
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||
float near, float far) noexcept;
|
||||
};
|
||||
|
||||
} // namespace omath::unity_engine
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Created by Vlad on 8/6/2025.
|
||||
//
|
||||
#pragma once
|
||||
#include "omath/engines/unity_engine/formulas.hpp"
|
||||
#include "omath/projectile_prediction/projectile.hpp"
|
||||
#include "omath/projectile_prediction/target.hpp"
|
||||
#include <optional>
|
||||
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
class PredEngineTrait final
|
||||
{
|
||||
public:
|
||||
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile& projectile,
|
||||
const float pitch, const float yaw,
|
||||
const float time, const float gravity) noexcept
|
||||
{
|
||||
auto current_pos = projectile.m_origin
|
||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||
RollAngle::from_degrees(0)})
|
||||
* projectile.m_launch_speed * time;
|
||||
current_pos.y -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;
|
||||
|
||||
return current_pos;
|
||||
}
|
||||
[[nodiscard]]
|
||||
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target& target,
|
||||
const float time, const float gravity) noexcept
|
||||
{
|
||||
auto predicted = target.m_origin + target.m_velocity * time;
|
||||
|
||||
if (target.m_is_airborne)
|
||||
predicted.y -= gravity * (time * time) * 0.5f;
|
||||
|
||||
return predicted;
|
||||
}
|
||||
[[nodiscard]]
|
||||
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
|
||||
{
|
||||
return std::sqrt(delta.x * delta.x + delta.z * delta.z);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
|
||||
{
|
||||
return vec.y;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
|
||||
Vector3<float> predicted_target_position,
|
||||
const std::optional<float> projectile_pitch) noexcept
|
||||
{
|
||||
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
||||
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
||||
|
||||
return {predicted_target_position.x, predicted_target_position.y + height, projectile.m_origin.z};
|
||||
}
|
||||
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
||||
// 89 look up, -89 look down
|
||||
[[nodiscard]]
|
||||
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 delta = view_to - origin;
|
||||
|
||||
return angles::radians_to_degrees(std::asin(delta.y / distance));
|
||||
}
|
||||
[[nodiscard]]
|
||||
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||
{
|
||||
const auto delta = view_to - origin;
|
||||
|
||||
return angles::radians_to_degrees(std::atan2(delta.z, delta.x));
|
||||
};
|
||||
};
|
||||
} // namespace omath::unity_engine
|
||||
@@ -451,7 +451,6 @@ namespace omath
|
||||
{up.x, up.y, up.z, 0},
|
||||
{forward.x, forward.y, forward.z, 0},
|
||||
{0, 0, 0, 1},
|
||||
|
||||
} * mat_translation<Type, St>(-camera_origin);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef OMATH_ENABLE_LEGACY
|
||||
|
||||
#include "omath/vector3.hpp"
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
@@ -106,3 +109,4 @@ namespace omath
|
||||
std::unique_ptr<float[]> m_data;
|
||||
};
|
||||
} // namespace omath
|
||||
#endif
|
||||
|
||||
@@ -15,16 +15,16 @@ namespace omath::pathfinding
|
||||
public:
|
||||
[[nodiscard]]
|
||||
static std::vector<Vector3<float>> find_path(const Vector3<float>& start, const Vector3<float>& end,
|
||||
const NavigationMesh& nav_mesh);
|
||||
const NavigationMesh& nav_mesh) noexcept;
|
||||
|
||||
private:
|
||||
[[nodiscard]]
|
||||
static std::vector<Vector3<float>>
|
||||
reconstruct_final_path(const std::unordered_map<Vector3<float>, PathNode>& closed_list,
|
||||
const Vector3<float>& current);
|
||||
const Vector3<float>& current) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
static auto get_perfect_node(const std::unordered_map<Vector3<float>, PathNode>& open_list,
|
||||
const Vector3<float>& end_vertex);
|
||||
const Vector3<float>& end_vertex) noexcept;
|
||||
};
|
||||
} // namespace omath::pathfinding
|
||||
|
||||
@@ -14,24 +14,23 @@ namespace omath::pathfinding
|
||||
|
||||
enum Error
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class NavigationMesh final
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
std::expected<Vector3<float>, std::string> get_closest_vertex(const Vector3<float>& point) const;
|
||||
std::expected<Vector3<float>, std::string> get_closest_vertex(const Vector3<float>& point) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
const std::vector<Vector3<float>>& get_neighbors(const Vector3<float>& vertex) const;
|
||||
const std::vector<Vector3<float>>& get_neighbors(const Vector3<float>& vertex) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
bool empty() const;
|
||||
|
||||
[[nodiscard]] std::vector<uint8_t> serialize() const;
|
||||
[[nodiscard]] std::vector<uint8_t> serialize() const noexcept;
|
||||
|
||||
void deserialize(const std::vector<uint8_t>& raw);
|
||||
void deserialize(const std::vector<uint8_t>& raw) noexcept;
|
||||
|
||||
std::unordered_map<Vector3<float>, std::vector<Vector3<float>>> m_vertex_map;
|
||||
};
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
class ProjPredEngine
|
||||
class ProjPredEngineInterface
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
virtual std::optional<Vector3<float>> maybe_calculate_aim_point(const Projectile& projectile,
|
||||
const Target& target) const = 0;
|
||||
virtual ~ProjPredEngine() = default;
|
||||
virtual ~ProjPredEngineInterface() = default;
|
||||
};
|
||||
} // namespace omath::projectile_prediction
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
class ProjPredEngineAvx2 final : public ProjPredEngine
|
||||
class ProjPredEngineAvx2 final : public ProjPredEngineInterface
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] std::optional<Vector3<float>> maybe_calculate_aim_point(const Projectile& projectile,
|
||||
const Target& target) const override;
|
||||
[[nodiscard]] std::optional<Vector3<float>>
|
||||
maybe_calculate_aim_point(const Projectile& projectile, const Target& target) const override;
|
||||
|
||||
ProjPredEngineAvx2(float gravity_constant, float simulation_time_step, float maximum_simulation_time);
|
||||
~ProjPredEngineAvx2() override = default;
|
||||
@@ -18,7 +18,7 @@ namespace omath::projectile_prediction
|
||||
private:
|
||||
[[nodiscard]] static std::optional<float> calculate_pitch(const Vector3<float>& proj_origin,
|
||||
const Vector3<float>& target_pos,
|
||||
float bullet_gravity, float v0, float time);
|
||||
float bullet_gravity, float v0, float time) ;
|
||||
|
||||
// We use [[maybe_unused]] here since AVX2 is not available for ARM and ARM64 CPU
|
||||
[[maybe_unused]] const float m_gravity_constant;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "omath/engines/source_engine/traits/pred_engine_trait.hpp"
|
||||
#include "omath/projectile_prediction/proj_pred_engine.hpp"
|
||||
#include "omath/projectile_prediction/projectile.hpp"
|
||||
#include "omath/projectile_prediction/target.hpp"
|
||||
@@ -12,15 +13,40 @@
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
class ProjPredEngineLegacy final : public ProjPredEngine
|
||||
template<class EngineTrait = source_engine::PredEngineTrait>
|
||||
class ProjPredEngineLegacy final : public ProjPredEngineInterface
|
||||
{
|
||||
public:
|
||||
explicit ProjPredEngineLegacy(float gravity_constant, float simulation_time_step, float maximum_simulation_time,
|
||||
float distance_tolerance);
|
||||
explicit ProjPredEngineLegacy(const float gravity_constant, const float simulation_time_step,
|
||||
const float maximum_simulation_time, const float distance_tolerance)
|
||||
: m_gravity_constant(gravity_constant), m_simulation_time_step(simulation_time_step),
|
||||
m_maximum_simulation_time(maximum_simulation_time), m_distance_tolerance(distance_tolerance)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::optional<Vector3<float>> maybe_calculate_aim_point(const Projectile& projectile,
|
||||
const Target& target) const override;
|
||||
const Target& target) const override
|
||||
{
|
||||
for (float time = 0.f; time < m_maximum_simulation_time; time += m_simulation_time_step)
|
||||
{
|
||||
const auto predicted_target_position =
|
||||
EngineTrait::predict_target_position(target, time, m_gravity_constant);
|
||||
|
||||
const auto projectile_pitch =
|
||||
maybe_calculate_projectile_launch_pitch_angle(projectile, predicted_target_position);
|
||||
|
||||
if (!projectile_pitch.has_value()) [[unlikely]]
|
||||
continue;
|
||||
|
||||
if (!is_projectile_reached_target(predicted_target_position, projectile, projectile_pitch.value(),
|
||||
time))
|
||||
continue;
|
||||
|
||||
return EngineTrait::calc_viewpoint_from_angles(projectile, predicted_target_position, projectile_pitch);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
private:
|
||||
const float m_gravity_constant;
|
||||
@@ -28,12 +54,56 @@ namespace omath::projectile_prediction
|
||||
const float m_maximum_simulation_time;
|
||||
const float m_distance_tolerance;
|
||||
|
||||
// Realization of this formula:
|
||||
// https://stackoverflow.com/questions/54917375/how-to-calculate-the-angle-to-shoot-a-bullet-in-order-to-hit-a-moving-target
|
||||
/*
|
||||
\[
|
||||
\theta \;=\; \arctan\!\Biggl(
|
||||
\frac{%
|
||||
v^{2}\;\pm\;\sqrt{\,v^{4}-g\!\left(gx^{2}+2yv^{2}\right)\,}
|
||||
}{%
|
||||
gx
|
||||
}\Biggr)
|
||||
\]
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::optional<float> maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile,
|
||||
const Vector3<float>& target_position) const;
|
||||
std::optional<float>
|
||||
maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile,
|
||||
const Vector3<float>& target_position) const noexcept
|
||||
{
|
||||
const auto bullet_gravity = m_gravity_constant * projectile.m_gravity_scale;
|
||||
|
||||
if (bullet_gravity == 0.f)
|
||||
return EngineTrait::calc_direct_pitch_angle(projectile.m_origin, target_position);
|
||||
|
||||
const auto delta = target_position - projectile.m_origin;
|
||||
|
||||
const auto distance2d = EngineTrait::calc_vector_2d_distance(delta);
|
||||
const auto distance2d_sqr = distance2d * distance2d;
|
||||
const auto launch_speed_sqr = projectile.m_launch_speed * projectile.m_launch_speed;
|
||||
|
||||
float root = launch_speed_sqr * launch_speed_sqr
|
||||
- bullet_gravity
|
||||
* (bullet_gravity * distance2d_sqr
|
||||
+ 2.0f * EngineTrait::get_vector_height_coordinate(delta) * launch_speed_sqr);
|
||||
|
||||
if (root < 0.0f) [[unlikely]]
|
||||
return std::nullopt;
|
||||
|
||||
root = std::sqrt(root);
|
||||
const float angle = std::atan((launch_speed_sqr - root) / (bullet_gravity * distance2d));
|
||||
|
||||
return angles::radians_to_degrees(angle);
|
||||
}
|
||||
[[nodiscard]]
|
||||
bool is_projectile_reached_target(const Vector3<float>& target_position, const Projectile& projectile,
|
||||
float pitch, float time) const;
|
||||
const float pitch, const float time) const noexcept
|
||||
{
|
||||
const auto yaw = EngineTrait::calc_direct_yaw_angle(projectile.m_origin, target_position);
|
||||
const auto projectile_position =
|
||||
EngineTrait::predict_projectile_position(projectile, pitch, yaw, time, m_gravity_constant);
|
||||
|
||||
return projectile_position.distance_to(target_position) <= m_distance_tolerance;
|
||||
}
|
||||
};
|
||||
} // namespace omath::projectile_prediction
|
||||
|
||||
@@ -10,9 +10,6 @@ namespace omath::projectile_prediction
|
||||
class Projectile final
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
Vector3<float> predict_position(float pitch, float yaw, float time, float gravity) const;
|
||||
|
||||
Vector3<float> m_origin;
|
||||
float m_launch_speed{};
|
||||
float m_gravity_scale{};
|
||||
|
||||
@@ -10,17 +10,6 @@ namespace omath::projectile_prediction
|
||||
class Target final
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
constexpr Vector3<float> predict_position(const float time, const float gravity) const
|
||||
{
|
||||
auto predicted = m_origin + m_velocity * time;
|
||||
|
||||
if (m_is_airborne)
|
||||
predicted.z -= gravity * std::pow(time, 2.f) * 0.5f;
|
||||
|
||||
return predicted;
|
||||
}
|
||||
|
||||
Vector3<float> m_origin;
|
||||
Vector3<float> m_velocity;
|
||||
bool m_is_airborne{};
|
||||
|
||||
@@ -26,32 +26,33 @@ namespace omath::projection
|
||||
};
|
||||
using FieldOfView = Angle<float, 0.f, 180.f, AngleFlags::Clamped>;
|
||||
|
||||
template<class Mat4X4Type, class ViewAnglesType>
|
||||
template<class Mat4X4Type, class ViewAnglesType, class TraitClass>
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
virtual ~Camera() = default;
|
||||
Camera(const Vector3<float>& position, const ViewAnglesType& view_angles, const ViewPort& view_port,
|
||||
const FieldOfView& fov, const float near, const float far)
|
||||
const FieldOfView& fov, const float near, const float far) noexcept
|
||||
: m_view_port(view_port), m_field_of_view(fov), m_far_plane_distance(far), m_near_plane_distance(near),
|
||||
m_view_angles(view_angles), m_origin(position)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void look_at(const Vector3<float>& target) = 0;
|
||||
|
||||
[[nodiscard]] virtual Mat4X4Type calc_view_matrix() const = 0;
|
||||
|
||||
[[nodiscard]] virtual Mat4X4Type calc_projection_matrix() const = 0;
|
||||
|
||||
[[nodiscard]] Mat4X4Type calc_view_projection_matrix() const
|
||||
void look_at(const Vector3<float>& target)
|
||||
{
|
||||
return calc_projection_matrix() * calc_view_matrix();
|
||||
m_view_angles = TraitClass::calc_look_at_angle(m_origin, target);
|
||||
}
|
||||
|
||||
[[nodiscard]] Mat4X4Type calc_view_projection_matrix() const noexcept
|
||||
{
|
||||
return TraitClass::calc_projection_matrix(m_field_of_view, m_view_port, m_near_plane_distance,
|
||||
m_far_plane_distance)
|
||||
* TraitClass::calc_view_matrix(m_view_angles, m_origin);
|
||||
}
|
||||
|
||||
public:
|
||||
[[nodiscard]] const Mat4X4Type& get_view_projection_matrix() const
|
||||
[[nodiscard]] const Mat4X4Type& get_view_projection_matrix() const noexcept
|
||||
{
|
||||
if (!m_view_projection_matrix.has_value())
|
||||
m_view_projection_matrix = calc_view_projection_matrix();
|
||||
@@ -59,68 +60,69 @@ namespace omath::projection
|
||||
return m_view_projection_matrix.value();
|
||||
}
|
||||
|
||||
void set_field_of_view(const FieldOfView& fov)
|
||||
void set_field_of_view(const FieldOfView& fov) noexcept
|
||||
{
|
||||
m_field_of_view = fov;
|
||||
m_view_projection_matrix = std::nullopt;
|
||||
}
|
||||
|
||||
void set_near_plane(const float near)
|
||||
void set_near_plane(const float near) noexcept
|
||||
{
|
||||
m_near_plane_distance = near;
|
||||
m_view_projection_matrix = std::nullopt;
|
||||
}
|
||||
|
||||
void set_far_plane(const float far)
|
||||
void set_far_plane(const float far) noexcept
|
||||
{
|
||||
m_far_plane_distance = far;
|
||||
m_view_projection_matrix = std::nullopt;
|
||||
}
|
||||
|
||||
void set_view_angles(const ViewAnglesType& view_angles)
|
||||
void set_view_angles(const ViewAnglesType& view_angles) noexcept
|
||||
{
|
||||
m_view_angles = view_angles;
|
||||
m_view_projection_matrix = std::nullopt;
|
||||
}
|
||||
|
||||
void set_origin(const Vector3<float>& origin)
|
||||
void set_origin(const Vector3<float>& origin) noexcept
|
||||
{
|
||||
m_origin = origin;
|
||||
m_view_projection_matrix = std::nullopt;
|
||||
}
|
||||
|
||||
void set_view_port(const ViewPort& view_port)
|
||||
void set_view_port(const ViewPort& view_port) noexcept
|
||||
{
|
||||
m_view_port = view_port;
|
||||
m_view_projection_matrix = std::nullopt;
|
||||
}
|
||||
|
||||
[[nodiscard]] const FieldOfView& get_field_of_view() const
|
||||
[[nodiscard]] const FieldOfView& get_field_of_view() const noexcept
|
||||
{
|
||||
return m_field_of_view;
|
||||
}
|
||||
|
||||
[[nodiscard]] const float& get_near_plane() const
|
||||
[[nodiscard]] const float& get_near_plane() const noexcept
|
||||
{
|
||||
return m_near_plane_distance;
|
||||
}
|
||||
|
||||
[[nodiscard]] const float& get_far_plane() const
|
||||
[[nodiscard]] const float& get_far_plane() const noexcept
|
||||
{
|
||||
return m_far_plane_distance;
|
||||
}
|
||||
|
||||
[[nodiscard]] const ViewAnglesType& get_view_angles() const
|
||||
[[nodiscard]] const ViewAnglesType& get_view_angles() const noexcept
|
||||
{
|
||||
return m_view_angles;
|
||||
}
|
||||
|
||||
[[nodiscard]] const Vector3<float>& get_origin() const
|
||||
[[nodiscard]] const Vector3<float>& get_origin() const noexcept
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<Vector3<float>, Error> world_to_screen(const Vector3<float>& world_position) const
|
||||
[[nodiscard]] std::expected<Vector3<float>, Error>
|
||||
world_to_screen(const Vector3<float>& world_position) const noexcept
|
||||
{
|
||||
auto normalized_cords = world_to_view_port(world_position);
|
||||
|
||||
@@ -131,7 +133,7 @@ namespace omath::projection
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<Vector3<float>, Error>
|
||||
world_to_view_port(const Vector3<float>& world_position) const
|
||||
world_to_view_port(const Vector3<float>& world_position) const noexcept
|
||||
{
|
||||
auto projected = get_view_projection_matrix()
|
||||
* mat_column_from_vector<float, Mat4X4Type::get_store_ordering()>(world_position);
|
||||
@@ -160,13 +162,13 @@ namespace omath::projection
|
||||
Vector3<float> m_origin;
|
||||
|
||||
private:
|
||||
template<class Type> [[nodiscard]]
|
||||
constexpr static bool is_ndc_out_of_bounds(const Type& ndc)
|
||||
template<class Type>
|
||||
[[nodiscard]] constexpr static bool is_ndc_out_of_bounds(const Type& ndc) noexcept
|
||||
{
|
||||
return std::ranges::any_of(ndc.raw_array(), [](const auto& val) { return val < -1 || val > 1; });
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector3<float> ndc_to_screen_position(const Vector3<float>& ndc) const
|
||||
[[nodiscard]] Vector3<float> ndc_to_screen_position(const Vector3<float>& ndc) const noexcept
|
||||
{
|
||||
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};
|
||||
}
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
namespace omath
|
||||
{
|
||||
/*
|
||||
v1
|
||||
|\
|
||||
| \
|
||||
a | \ hypot
|
||||
| \
|
||||
-----
|
||||
v2 ----- v3
|
||||
b
|
||||
*/
|
||||
|
||||
|
||||
@@ -24,184 +24,189 @@ namespace omath
|
||||
// Constructors
|
||||
constexpr Vector2() = default;
|
||||
|
||||
constexpr Vector2(const Type& x, const Type& y): x(x), y(y)
|
||||
constexpr Vector2(const Type& x, const Type& y) noexcept: x(x), y(y)
|
||||
{
|
||||
}
|
||||
|
||||
// Equality operators
|
||||
[[nodiscard]]
|
||||
constexpr bool operator==(const Vector2& src) const
|
||||
constexpr bool operator==(const Vector2& other) const noexcept
|
||||
{
|
||||
return x == src.x && y == src.y;
|
||||
return x == other.x && y == other.y;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator!=(const Vector2& src) const
|
||||
constexpr bool operator!=(const Vector2& other) const noexcept
|
||||
{
|
||||
return !(*this == src);
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
// Compound assignment operators
|
||||
constexpr Vector2& operator+=(const Vector2& v)
|
||||
constexpr Vector2& operator+=(const Vector2& other) noexcept
|
||||
{
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator-=(const Vector2& v)
|
||||
constexpr Vector2& operator-=(const Vector2& other) noexcept
|
||||
{
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator*=(const Vector2& v)
|
||||
constexpr Vector2& operator*=(const Vector2& other) noexcept
|
||||
{
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
x *= other.x;
|
||||
y *= other.y;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator/=(const Vector2& v)
|
||||
constexpr Vector2& operator/=(const Vector2& other) noexcept
|
||||
{
|
||||
x /= v.x;
|
||||
y /= v.y;
|
||||
x /= other.x;
|
||||
y /= other.y;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator*=(const Type& fl)
|
||||
constexpr Vector2& operator*=(const Type& value) noexcept
|
||||
{
|
||||
x *= fl;
|
||||
y *= fl;
|
||||
x *= value;
|
||||
y *= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator/=(const Type& fl)
|
||||
constexpr Vector2& operator/=(const Type& value) noexcept
|
||||
{
|
||||
x /= fl;
|
||||
y /= fl;
|
||||
x /= value;
|
||||
y /= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator+=(const Type& fl)
|
||||
constexpr Vector2& operator+=(const Type& value) noexcept
|
||||
{
|
||||
x += fl;
|
||||
y += fl;
|
||||
x += value;
|
||||
y += value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator-=(const Type& fl)
|
||||
constexpr Vector2& operator-=(const Type& value) noexcept
|
||||
{
|
||||
x -= fl;
|
||||
y -= fl;
|
||||
x -= value;
|
||||
y -= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Basic vector operations
|
||||
[[nodiscard]] Type distance_to(const Vector2& other) const
|
||||
[[nodiscard]] Type distance_to(const Vector2& other) const noexcept
|
||||
{
|
||||
return std::sqrt(distance_to_sqr(other));
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Type distance_to_sqr(const Vector2& other) const
|
||||
[[nodiscard]] constexpr Type distance_to_sqr(const Vector2& other) const noexcept
|
||||
{
|
||||
return (x - other.x) * (x - other.x) + (y - other.y) * (y - other.y);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Type dot(const Vector2& other) const
|
||||
[[nodiscard]] constexpr Type dot(const Vector2& other) const noexcept
|
||||
{
|
||||
return x * other.x + y * other.y;
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
[[nodiscard]] constexpr Type length() const
|
||||
[[nodiscard]] constexpr Type length() const noexcept
|
||||
{
|
||||
return std::hypot(this->x, this->y);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector2 normalized() const
|
||||
[[nodiscard]] constexpr Vector2 normalized() const noexcept
|
||||
{
|
||||
const Type len = length();
|
||||
return len > 0.f ? *this / len : *this;
|
||||
}
|
||||
#else
|
||||
[[nodiscard]] Type length() const
|
||||
[[nodiscard]] Type length() const noexcept
|
||||
{
|
||||
return std::hypot(x, y);
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector2 normalized() const
|
||||
[[nodiscard]] Vector2 normalized() const noexcept
|
||||
{
|
||||
const Type len = length();
|
||||
return len > 0.f ? *this / len : *this;
|
||||
return len > static_cast<Type>(0) ? *this / len : *this;
|
||||
}
|
||||
#endif
|
||||
[[nodiscard]] constexpr Type length_sqr() const
|
||||
[[nodiscard]] constexpr Type length_sqr() const noexcept
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
constexpr Vector2& abs()
|
||||
constexpr Vector2& abs() noexcept
|
||||
{
|
||||
// FIXME: Replace with std::abs, if it will become constexprable
|
||||
x = x < 0 ? -x : x;
|
||||
y = y < 0 ? -y : y;
|
||||
x = x < static_cast<Type>(0) ? -x : x;
|
||||
y = y < static_cast<Type>(0) ? -y : y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector2 operator-() const
|
||||
[[nodiscard]] constexpr Vector2 operator-() const noexcept
|
||||
{
|
||||
return {-x, -y};
|
||||
}
|
||||
|
||||
// Binary arithmetic operators
|
||||
[[nodiscard]] constexpr Vector2 operator+(const Vector2& v) const
|
||||
[[nodiscard]] constexpr Vector2 operator+(const Vector2& other) const noexcept
|
||||
{
|
||||
return {x + v.x, y + v.y};
|
||||
return {x + other.x, y + other.y};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector2 operator-(const Vector2& v) const
|
||||
[[nodiscard]] constexpr Vector2 operator-(const Vector2& other) const noexcept
|
||||
{
|
||||
return {x - v.x, y - v.y};
|
||||
return {x - other.x, y - other.y};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector2 operator*(const float fl) const
|
||||
[[nodiscard]] constexpr Vector2 operator*(const Type& value) const noexcept
|
||||
{
|
||||
return {x * fl, y * fl};
|
||||
return {x * value, y * value};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector2 operator/(const float fl) const
|
||||
[[nodiscard]] constexpr Vector2 operator/(const Type& value) const noexcept
|
||||
{
|
||||
return {x / fl, y / fl};
|
||||
return {x / value, y / value};
|
||||
}
|
||||
|
||||
// Sum of elements
|
||||
[[nodiscard]] constexpr Type sum() const
|
||||
[[nodiscard]] constexpr Type sum() const noexcept
|
||||
{
|
||||
return x + y;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::tuple<Type, Type> as_tuple() const
|
||||
constexpr std::tuple<Type, Type> as_tuple() const noexcept
|
||||
{
|
||||
return std::make_tuple(x, y);
|
||||
}
|
||||
|
||||
#ifdef OMATH_IMGUI_INTEGRATION
|
||||
[[nodiscard]]
|
||||
ImVec2 to_im_vec2() const
|
||||
ImVec2 to_im_vec2() const noexcept
|
||||
{
|
||||
return {static_cast<float>(this->x), static_cast<float>(this->y)};
|
||||
}
|
||||
[[nodiscard]]
|
||||
static Vector3<float> from_im_vec2(const ImVec2& other) noexcept
|
||||
{
|
||||
return {static_cast<Type>(other.x), static_cast<Type>(other.y)};
|
||||
}
|
||||
#endif
|
||||
};
|
||||
} // namespace omath
|
||||
|
||||
@@ -24,86 +24,86 @@ namespace omath
|
||||
{
|
||||
public:
|
||||
Type z = static_cast<Type>(0);
|
||||
constexpr Vector3(const Type& x, const Type& y, const Type& z): Vector2<Type>(x, y), z(z)
|
||||
constexpr Vector3(const Type& x, const Type& y, const Type& z) noexcept: Vector2<Type>(x, y), z(z)
|
||||
{
|
||||
}
|
||||
constexpr Vector3(): Vector2<Type>() {};
|
||||
constexpr Vector3() noexcept: Vector2<Type>() {};
|
||||
|
||||
[[nodiscard]] constexpr bool operator==(const Vector3& src) const
|
||||
[[nodiscard]] constexpr bool operator==(const Vector3& other) const noexcept
|
||||
{
|
||||
return Vector2<Type>::operator==(src) && (src.z == z);
|
||||
return Vector2<Type>::operator==(other) && (other.z == z);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator!=(const Vector3& src) const
|
||||
[[nodiscard]] constexpr bool operator!=(const Vector3& other) const noexcept
|
||||
{
|
||||
return !(*this == src);
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
constexpr Vector3& operator+=(const Vector3& v)
|
||||
constexpr Vector3& operator+=(const Vector3& other) noexcept
|
||||
{
|
||||
Vector2<Type>::operator+=(v);
|
||||
z += v.z;
|
||||
Vector2<Type>::operator+=(other);
|
||||
z += other.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector3& operator-=(const Vector3& v)
|
||||
constexpr Vector3& operator-=(const Vector3& other) noexcept
|
||||
{
|
||||
Vector2<Type>::operator-=(v);
|
||||
z -= v.z;
|
||||
Vector2<Type>::operator-=(other);
|
||||
z -= other.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector3& operator*=(const float fl)
|
||||
constexpr Vector3& operator*=(const Type& value) noexcept
|
||||
{
|
||||
Vector2<Type>::operator*=(fl);
|
||||
z *= fl;
|
||||
Vector2<Type>::operator*=(value);
|
||||
z *= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector3& operator*=(const Vector3& v)
|
||||
constexpr Vector3& operator*=(const Vector3& other) noexcept
|
||||
{
|
||||
Vector2<Type>::operator*=(v);
|
||||
z *= v.z;
|
||||
Vector2<Type>::operator*=(other);
|
||||
z *= other.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector3& operator/=(const Vector3& v)
|
||||
constexpr Vector3& operator/=(const Vector3& other) noexcept
|
||||
{
|
||||
Vector2<Type>::operator/=(v);
|
||||
z /= v.z;
|
||||
Vector2<Type>::operator/=(other);
|
||||
z /= other.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector3& operator+=(const float fl)
|
||||
constexpr Vector3& operator+=(const Type& value) noexcept
|
||||
{
|
||||
Vector2<Type>::operator+=(fl);
|
||||
z += fl;
|
||||
Vector2<Type>::operator+=(value);
|
||||
z += value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector3& operator/=(const float fl)
|
||||
constexpr Vector3& operator/=(const Type& value) noexcept
|
||||
{
|
||||
Vector2<Type>::operator/=(fl);
|
||||
z /= fl;
|
||||
Vector2<Type>::operator/=(value);
|
||||
z /= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector3& operator-=(const float fl)
|
||||
constexpr Vector3& operator-=(const Type& value) noexcept
|
||||
{
|
||||
Vector2<Type>::operator-=(fl);
|
||||
z -= fl;
|
||||
Vector2<Type>::operator-=(value);
|
||||
z -= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector3& abs()
|
||||
constexpr Vector3& abs() noexcept
|
||||
{
|
||||
Vector2<Type>::abs();
|
||||
z = z < 0.f ? -z : z;
|
||||
@@ -111,12 +111,12 @@ namespace omath
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Type distance_to_sqr(const Vector3& other) const
|
||||
[[nodiscard]] constexpr Type distance_to_sqr(const Vector3& other) const noexcept
|
||||
{
|
||||
return (*this - other).length_sqr();
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Type dot(const Vector3& other) const
|
||||
[[nodiscard]] constexpr Type dot(const Vector3& other) const noexcept
|
||||
{
|
||||
return Vector2<Type>::dot(other) + z * other.z;
|
||||
}
|
||||
@@ -142,110 +142,112 @@ namespace omath
|
||||
return length_value != 0 ? *this / length_value : *this;
|
||||
}
|
||||
#else
|
||||
[[nodiscard]] Type length() const
|
||||
[[nodiscard]] Type length() const noexcept
|
||||
{
|
||||
return std::hypot(this->x, this->y, z);
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector3 normalized() const
|
||||
[[nodiscard]] Vector3 normalized() const noexcept
|
||||
{
|
||||
const Type len = this->length();
|
||||
|
||||
return len != 0 ? *this / len : *this;
|
||||
return len != static_cast<Type>(0) ? *this / len : *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] Type length_2d() const
|
||||
[[nodiscard]] Type length_2d() const noexcept
|
||||
{
|
||||
return Vector2<Type>::length();
|
||||
}
|
||||
|
||||
[[nodiscard]] Type distance_to(const Vector3& vOther) const
|
||||
[[nodiscard]] Type distance_to(const Vector3& vOther) const noexcept
|
||||
{
|
||||
return (*this - vOther).length();
|
||||
}
|
||||
#endif
|
||||
|
||||
[[nodiscard]] constexpr Type length_sqr() const
|
||||
[[nodiscard]] constexpr Type length_sqr() const noexcept
|
||||
{
|
||||
return Vector2<Type>::length_sqr() + z * z;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator-() const
|
||||
[[nodiscard]] constexpr Vector3 operator-() const noexcept
|
||||
{
|
||||
return {-this->x, -this->y, -z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator+(const Vector3& v) const
|
||||
[[nodiscard]] constexpr Vector3 operator+(const Vector3& other) const noexcept
|
||||
{
|
||||
return {this->x + v.x, this->y + v.y, z + v.z};
|
||||
return {this->x + other.x, this->y + other.y, z + other.z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator-(const Vector3& v) const
|
||||
[[nodiscard]] constexpr Vector3 operator-(const Vector3& other) const noexcept
|
||||
{
|
||||
return {this->x - v.x, this->y - v.y, z - v.z};
|
||||
return {this->x - other.x, this->y - other.y, z - other.z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator*(const float fl) const
|
||||
[[nodiscard]] constexpr Vector3 operator*(const Type& value) const noexcept
|
||||
{
|
||||
return {this->x * fl, this->y * fl, z * fl};
|
||||
return {this->x * value, this->y * value, z * value};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator*(const Vector3& v) const
|
||||
[[nodiscard]] constexpr Vector3 operator*(const Vector3& other) const noexcept
|
||||
{
|
||||
return {this->x * v.x, this->y * v.y, z * v.z};
|
||||
return {this->x * other.x, this->y * other.y, z * other.z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator/(const float fl) const
|
||||
[[nodiscard]] constexpr Vector3 operator/(const Type& value) const noexcept
|
||||
{
|
||||
return {this->x / fl, this->y / fl, z / fl};
|
||||
return {this->x / value, this->y / value, z / value};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator/(const Vector3& v) const
|
||||
[[nodiscard]] constexpr Vector3 operator/(const Vector3& other) const noexcept
|
||||
{
|
||||
return {this->x / v.x, this->y / v.y, z / v.z};
|
||||
return {this->x / other.x, this->y / other.y, z / other.z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 cross(const Vector3& v) const
|
||||
[[nodiscard]] constexpr Vector3 cross(const Vector3& other) const noexcept
|
||||
{
|
||||
return {this->y * v.z - z * v.y, z * v.x - this->x * v.z, this->x * v.y - this->y * v.x};
|
||||
return {this->y * other.z - z * other.y, z * other.x - this->x * other.z,
|
||||
this->x * other.y - this->y * other.x};
|
||||
}
|
||||
[[nodiscard]] constexpr Type sum() const
|
||||
|
||||
[[nodiscard]] constexpr Type sum() const noexcept
|
||||
{
|
||||
return sum_2d() + z;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<Angle<float, 0.f, 180.f, AngleFlags::Clamped>, Vector3Error>
|
||||
angle_between(const Vector3& other) const
|
||||
angle_between(const Vector3& other) const noexcept
|
||||
{
|
||||
const auto bottom = length() * other.length();
|
||||
|
||||
if (bottom == 0.f)
|
||||
if (bottom == static_cast<Type>(0))
|
||||
return std::unexpected(Vector3Error::IMPOSSIBLE_BETWEEN_ANGLE);
|
||||
|
||||
return Angle<float, 0.f, 180.f, AngleFlags::Clamped>::from_radians(std::acos(dot(other) / bottom));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool is_perpendicular(const Vector3& other) const
|
||||
[[nodiscard]] bool is_perpendicular(const Vector3& other) const noexcept
|
||||
{
|
||||
if (const auto angle = angle_between(other))
|
||||
return angle->as_degrees() == 90.f;
|
||||
return angle->as_degrees() == static_cast<Type>(90);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Type sum_2d() const
|
||||
[[nodiscard]] constexpr Type sum_2d() const noexcept
|
||||
{
|
||||
return Vector2<Type>::sum();
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr std::tuple<Type, Type, Type> as_tuple() const
|
||||
[[nodiscard]] constexpr std::tuple<Type, Type, Type> as_tuple() const noexcept
|
||||
{
|
||||
return std::make_tuple(this->x, this->y, z);
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector3 view_angle_to(const Vector3& other) const
|
||||
[[nodiscard]] Vector3 view_angle_to(const Vector3& other) const noexcept
|
||||
{
|
||||
const float distance = distance_to(other);
|
||||
const auto distance = distance_to(other);
|
||||
const auto delta = other - *this;
|
||||
|
||||
return {angles::radians_to_degrees(std::asin(delta.z / distance)),
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace omath
|
||||
{
|
||||
template<class Type>
|
||||
requires std::is_arithmetic_v<Type>
|
||||
class Vector4 : public Vector3<Type>
|
||||
{
|
||||
public:
|
||||
@@ -17,90 +18,90 @@ namespace omath
|
||||
constexpr Vector4(const Type& x, const Type& y, const Type& z, const Type& w): Vector3<Type>(x, y, z), w(w)
|
||||
{
|
||||
}
|
||||
constexpr Vector4(): Vector3<Type>(), w(0) {};
|
||||
constexpr Vector4() noexcept: Vector3<Type>(), w(static_cast<Type>(0)) {};
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator==(const Vector4& src) const
|
||||
constexpr bool operator==(const Vector4& other) const noexcept
|
||||
{
|
||||
return Vector3<Type>::operator==(src) && w == src.w;
|
||||
return Vector3<Type>::operator==(other) && w == other.w;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator!=(const Vector4& src) const
|
||||
constexpr bool operator!=(const Vector4& other) const noexcept
|
||||
{
|
||||
return !(*this == src);
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
constexpr Vector4& operator+=(const Vector4& v)
|
||||
constexpr Vector4& operator+=(const Vector4& other) noexcept
|
||||
{
|
||||
Vector3<Type>::operator+=(v);
|
||||
w += v.w;
|
||||
Vector3<Type>::operator+=(other);
|
||||
w += other.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector4& operator-=(const Vector4& v)
|
||||
constexpr Vector4& operator-=(const Vector4& other) noexcept
|
||||
{
|
||||
Vector3<Type>::operator-=(v);
|
||||
w -= v.w;
|
||||
Vector3<Type>::operator-=(other);
|
||||
w -= other.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector4& operator*=(const float scalar)
|
||||
constexpr Vector4& operator*=(const Type& value) noexcept
|
||||
{
|
||||
Vector3<Type>::operator*=(scalar);
|
||||
w *= scalar;
|
||||
Vector3<Type>::operator*=(value);
|
||||
w *= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector4& operator*=(const Vector4& v)
|
||||
constexpr Vector4& operator*=(const Vector4& other) noexcept
|
||||
{
|
||||
Vector3<Type>::operator*=(v);
|
||||
w *= v.w;
|
||||
Vector3<Type>::operator*=(other);
|
||||
w *= other.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector4& operator/=(const float scalar)
|
||||
constexpr Vector4& operator/=(const Type& value) noexcept
|
||||
{
|
||||
Vector3<Type>::operator/=(scalar);
|
||||
w /= scalar;
|
||||
Vector3<Type>::operator/=(value);
|
||||
w /= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector4& operator/=(const Vector4& v)
|
||||
constexpr Vector4& operator/=(const Vector4& other) noexcept
|
||||
{
|
||||
Vector3<Type>::operator/=(v);
|
||||
w /= v.w;
|
||||
Vector3<Type>::operator/=(other);
|
||||
w /= other.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Type length_sqr() const
|
||||
[[nodiscard]] constexpr Type length_sqr() const noexcept
|
||||
{
|
||||
return Vector3<Type>::length_sqr() + w * w;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Type dot(const Vector4& other) const
|
||||
[[nodiscard]] constexpr Type dot(const Vector4& other) const noexcept
|
||||
{
|
||||
return Vector3<Type>::dot(other) + w * other.w;
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector3<Type> length() const
|
||||
[[nodiscard]] Vector3<Type> length() const noexcept
|
||||
{
|
||||
return std::sqrt(length_sqr());
|
||||
}
|
||||
|
||||
constexpr Vector4& abs()
|
||||
constexpr Vector4& abs() noexcept
|
||||
{
|
||||
Vector3<Type>::abs();
|
||||
w = w < 0.f ? -w : w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
constexpr Vector4& clamp(const Type& min, const Type& max)
|
||||
constexpr Vector4& clamp(const Type& min, const Type& max) noexcept
|
||||
{
|
||||
this->x = std::clamp(this->x, min, max);
|
||||
this->y = std::clamp(this->y, min, max);
|
||||
@@ -110,56 +111,56 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator-() const
|
||||
constexpr Vector4 operator-() const noexcept
|
||||
{
|
||||
return {-this->x, -this->y, -this->z, -w};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator+(const Vector4& v) const
|
||||
constexpr Vector4 operator+(const Vector4& other) const noexcept
|
||||
{
|
||||
return {this->x + v.x, this->y + v.y, this->z + v.z, w + v.w};
|
||||
return {this->x + other.x, this->y + other.y, this->z + other.z, w + other.w};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator-(const Vector4& v) const
|
||||
constexpr Vector4 operator-(const Vector4& other) const noexcept
|
||||
{
|
||||
return {this->x - v.x, this->y - v.y, this->z - v.z, w - v.w};
|
||||
return {this->x - other.x, this->y - other.y, this->z - other.z, w - other.w};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator*(const Type& scalar) const
|
||||
constexpr Vector4 operator*(const Type& value) const noexcept
|
||||
{
|
||||
return {this->x * scalar, this->y * scalar, this->z * scalar, w * scalar};
|
||||
return {this->x * value, this->y * value, this->z * value, w * value};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator*(const Vector4& v) const
|
||||
constexpr Vector4 operator*(const Vector4& other) const noexcept
|
||||
{
|
||||
return {this->x * v.x, this->y * v.y, this->z * v.z, w * v.w};
|
||||
return {this->x * other.x, this->y * other.y, this->z * other.z, w * other.w};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator/(const Type& scalar) const
|
||||
constexpr Vector4 operator/(const Type& value) const noexcept
|
||||
{
|
||||
return {this->x / scalar, this->y / scalar, this->z / scalar, w / scalar};
|
||||
return {this->x / value, this->y / value, this->z / value, w / value};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator/(const Vector4& v) const
|
||||
constexpr Vector4 operator/(const Vector4& other) const noexcept
|
||||
{
|
||||
return {this->x / v.x, this->y / v.y, this->z / v.z, w / v.w};
|
||||
return {this->x / other.x, this->y / other.y, this->z / other.z, w / other.w};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Type sum() const
|
||||
constexpr Type sum() const noexcept
|
||||
{
|
||||
return Vector3<Type>::sum() + w;
|
||||
}
|
||||
|
||||
#ifdef OMATH_IMGUI_INTEGRATION
|
||||
[[nodiscard]]
|
||||
ImVec4 to_im_vec4() const
|
||||
ImVec4 to_im_vec4() const noexcept
|
||||
{
|
||||
return {
|
||||
static_cast<float>(this->x),
|
||||
@@ -168,6 +169,12 @@ namespace omath
|
||||
static_cast<float>(w),
|
||||
};
|
||||
}
|
||||
[[nodiscard]]
|
||||
static Vector4<float> from_im_vec4(const ImVec4& other) noexcept
|
||||
{
|
||||
return {static_cast<Type>(other.x), static_cast<Type>(other.y), static_cast<Type>(other.z)};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
};
|
||||
} // namespace omath
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace omath::primitives
|
||||
{
|
||||
std::array<Triangle<Vector3<float>>, 12> create_box(const Vector3<float>& top, const Vector3<float>& bottom,
|
||||
const Vector3<float>& dir_forward,
|
||||
const Vector3<float>& dir_right, const float ratio)
|
||||
const Vector3<float>& dir_right, const float ratio) noexcept
|
||||
{
|
||||
const auto height = top.distance_to(bottom);
|
||||
const auto side_size = height / ratio;
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
|
||||
namespace omath::collision
|
||||
{
|
||||
bool LineTracer::can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& triangle)
|
||||
bool LineTracer::can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept
|
||||
{
|
||||
return get_ray_hit_point(ray, triangle) == ray.end;
|
||||
}
|
||||
Vector3<float> Ray::direction_vector() const
|
||||
Vector3<float> Ray::direction_vector() const noexcept
|
||||
{
|
||||
return end - start;
|
||||
}
|
||||
|
||||
Vector3<float> Ray::direction_vector_normalized() const
|
||||
Vector3<float> Ray::direction_vector_normalized() const noexcept
|
||||
{
|
||||
return direction_vector().normalized();
|
||||
}
|
||||
|
||||
Vector3<float> LineTracer::get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle)
|
||||
Vector3<float> LineTracer::get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept
|
||||
{
|
||||
constexpr float k_epsilon = std::numeric_limits<float>::epsilon();
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
//
|
||||
// Created by vlad on 2/4/24.
|
||||
//
|
||||
|
||||
#include "omath/color.hpp"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace omath
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 3/17/2025.
|
||||
//
|
||||
#include "omath/engines/iw_engine/camera.hpp"
|
||||
#include "omath/engines/iw_engine/formulas.hpp"
|
||||
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
|
||||
Camera::Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
||||
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, const float near, const float far)
|
||||
: projection::Camera<Mat4X4, ViewAngles>(position, view_angles, view_port, fov, near, far)
|
||||
{
|
||||
}
|
||||
void Camera::look_at([[maybe_unused]] const Vector3<float>& target)
|
||||
{
|
||||
const float distance = m_origin.distance_to(target);
|
||||
const auto delta = target - m_origin;
|
||||
|
||||
m_view_angles.pitch = PitchAngle::from_radians(std::asin(delta.z / distance));
|
||||
m_view_angles.yaw = -YawAngle::from_radians(std::atan2(delta.y, delta.x));
|
||||
m_view_angles.roll = RollAngle::from_radians(0.f);
|
||||
}
|
||||
Mat4X4 Camera::calc_view_matrix() const
|
||||
{
|
||||
return iw_engine::calc_view_matrix(m_view_angles, m_origin);
|
||||
}
|
||||
Mat4X4 Camera::calc_projection_matrix() const
|
||||
{
|
||||
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
||||
m_near_plane_distance, m_far_plane_distance);
|
||||
}
|
||||
} // namespace omath::iw_engine
|
||||
@@ -6,37 +6,37 @@
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
|
||||
Vector3<float> forward_vector(const ViewAngles& angles)
|
||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
|
||||
Vector3<float> right_vector(const ViewAngles& angles)
|
||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Vector3<float> up_vector(const ViewAngles& angles)
|
||||
Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles)
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll);
|
||||
}
|
||||
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
|
||||
}
|
||||
|
||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||
const float far)
|
||||
const float far) noexcept
|
||||
{
|
||||
// NOTE: Need magic number to fix fov calculation, since IW engine inherit Quake proj matrix calculation
|
||||
constexpr auto k_multiply_factor = 0.75f;
|
||||
|
||||
27
source/engines/iw_engine/traits/camera_trait.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Vlad on 8/11/2025.
|
||||
//
|
||||
#include "omath/engines/iw_engine/traits/camera_trait.hpp"
|
||||
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
|
||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto distance = cam_origin.distance_to(look_at);
|
||||
const auto delta = cam_origin - look_at;
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(delta.z / distance)),
|
||||
YawAngle::from_radians(std::atan2(delta.y, delta.x)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return iw_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near,
|
||||
const float far) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far);
|
||||
}
|
||||
} // namespace omath::iw_engine
|
||||
@@ -1,33 +0,0 @@
|
||||
//
|
||||
// Created by Orange on 12/23/2024.
|
||||
//
|
||||
#include "omath/engines/opengl_engine/camera.hpp"
|
||||
#include "omath/engines/opengl_engine/formulas.hpp"
|
||||
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
|
||||
Camera::Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
||||
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, const float near, const float far)
|
||||
: projection::Camera<Mat4X4, ViewAngles>(position, view_angles, view_port, fov, near, far)
|
||||
{
|
||||
}
|
||||
void Camera::look_at([[maybe_unused]] const Vector3<float>& target)
|
||||
{
|
||||
const float distance = m_origin.distance_to(target);
|
||||
const auto delta = target - m_origin;
|
||||
|
||||
m_view_angles.pitch = PitchAngle::from_radians(std::asin(delta.z / distance));
|
||||
m_view_angles.yaw = -YawAngle::from_radians(std::atan2(delta.y, delta.x));
|
||||
m_view_angles.roll = RollAngle::from_radians(0.f);
|
||||
}
|
||||
Mat4X4 Camera::calc_view_matrix() const
|
||||
{
|
||||
return opengl_engine::calc_view_matrix(m_view_angles, m_origin);
|
||||
}
|
||||
Mat4X4 Camera::calc_projection_matrix() const
|
||||
{
|
||||
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
||||
m_near_plane_distance, m_far_plane_distance);
|
||||
}
|
||||
} // namespace omath::opengl_engine
|
||||
@@ -6,39 +6,39 @@
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
|
||||
Vector3<float> forward_vector(const ViewAngles& angles)
|
||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec
|
||||
= rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_forward);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Vector3<float> right_vector(const ViewAngles& angles)
|
||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec
|
||||
= rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_right);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Vector3<float> up_vector(const ViewAngles& angles)
|
||||
Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_up);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view<float, MatStoreType::COLUMN_MAJOR>(-forward_vector(angles), right_vector(angles),
|
||||
up_vector(angles), cam_origin);
|
||||
}
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles)
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_x<float, MatStoreType::COLUMN_MAJOR>(-angles.pitch)
|
||||
* mat_rotation_axis_y<float, MatStoreType::COLUMN_MAJOR>(-angles.yaw)
|
||||
* mat_rotation_axis_z<float, MatStoreType::COLUMN_MAJOR>(angles.roll);
|
||||
}
|
||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||
const float far)
|
||||
const float far) noexcept
|
||||
{
|
||||
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
|
||||
|
||||
|
||||
28
source/engines/opengl_engine/traits/camera_trait.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by Vlad on 8/11/2025.
|
||||
//
|
||||
#include "omath/engines/opengl_engine/traits/camera_trait.hpp"
|
||||
|
||||
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
|
||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto distance = cam_origin.distance_to(look_at);
|
||||
const auto delta = cam_origin - look_at;
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(delta.y / distance)),
|
||||
YawAngle::from_radians(std::atan2(delta.z, delta.x)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return opengl_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near,
|
||||
const float far) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far);
|
||||
}
|
||||
} // namespace omath::opengl_engine
|
||||
@@ -1,35 +0,0 @@
|
||||
//
|
||||
// Created by Orange on 12/4/2024.
|
||||
//
|
||||
#include "omath/engines/source_engine/camera.hpp"
|
||||
#include "omath/engines/source_engine/formulas.hpp"
|
||||
|
||||
namespace omath::source_engine
|
||||
{
|
||||
|
||||
Camera::Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
||||
const projection::FieldOfView& fov, const float near, const float far)
|
||||
: projection::Camera<Mat4X4, ViewAngles>(position, view_angles, view_port, fov, near, far)
|
||||
{
|
||||
}
|
||||
void Camera::look_at(const Vector3<float>& target)
|
||||
{
|
||||
const float distance = m_origin.distance_to(target);
|
||||
const auto delta = target - m_origin;
|
||||
|
||||
m_view_angles.pitch = PitchAngle::from_radians(std::asin(delta.z / distance));
|
||||
m_view_angles.yaw = -YawAngle::from_radians(std::atan2(delta.y, delta.x));
|
||||
m_view_angles.roll = RollAngle::from_radians(0.f);
|
||||
}
|
||||
|
||||
Mat4X4 Camera::calc_view_matrix() const
|
||||
{
|
||||
return source_engine::calc_view_matrix(m_view_angles, m_origin);
|
||||
}
|
||||
|
||||
Mat4X4 Camera::calc_projection_matrix() const
|
||||
{
|
||||
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
||||
m_near_plane_distance, m_far_plane_distance);
|
||||
}
|
||||
} // namespace omath::source_engine
|
||||
@@ -5,38 +5,38 @@
|
||||
|
||||
namespace omath::source_engine
|
||||
{
|
||||
Vector3<float> forward_vector(const ViewAngles& angles)
|
||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles)
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll);
|
||||
}
|
||||
|
||||
Vector3<float> right_vector(const ViewAngles& angles)
|
||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Vector3<float> up_vector(const ViewAngles& angles)
|
||||
Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
|
||||
}
|
||||
|
||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||
const float far)
|
||||
const float far) noexcept
|
||||
{
|
||||
// NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation
|
||||
constexpr auto k_multiply_factor = 0.75f;
|
||||
|
||||
27
source/engines/source_engine/traits/camera_trait.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Vlad on 8/11/2025.
|
||||
//
|
||||
#include "omath/engines/source_engine/traits/camera_trait.hpp"
|
||||
|
||||
namespace omath::source_engine
|
||||
{
|
||||
|
||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto distance = cam_origin.distance_to(look_at);
|
||||
const auto delta = cam_origin - look_at;
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(delta.z / distance)),
|
||||
YawAngle::from_radians(std::atan2(delta.y, delta.x)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return source_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near,
|
||||
const float far) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far);
|
||||
}
|
||||
} // namespace omath::source_engine
|
||||
@@ -1,27 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 3/22/2025.
|
||||
//
|
||||
#include <omath/engines/unity_engine/camera.hpp>
|
||||
#include <omath/engines/unity_engine/formulas.hpp>
|
||||
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
Camera::Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
||||
const projection::FieldOfView& fov, const float near, const float far)
|
||||
: projection::Camera<Mat4X4, ViewAngles>(position, view_angles, view_port, fov, near, far)
|
||||
{
|
||||
}
|
||||
void Camera::look_at([[maybe_unused]] const Vector3<float>& target)
|
||||
{
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
Mat4X4 Camera::calc_view_matrix() const
|
||||
{
|
||||
return unity_engine::calc_view_matrix(m_view_angles, m_origin);
|
||||
}
|
||||
Mat4X4 Camera::calc_projection_matrix() const
|
||||
{
|
||||
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
||||
m_near_plane_distance, m_far_plane_distance);
|
||||
}
|
||||
} // namespace omath::unity_engine
|
||||
@@ -5,37 +5,37 @@
|
||||
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
Vector3<float> forward_vector(const ViewAngles& angles)
|
||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Vector3<float> right_vector(const ViewAngles& angles)
|
||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Vector3<float> up_vector(const ViewAngles& angles)
|
||||
Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), -right_vector(angles),
|
||||
up_vector(angles), cam_origin);
|
||||
}
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles)
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
return mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch)
|
||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||
* mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll);
|
||||
}
|
||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||
const float far)
|
||||
const float far) noexcept
|
||||
{
|
||||
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
|
||||
|
||||
|
||||
27
source/engines/unity_engine/traits/camera_trait.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Vlad on 8/11/2025.
|
||||
//
|
||||
#include "omath/engines/unity_engine/traits/camera_trait.hpp"
|
||||
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
|
||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto distance = cam_origin.distance_to(look_at);
|
||||
const auto delta = cam_origin - look_at;
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(delta.y / distance)),
|
||||
YawAngle::from_radians(std::atan2(delta.z, delta.x)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return unity_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near,
|
||||
const float far) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far);
|
||||
}
|
||||
} // namespace omath::unity_engine
|
||||
@@ -1,3 +1,5 @@
|
||||
#ifdef OMATH_ENABLE_LEGACY
|
||||
|
||||
#include "omath/matrix.hpp"
|
||||
#include "omath/angles.hpp"
|
||||
#include "omath/vector3.hpp"
|
||||
@@ -359,3 +361,4 @@ namespace omath
|
||||
m_data = nullptr;
|
||||
}
|
||||
} // namespace omath
|
||||
#endif
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace omath::pathfinding
|
||||
|
||||
std::vector<Vector3<float>>
|
||||
Astar::reconstruct_final_path(const std::unordered_map<Vector3<float>, PathNode>& closed_list,
|
||||
const Vector3<float>& current)
|
||||
const Vector3<float>& current) noexcept
|
||||
{
|
||||
std::vector<Vector3<float>> path;
|
||||
std::optional current_opt = current;
|
||||
@@ -38,7 +38,7 @@ namespace omath::pathfinding
|
||||
return path;
|
||||
}
|
||||
auto Astar::get_perfect_node(const std::unordered_map<Vector3<float>, PathNode>& open_list,
|
||||
const Vector3<float>& end_vertex)
|
||||
const Vector3<float>& end_vertex) noexcept
|
||||
{
|
||||
return std::ranges::min_element(open_list,
|
||||
[&end_vertex](const auto& a, const auto& b)
|
||||
@@ -50,7 +50,7 @@ namespace omath::pathfinding
|
||||
}
|
||||
|
||||
std::vector<Vector3<float>> Astar::find_path(const Vector3<float>& start, const Vector3<float>& end,
|
||||
const NavigationMesh& nav_mesh)
|
||||
const NavigationMesh& nav_mesh) noexcept
|
||||
{
|
||||
std::unordered_map<Vector3<float>, PathNode> closed_list;
|
||||
std::unordered_map<Vector3<float>, PathNode> open_list;
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
#include <stdexcept>
|
||||
namespace omath::pathfinding
|
||||
{
|
||||
std::expected<Vector3<float>, std::string> NavigationMesh::get_closest_vertex(const Vector3<float>& point) const
|
||||
std::expected<Vector3<float>, std::string>
|
||||
NavigationMesh::get_closest_vertex(const Vector3<float>& point) const noexcept
|
||||
{
|
||||
const auto res = std::ranges::min_element(m_vertex_map, [&point](const auto& a, const auto& b)
|
||||
{ return a.first.distance_to(point) < b.first.distance_to(point); });
|
||||
@@ -17,7 +18,7 @@ namespace omath::pathfinding
|
||||
return res->first;
|
||||
}
|
||||
|
||||
const std::vector<Vector3<float>>& NavigationMesh::get_neighbors(const Vector3<float>& vertex) const
|
||||
const std::vector<Vector3<float>>& NavigationMesh::get_neighbors(const Vector3<float>& vertex) const noexcept
|
||||
{
|
||||
return m_vertex_map.at(vertex);
|
||||
}
|
||||
@@ -27,7 +28,7 @@ namespace omath::pathfinding
|
||||
return m_vertex_map.empty();
|
||||
}
|
||||
|
||||
std::vector<uint8_t> NavigationMesh::serialize() const
|
||||
std::vector<uint8_t> NavigationMesh::serialize() const noexcept
|
||||
{
|
||||
auto dump_to_vector = []<typename T>(const T& t, std::vector<uint8_t>& vec)
|
||||
{
|
||||
@@ -50,7 +51,7 @@ namespace omath::pathfinding
|
||||
return raw;
|
||||
}
|
||||
|
||||
void NavigationMesh::deserialize(const std::vector<uint8_t>& raw)
|
||||
void NavigationMesh::deserialize(const std::vector<uint8_t>& raw) noexcept
|
||||
{
|
||||
auto load_from_vector = [](const std::vector<uint8_t>& vec, size_t& offset, auto& value)
|
||||
{
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 2/23/2025.
|
||||
//
|
||||
#include "omath/projectile_prediction/proj_pred_engine.hpp"
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
|
||||
} // namespace omath::projectile_prediction
|
||||
@@ -1,70 +0,0 @@
|
||||
#include "omath/projectile_prediction/proj_pred_engine_legacy.hpp"
|
||||
#include <cmath>
|
||||
#include <omath/angles.hpp>
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
ProjPredEngineLegacy::ProjPredEngineLegacy(const float gravity_constant, const float simulation_time_step,
|
||||
const float maximum_simulation_time, const float distance_tolerance)
|
||||
: m_gravity_constant(gravity_constant), m_simulation_time_step(simulation_time_step),
|
||||
m_maximum_simulation_time(maximum_simulation_time), m_distance_tolerance(distance_tolerance)
|
||||
{
|
||||
}
|
||||
|
||||
std::optional<Vector3<float>> ProjPredEngineLegacy::maybe_calculate_aim_point(const Projectile& projectile,
|
||||
const Target& target) const
|
||||
{
|
||||
for (float time = 0.f; time < m_maximum_simulation_time; time += m_simulation_time_step)
|
||||
{
|
||||
const auto predicted_target_position = target.predict_position(time, m_gravity_constant);
|
||||
|
||||
const auto projectile_pitch
|
||||
= maybe_calculate_projectile_launch_pitch_angle(projectile, predicted_target_position);
|
||||
|
||||
if (!projectile_pitch.has_value()) [[unlikely]]
|
||||
continue;
|
||||
|
||||
if (!is_projectile_reached_target(predicted_target_position, projectile, projectile_pitch.value(), time))
|
||||
continue;
|
||||
|
||||
const auto delta2d = (predicted_target_position - projectile.m_origin).length_2d();
|
||||
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
||||
|
||||
return Vector3(predicted_target_position.x, predicted_target_position.y, projectile.m_origin.z + height);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<float>
|
||||
ProjPredEngineLegacy::maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile,
|
||||
const Vector3<float>& target_position) const
|
||||
{
|
||||
const auto bullet_gravity = m_gravity_constant * projectile.m_gravity_scale;
|
||||
const auto delta = target_position - projectile.m_origin;
|
||||
|
||||
const auto distance2d = delta.length_2d();
|
||||
const auto distance2d_sqr = distance2d * distance2d;
|
||||
const auto launch_speed_sqr = projectile.m_launch_speed * projectile.m_launch_speed;
|
||||
|
||||
float root = launch_speed_sqr * launch_speed_sqr
|
||||
- bullet_gravity * (bullet_gravity * distance2d_sqr + 2.0f * delta.z * launch_speed_sqr);
|
||||
|
||||
if (root < 0.0f) [[unlikely]]
|
||||
return std::nullopt;
|
||||
|
||||
root = std::sqrt(root);
|
||||
const float angle = std::atan((launch_speed_sqr - root) / (bullet_gravity * distance2d));
|
||||
|
||||
return angles::radians_to_degrees(angle);
|
||||
}
|
||||
|
||||
bool ProjPredEngineLegacy::is_projectile_reached_target(const Vector3<float>& target_position,
|
||||
const Projectile& projectile, const float pitch,
|
||||
const float time) const
|
||||
{
|
||||
const auto yaw = projectile.m_origin.view_angle_to(target_position).y;
|
||||
const auto projectile_position = projectile.predict_position(pitch, yaw, time, m_gravity_constant);
|
||||
|
||||
return projectile_position.distance_to(target_position) <= m_distance_tolerance;
|
||||
}
|
||||
} // namespace omath::projectile_prediction
|
||||
@@ -1,22 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#include "omath/projectile_prediction/projectile.hpp"
|
||||
#include <omath/engines/source_engine/formulas.hpp>
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
Vector3<float> Projectile::predict_position(const float pitch, const float yaw, const float time,
|
||||
const float gravity) const
|
||||
{
|
||||
auto current_pos = m_origin
|
||||
+ source_engine::forward_vector({source_engine::PitchAngle::from_degrees(-pitch),
|
||||
source_engine::YawAngle::from_degrees(yaw),
|
||||
source_engine::RollAngle::from_degrees(0)})
|
||||
* m_launch_speed * time;
|
||||
current_pos.z -= (gravity * m_gravity_scale) * (time * time) * 0.5f;
|
||||
|
||||
return current_pos;
|
||||
}
|
||||
} // namespace omath::projectile_prediction
|
||||
@@ -1,10 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#include "omath/projectile_prediction/projectile.hpp"
|
||||
|
||||
namespace omath::prediction
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 27.08.2024.
|
||||
//
|
||||
#include "omath/projection/camera.hpp"
|
||||
|
||||
namespace omath::projection
|
||||
{
|
||||
}
|
||||
@@ -5,7 +5,7 @@ project(unit_tests)
|
||||
include(GoogleTest)
|
||||
|
||||
file(GLOB_RECURSE UNIT_TESTS_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
add_executable(unit_tests ${UNIT_TESTS_SOURCES})
|
||||
add_executable(${PROJECT_NAME} ${UNIT_TESTS_SOURCES})
|
||||
|
||||
set_target_properties(unit_tests PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||
@@ -17,6 +17,6 @@ set_target_properties(unit_tests PROPERTIES
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
|
||||
target_link_libraries(unit_tests PRIVATE gtest gtest_main omath::omath)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE gtest gtest_main omath::omath)
|
||||
|
||||
gtest_discover_tests(unit_tests)
|
||||
gtest_discover_tests(${PROJECT_NAME})
|
||||
@@ -7,27 +7,27 @@
|
||||
#include <omath/engines/iw_engine/formulas.hpp>
|
||||
|
||||
|
||||
TEST(UnitTestIwEngine, ForwardVector)
|
||||
TEST(unit_test_iw_engine, ForwardVector)
|
||||
{
|
||||
const auto forward = omath::iw_engine::forward_vector({});
|
||||
|
||||
EXPECT_EQ(forward, omath::iw_engine::k_abs_forward);
|
||||
}
|
||||
|
||||
TEST(UnitTestIwEngine, RightVector)
|
||||
TEST(unit_test_iw_engine, RightVector)
|
||||
{
|
||||
const auto right = omath::iw_engine::right_vector({});
|
||||
|
||||
EXPECT_EQ(right, omath::iw_engine::k_abs_right);
|
||||
}
|
||||
|
||||
TEST(UnitTestIwEngine, UpVector)
|
||||
TEST(unit_test_iw_engine, UpVector)
|
||||
{
|
||||
const auto up = omath::iw_engine::up_vector({});
|
||||
EXPECT_EQ(up, omath::iw_engine::k_abs_up);
|
||||
}
|
||||
|
||||
TEST(UnitTestIwEngine, ForwardVectorRotationYaw)
|
||||
TEST(unit_test_iw_engine, ForwardVectorRotationYaw)
|
||||
{
|
||||
omath::iw_engine::ViewAngles angles;
|
||||
|
||||
@@ -39,7 +39,7 @@ TEST(UnitTestIwEngine, ForwardVectorRotationYaw)
|
||||
EXPECT_NEAR(forward.z, omath::iw_engine::k_abs_right.z, 0.00001f);
|
||||
}
|
||||
|
||||
TEST(UnitTestIwEngine, ForwardVectorRotationPitch)
|
||||
TEST(unit_test_iw_engine, ForwardVectorRotationPitch)
|
||||
{
|
||||
omath::iw_engine::ViewAngles angles;
|
||||
|
||||
@@ -51,7 +51,7 @@ TEST(UnitTestIwEngine, ForwardVectorRotationPitch)
|
||||
EXPECT_NEAR(forward.z, omath::iw_engine::k_abs_up.z, 0.01f);
|
||||
}
|
||||
|
||||
TEST(UnitTestIwEngine, ForwardVectorRotationRoll)
|
||||
TEST(unit_test_iw_engine, ForwardVectorRotationRoll)
|
||||
{
|
||||
omath::iw_engine::ViewAngles angles;
|
||||
|
||||
@@ -63,7 +63,7 @@ TEST(UnitTestIwEngine, ForwardVectorRotationRoll)
|
||||
EXPECT_NEAR(forward.z, omath::iw_engine::k_abs_right.z, 0.00001f);
|
||||
}
|
||||
|
||||
TEST(UnitTestIwEngine, ProjectTargetMovedFromCamera)
|
||||
TEST(unit_test_iw_engine, ProjectTargetMovedFromCamera)
|
||||
{
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const auto cam = omath::iw_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
@@ -83,7 +83,7 @@ TEST(UnitTestIwEngine, ProjectTargetMovedFromCamera)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UnitTestIwEngine, CameraSetAndGetFov)
|
||||
TEST(unit_test_iw_engine, CameraSetAndGetFov)
|
||||
{
|
||||
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.01f, 1000.f);
|
||||
@@ -94,7 +94,7 @@ TEST(UnitTestIwEngine, CameraSetAndGetFov)
|
||||
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||
}
|
||||
|
||||
TEST(UnitTestIwEngine, CameraSetAndGetOrigin)
|
||||
TEST(unit_test_iw_engine, CameraSetAndGetOrigin)
|
||||
{
|
||||
auto cam = omath::iw_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||
|
||||
|
||||
@@ -7,25 +7,25 @@
|
||||
#include <omath/engines/opengl_engine/formulas.hpp>
|
||||
|
||||
|
||||
TEST(UnitTestOpenGL, ForwardVector)
|
||||
TEST(unit_test_opengl, ForwardVector)
|
||||
{
|
||||
const auto forward = omath::opengl_engine::forward_vector({});
|
||||
EXPECT_EQ(forward, omath::opengl_engine::k_abs_forward);
|
||||
}
|
||||
|
||||
TEST(UnitTestOpenGL, RightVector)
|
||||
TEST(unit_test_opengl, RightVector)
|
||||
{
|
||||
const auto right = omath::opengl_engine::right_vector({});
|
||||
EXPECT_EQ(right, omath::opengl_engine::k_abs_right);
|
||||
}
|
||||
|
||||
TEST(UnitTestOpenGL, UpVector)
|
||||
TEST(unit_test_opengl, UpVector)
|
||||
{
|
||||
const auto up = omath::opengl_engine::up_vector({});
|
||||
EXPECT_EQ(up, omath::opengl_engine::k_abs_up);
|
||||
}
|
||||
|
||||
TEST(UnitTestOpenGL, ForwardVectorRotationYaw)
|
||||
TEST(unit_test_opengl, ForwardVectorRotationYaw)
|
||||
{
|
||||
omath::opengl_engine::ViewAngles angles;
|
||||
|
||||
@@ -39,7 +39,7 @@ TEST(UnitTestOpenGL, ForwardVectorRotationYaw)
|
||||
|
||||
|
||||
|
||||
TEST(UnitTestOpenGL, ForwardVectorRotationPitch)
|
||||
TEST(unit_test_opengl, ForwardVectorRotationPitch)
|
||||
{
|
||||
omath::opengl_engine::ViewAngles angles;
|
||||
|
||||
@@ -51,7 +51,7 @@ TEST(UnitTestOpenGL, ForwardVectorRotationPitch)
|
||||
EXPECT_NEAR(forward.z, omath::opengl_engine::k_abs_up.z, 0.00001f);
|
||||
}
|
||||
|
||||
TEST(UnitTestOpenGL, ForwardVectorRotationRoll)
|
||||
TEST(unit_test_opengl, ForwardVectorRotationRoll)
|
||||
{
|
||||
omath::opengl_engine::ViewAngles angles;
|
||||
|
||||
@@ -63,7 +63,7 @@ TEST(UnitTestOpenGL, ForwardVectorRotationRoll)
|
||||
EXPECT_NEAR(forward.z, omath::opengl_engine::k_abs_right.z, 0.00001f);
|
||||
}
|
||||
|
||||
TEST(UnitTestOpenGL, ProjectTargetMovedFromCamera)
|
||||
TEST(unit_test_opengl, ProjectTargetMovedFromCamera)
|
||||
{
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const auto cam = omath::opengl_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
@@ -83,7 +83,7 @@ TEST(UnitTestOpenGL, ProjectTargetMovedFromCamera)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UnitTestOpenGL, CameraSetAndGetFov)
|
||||
TEST(unit_test_opengl, CameraSetAndGetFov)
|
||||
{
|
||||
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.01f, 1000.f);
|
||||
@@ -94,7 +94,7 @@ TEST(UnitTestOpenGL, CameraSetAndGetFov)
|
||||
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||
}
|
||||
|
||||
TEST(UnitTestOpenGL, CameraSetAndGetOrigin)
|
||||
TEST(unit_test_opengl, CameraSetAndGetOrigin)
|
||||
{
|
||||
auto cam = omath::opengl_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||
|
||||
|
||||
@@ -7,27 +7,27 @@
|
||||
#include <omath/engines/source_engine/formulas.hpp>
|
||||
|
||||
|
||||
TEST(UnitTestSourceEngine, ForwardVector)
|
||||
TEST(unit_test_source_engine, ForwardVector)
|
||||
{
|
||||
const auto forward = omath::source_engine::forward_vector({});
|
||||
|
||||
EXPECT_EQ(forward, omath::source_engine::k_abs_forward);
|
||||
}
|
||||
|
||||
TEST(UnitTestSourceEngine, RightVector)
|
||||
TEST(unit_test_source_engine, RightVector)
|
||||
{
|
||||
const auto right = omath::source_engine::right_vector({});
|
||||
|
||||
EXPECT_EQ(right, omath::source_engine::k_abs_right);
|
||||
}
|
||||
|
||||
TEST(UnitTestSourceEngine, UpVector)
|
||||
TEST(unit_test_source_engine, UpVector)
|
||||
{
|
||||
const auto up = omath::source_engine::up_vector({});
|
||||
EXPECT_EQ(up, omath::source_engine::k_abs_up);
|
||||
}
|
||||
|
||||
TEST(UnitTestSourceEngine, ForwardVectorRotationYaw)
|
||||
TEST(unit_test_source_engine, ForwardVectorRotationYaw)
|
||||
{
|
||||
omath::source_engine::ViewAngles angles;
|
||||
|
||||
@@ -39,7 +39,7 @@ TEST(UnitTestSourceEngine, ForwardVectorRotationYaw)
|
||||
EXPECT_NEAR(forward.z, omath::source_engine::k_abs_right.z, 0.00001f);
|
||||
}
|
||||
|
||||
TEST(UnitTestSourceEngine, ForwardVectorRotationPitch)
|
||||
TEST(unit_test_source_engine, ForwardVectorRotationPitch)
|
||||
{
|
||||
omath::source_engine::ViewAngles angles;
|
||||
|
||||
@@ -51,7 +51,7 @@ TEST(UnitTestSourceEngine, ForwardVectorRotationPitch)
|
||||
EXPECT_NEAR(forward.z, omath::source_engine::k_abs_up.z, 0.01f);
|
||||
}
|
||||
|
||||
TEST(UnitTestSourceEngine, ForwardVectorRotationRoll)
|
||||
TEST(unit_test_source_engine, ForwardVectorRotationRoll)
|
||||
{
|
||||
omath::source_engine::ViewAngles angles;
|
||||
|
||||
@@ -63,7 +63,7 @@ TEST(UnitTestSourceEngine, ForwardVectorRotationRoll)
|
||||
EXPECT_NEAR(forward.z, omath::source_engine::k_abs_right.z, 0.00001f);
|
||||
}
|
||||
|
||||
TEST(UnitTestSourceEngine, ProjectTargetMovedFromCamera)
|
||||
TEST(unit_test_source_engine, ProjectTargetMovedFromCamera)
|
||||
{
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
@@ -83,7 +83,7 @@ TEST(UnitTestSourceEngine, ProjectTargetMovedFromCamera)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UnitTestSourceEngine, ProjectTargetMovedUp)
|
||||
TEST(unit_test_source_engine, ProjectTargetMovedUp)
|
||||
{
|
||||
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);
|
||||
@@ -103,7 +103,7 @@ TEST(UnitTestSourceEngine, ProjectTargetMovedUp)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UnitTestSourceEngine, CameraSetAndGetFov)
|
||||
TEST(unit_test_source_engine, CameraSetAndGetFov)
|
||||
{
|
||||
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.01f, 1000.f);
|
||||
@@ -114,7 +114,7 @@ TEST(UnitTestSourceEngine, CameraSetAndGetFov)
|
||||
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||
}
|
||||
|
||||
TEST(UnitTestSourceEngine, CameraSetAndGetOrigin)
|
||||
TEST(unit_test_source_engine, CameraSetAndGetOrigin)
|
||||
{
|
||||
auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
#include <omath/engines/unity_engine/formulas.hpp>
|
||||
#include <print>
|
||||
|
||||
TEST(UnitTestUnityEngine, ForwardVector)
|
||||
TEST(unit_test_unity_engine, ForwardVector)
|
||||
{
|
||||
const auto forward = omath::unity_engine::forward_vector({});
|
||||
|
||||
EXPECT_EQ(forward, omath::unity_engine::k_abs_forward);
|
||||
}
|
||||
|
||||
TEST(UnitTestUnityEngine, ForwardVectorRotationYaw)
|
||||
TEST(unit_test_unity_engine, ForwardVectorRotationYaw)
|
||||
{
|
||||
omath::unity_engine::ViewAngles angles;
|
||||
|
||||
@@ -26,7 +26,7 @@ TEST(UnitTestUnityEngine, ForwardVectorRotationYaw)
|
||||
EXPECT_NEAR(forward.z, omath::unity_engine::k_abs_right.z, 0.00001f);
|
||||
}
|
||||
|
||||
TEST(UnitTestUnityEngine, ForwardVectorRotationPitch)
|
||||
TEST(unit_test_unity_engine, ForwardVectorRotationPitch)
|
||||
{
|
||||
omath::unity_engine::ViewAngles angles;
|
||||
|
||||
@@ -38,7 +38,7 @@ TEST(UnitTestUnityEngine, ForwardVectorRotationPitch)
|
||||
EXPECT_NEAR(forward.z, omath::unity_engine::k_abs_up.z, 0.00001f);
|
||||
}
|
||||
|
||||
TEST(UnitTestUnityEngine, ForwardVectorRotationRoll)
|
||||
TEST(unit_test_unity_engine, ForwardVectorRotationRoll)
|
||||
{
|
||||
omath::unity_engine::ViewAngles angles;
|
||||
|
||||
@@ -50,20 +50,20 @@ TEST(UnitTestUnityEngine, ForwardVectorRotationRoll)
|
||||
EXPECT_NEAR(forward.z, omath::unity_engine::k_abs_right.z, 0.00001f);
|
||||
}
|
||||
|
||||
TEST(UnitTestUnityEngine, RightVector)
|
||||
TEST(unit_test_unity_engine, RightVector)
|
||||
{
|
||||
const auto right = omath::unity_engine::right_vector({});
|
||||
|
||||
EXPECT_EQ(right, omath::unity_engine::k_abs_right);
|
||||
}
|
||||
|
||||
TEST(UnitTestUnityEngine, UpVector)
|
||||
TEST(unit_test_unity_engine, UpVector)
|
||||
{
|
||||
const auto up = omath::unity_engine::up_vector({});
|
||||
EXPECT_EQ(up, omath::unity_engine::k_abs_up);
|
||||
}
|
||||
|
||||
TEST(UnitTestUnityEngine, ProjectTargetMovedFromCamera)
|
||||
TEST(unit_test_unity_engine, ProjectTargetMovedFromCamera)
|
||||
{
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.01f, 1000.f);
|
||||
@@ -82,7 +82,7 @@ TEST(UnitTestUnityEngine, ProjectTargetMovedFromCamera)
|
||||
EXPECT_NEAR(projected->y, 360, 0.00001f);
|
||||
}
|
||||
}
|
||||
TEST(UnitTestUnityEngine, Project)
|
||||
TEST(unit_test_unity_engine, Project)
|
||||
{
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
|
||||
@@ -91,7 +91,7 @@ TEST(UnitTestUnityEngine, Project)
|
||||
std::println("{} {}", proj->x, proj->y);
|
||||
}
|
||||
|
||||
TEST(UnitTestUnityEngine, CameraSetAndGetFov)
|
||||
TEST(unit_test_unity_engine, CameraSetAndGetFov)
|
||||
{
|
||||
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.01f, 1000.f);
|
||||
@@ -102,7 +102,7 @@ TEST(UnitTestUnityEngine, CameraSetAndGetFov)
|
||||
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||
}
|
||||
|
||||
TEST(UnitTestUnityEngine, CameraSetAndGetOrigin)
|
||||
TEST(unit_test_unity_engine, CameraSetAndGetOrigin)
|
||||
{
|
||||
auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
using namespace omath;
|
||||
|
||||
class UnitTestColor : public ::testing::Test
|
||||
class unit_test_color : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
Color color1;
|
||||
@@ -21,7 +21,7 @@ protected:
|
||||
};
|
||||
|
||||
// Test constructors
|
||||
TEST_F(UnitTestColor, Constructor_Float)
|
||||
TEST_F(unit_test_color, Constructor_Float)
|
||||
{
|
||||
constexpr Color color(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
EXPECT_FLOAT_EQ(color.x, 0.5f);
|
||||
@@ -30,7 +30,7 @@ TEST_F(UnitTestColor, Constructor_Float)
|
||||
EXPECT_FLOAT_EQ(color.w, 1.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestColor, Constructor_Vector4)
|
||||
TEST_F(unit_test_color, Constructor_Vector4)
|
||||
{
|
||||
constexpr omath::Vector4 vec(0.2f, 0.4f, 0.6f, 0.8f);
|
||||
Color color(vec);
|
||||
@@ -41,7 +41,7 @@ TEST_F(UnitTestColor, Constructor_Vector4)
|
||||
}
|
||||
|
||||
// Test static methods for color creation
|
||||
TEST_F(UnitTestColor, FromRGBA)
|
||||
TEST_F(unit_test_color, FromRGBA)
|
||||
{
|
||||
constexpr Color color = Color::from_rgba(128, 64, 32, 255);
|
||||
EXPECT_FLOAT_EQ(color.x, 128.0f / 255.0f);
|
||||
@@ -50,7 +50,7 @@ TEST_F(UnitTestColor, FromRGBA)
|
||||
EXPECT_FLOAT_EQ(color.w, 1.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestColor, FromHSV)
|
||||
TEST_F(unit_test_color, FromHSV)
|
||||
{
|
||||
constexpr Color color = Color::from_hsv(0.0f, 1.0f, 1.0f); // Red in HSV
|
||||
EXPECT_FLOAT_EQ(color.x, 1.0f);
|
||||
@@ -60,7 +60,7 @@ TEST_F(UnitTestColor, FromHSV)
|
||||
}
|
||||
|
||||
// Test HSV conversion
|
||||
TEST_F(UnitTestColor, ToHSV)
|
||||
TEST_F(unit_test_color, ToHSV)
|
||||
{
|
||||
Hsv hsv = color1.to_hsv(); // Red color
|
||||
EXPECT_FLOAT_EQ(hsv.hue, 0.0f);
|
||||
@@ -69,7 +69,7 @@ TEST_F(UnitTestColor, ToHSV)
|
||||
}
|
||||
|
||||
// Test color blending
|
||||
TEST_F(UnitTestColor, Blend)
|
||||
TEST_F(unit_test_color, Blend)
|
||||
{
|
||||
Color blended = color1.blend(color2, 0.5f);
|
||||
EXPECT_FLOAT_EQ(blended.x, 0.5f);
|
||||
@@ -79,7 +79,7 @@ TEST_F(UnitTestColor, Blend)
|
||||
}
|
||||
|
||||
// Test predefined colors
|
||||
TEST_F(UnitTestColor, PredefinedColors)
|
||||
TEST_F(unit_test_color, PredefinedColors)
|
||||
{
|
||||
constexpr Color red = Color::red();
|
||||
constexpr Color green = Color::green();
|
||||
@@ -102,7 +102,7 @@ TEST_F(UnitTestColor, PredefinedColors)
|
||||
}
|
||||
|
||||
// Test non-member function: Blend for Vector3
|
||||
TEST_F(UnitTestColor, BlendVector3)
|
||||
TEST_F(unit_test_color, BlendVector3)
|
||||
{
|
||||
constexpr Color v1(1.0f, 0.0f, 0.0f, 1.f); // Red
|
||||
constexpr Color v2(0.0f, 1.0f, 0.0f, 1.f); // Green
|
||||
|
||||
@@ -31,10 +31,10 @@ namespace
|
||||
// -----------------------------------------------------------------------------
|
||||
// Fixture with one canonical right‑angled triangle in the XY plane.
|
||||
// -----------------------------------------------------------------------------
|
||||
class LineTracerFixture : public ::testing::Test
|
||||
class line_tracer_fixture : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
LineTracerFixture() :
|
||||
line_tracer_fixture() :
|
||||
triangle({0.f, 0.f, 0.f}, {1.f, 0.f, 0.f}, {0.f, 1.f, 0.f})
|
||||
{
|
||||
}
|
||||
@@ -51,7 +51,7 @@ namespace
|
||||
bool expected_clear; // true => segment does NOT hit the triangle
|
||||
};
|
||||
|
||||
class CanTraceLineParam : public LineTracerFixture,
|
||||
class CanTraceLineParam : public line_tracer_fixture,
|
||||
public ::testing::WithParamInterface<TraceCase>
|
||||
{
|
||||
};
|
||||
@@ -79,7 +79,7 @@ namespace
|
||||
// -----------------------------------------------------------------------------
|
||||
// Validate that the reported hit point is correct for a genuine intersection.
|
||||
// -----------------------------------------------------------------------------
|
||||
TEST_F(LineTracerFixture, HitPointCorrect)
|
||||
TEST_F(line_tracer_fixture, HitPointCorrect)
|
||||
{
|
||||
constexpr Ray ray{{0.3f, 0.3f, -1.f}, {0.3f, 0.3f, 1.f}};
|
||||
constexpr Vec3 expected{0.3f, 0.3f, 0.f};
|
||||
@@ -92,7 +92,7 @@ namespace
|
||||
// -----------------------------------------------------------------------------
|
||||
// Triangle far beyond the ray should not block.
|
||||
// -----------------------------------------------------------------------------
|
||||
TEST_F(LineTracerFixture, DistantTriangleClear)
|
||||
TEST_F(line_tracer_fixture, DistantTriangleClear)
|
||||
{
|
||||
constexpr Ray short_ray{{0.f, 0.f, 0.f}, {0.f, 0.f, 1.f}};
|
||||
constexpr Triangle<Vec3> distant{{1000.f, 1000.f, 1000.f},
|
||||
@@ -102,7 +102,7 @@ namespace
|
||||
EXPECT_TRUE(LineTracer::can_trace_line(short_ray, distant));
|
||||
}
|
||||
|
||||
TEST(LineTracerTraceRayEdge, CantHit)
|
||||
TEST(unit_test_unity_engine, CantHit)
|
||||
{
|
||||
constexpr omath::Triangle<Vector3<float>> triangle{{2, 0, 0}, {2, 2, 0}, {2, 2, 2}};
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace
|
||||
|
||||
EXPECT_TRUE(omath::collision::LineTracer::can_trace_line(ray, triangle));
|
||||
}
|
||||
TEST(LineTracerTraceRayEdge, CanHit)
|
||||
TEST(unit_test_unity_engine, CanHit)
|
||||
{
|
||||
constexpr omath::Triangle<Vector3<float>> triangle{{2, 0, 0}, {2, 2, 0}, {2, 2, 2}};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace omath;
|
||||
|
||||
class UnitTestMat : public ::testing::Test
|
||||
class unit_test_mat : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
Mat<2, 2> m1;
|
||||
@@ -19,7 +19,7 @@ protected:
|
||||
};
|
||||
|
||||
// Test constructors
|
||||
TEST_F(UnitTestMat, Constructor_Default)
|
||||
TEST_F(unit_test_mat, Constructor_Default)
|
||||
{
|
||||
Mat<3, 3> m;
|
||||
EXPECT_EQ(m.row_count(), 3);
|
||||
@@ -29,7 +29,7 @@ TEST_F(UnitTestMat, Constructor_Default)
|
||||
EXPECT_FLOAT_EQ(m.at(i, j), 0.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, Constructor_InitializerList)
|
||||
TEST_F(unit_test_mat, Constructor_InitializerList)
|
||||
{
|
||||
constexpr Mat<2, 2> m{{1.0f, 2.0f}, {3.0f, 4.0f}};
|
||||
EXPECT_EQ(m.row_count(), 2);
|
||||
@@ -40,7 +40,7 @@ TEST_F(UnitTestMat, Constructor_InitializerList)
|
||||
EXPECT_FLOAT_EQ(m.at(1, 1), 4.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, Operator_SquareBrackets)
|
||||
TEST_F(unit_test_mat, Operator_SquareBrackets)
|
||||
{
|
||||
EXPECT_EQ((m2[0, 0]), 1.0f);
|
||||
EXPECT_EQ((m2[0, 1]), 2.0f);
|
||||
@@ -48,7 +48,7 @@ TEST_F(UnitTestMat, Operator_SquareBrackets)
|
||||
EXPECT_EQ((m2[1, 1]), 4.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, Constructor_Copy)
|
||||
TEST_F(unit_test_mat, Constructor_Copy)
|
||||
{
|
||||
Mat<2, 2> m3 = m2;
|
||||
EXPECT_EQ(m3.row_count(), m2.row_count());
|
||||
@@ -57,7 +57,7 @@ TEST_F(UnitTestMat, Constructor_Copy)
|
||||
EXPECT_FLOAT_EQ(m3.at(1, 1), m2.at(1, 1));
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, Constructor_Move)
|
||||
TEST_F(unit_test_mat, Constructor_Move)
|
||||
{
|
||||
Mat<2, 2> m3 = std::move(m2);
|
||||
EXPECT_EQ(m3.row_count(), 2);
|
||||
@@ -68,7 +68,7 @@ TEST_F(UnitTestMat, Constructor_Move)
|
||||
}
|
||||
|
||||
// Test matrix operations
|
||||
TEST_F(UnitTestMat, Operator_Multiplication_Matrix)
|
||||
TEST_F(unit_test_mat, Operator_Multiplication_Matrix)
|
||||
{
|
||||
Mat<2, 2> m3 = m2 * m2;
|
||||
EXPECT_EQ(m3.row_count(), 2);
|
||||
@@ -79,14 +79,14 @@ TEST_F(UnitTestMat, Operator_Multiplication_Matrix)
|
||||
EXPECT_FLOAT_EQ(m3.at(1, 1), 22.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, Operator_Multiplication_Scalar)
|
||||
TEST_F(unit_test_mat, Operator_Multiplication_Scalar)
|
||||
{
|
||||
Mat<2, 2> m3 = m2 * 2.0f;
|
||||
EXPECT_FLOAT_EQ(m3.at(0, 0), 2.0f);
|
||||
EXPECT_FLOAT_EQ(m3.at(1, 1), 8.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, Operator_Division_Scalar)
|
||||
TEST_F(unit_test_mat, Operator_Division_Scalar)
|
||||
{
|
||||
Mat<2, 2> m3 = m2 / 2.0f;
|
||||
EXPECT_FLOAT_EQ(m3.at(0, 0), 0.5f);
|
||||
@@ -94,7 +94,7 @@ TEST_F(UnitTestMat, Operator_Division_Scalar)
|
||||
}
|
||||
|
||||
// Test matrix functions
|
||||
TEST_F(UnitTestMat, Transpose)
|
||||
TEST_F(unit_test_mat, Transpose)
|
||||
{
|
||||
Mat<2, 2> m3 = m2.transposed();
|
||||
EXPECT_FLOAT_EQ(m3.at(0, 0), m2.at(0, 0));
|
||||
@@ -103,19 +103,19 @@ TEST_F(UnitTestMat, Transpose)
|
||||
EXPECT_FLOAT_EQ(m3.at(1, 1), m2.at(1, 1));
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, Determinant)
|
||||
TEST_F(unit_test_mat, Determinant)
|
||||
{
|
||||
const float det = m2.determinant();
|
||||
EXPECT_FLOAT_EQ(det, -2.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, Sum)
|
||||
TEST_F(unit_test_mat, Sum)
|
||||
{
|
||||
const float sum = m2.sum();
|
||||
EXPECT_FLOAT_EQ(sum, 10.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, Clear)
|
||||
TEST_F(unit_test_mat, Clear)
|
||||
{
|
||||
m2.clear();
|
||||
for (size_t i = 0; i < m2.row_count(); ++i)
|
||||
@@ -123,7 +123,7 @@ TEST_F(UnitTestMat, Clear)
|
||||
EXPECT_FLOAT_EQ(m2.at(i, j), 0.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, ToString)
|
||||
TEST_F(unit_test_mat, ToString)
|
||||
{
|
||||
const std::string str = m2.to_string();
|
||||
EXPECT_FALSE(str.empty());
|
||||
@@ -131,7 +131,7 @@ TEST_F(UnitTestMat, ToString)
|
||||
}
|
||||
|
||||
// Test assignment operators
|
||||
TEST_F(UnitTestMat, AssignmentOperator_Copy)
|
||||
TEST_F(unit_test_mat, AssignmentOperator_Copy)
|
||||
{
|
||||
Mat<2, 2> m3;
|
||||
m3 = m2;
|
||||
@@ -140,7 +140,7 @@ TEST_F(UnitTestMat, AssignmentOperator_Copy)
|
||||
EXPECT_FLOAT_EQ(m3.at(0, 0), m2.at(0, 0));
|
||||
}
|
||||
|
||||
TEST_F(UnitTestMat, AssignmentOperator_Move)
|
||||
TEST_F(unit_test_mat, AssignmentOperator_Move)
|
||||
{
|
||||
Mat<2, 2> m3;
|
||||
m3 = std::move(m2);
|
||||
@@ -152,7 +152,7 @@ TEST_F(UnitTestMat, AssignmentOperator_Move)
|
||||
}
|
||||
|
||||
// Test static methods
|
||||
TEST_F(UnitTestMat, StaticMethod_ToScreenMat)
|
||||
TEST_F(unit_test_mat, StaticMethod_ToScreenMat)
|
||||
{
|
||||
Mat<4, 4> screenMat = Mat<4, 4>::to_screen_mat(800.0f, 600.0f);
|
||||
EXPECT_FLOAT_EQ(screenMat.at(0, 0), 400.0f);
|
||||
@@ -164,11 +164,11 @@ TEST_F(UnitTestMat, StaticMethod_ToScreenMat)
|
||||
|
||||
|
||||
// Test exception handling in At() method
|
||||
TEST_F(UnitTestMat, Method_At_OutOfRange)
|
||||
TEST_F(unit_test_mat, Method_At_OutOfRange)
|
||||
{
|
||||
#if !defined(NDEBUG) && defined(OMATH_SUPRESS_SAFETY_CHECKS)
|
||||
EXPECT_THROW(std::ignore = m2.At(2, 0), std::out_of_range);
|
||||
EXPECT_THROW(std::ignore = m2.At(0, 2), std::out_of_range);
|
||||
EXPECT_THROW(std::ignore = m2.at(2, 0), std::out_of_range);
|
||||
EXPECT_THROW(std::ignore = m2.at(0, 2), std::out_of_range);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
//
|
||||
// Created by vlad on 5/18/2024.
|
||||
//
|
||||
|
||||
#ifdef OMATH_ENABLE_LEGACY
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/matrix.hpp>
|
||||
#include "omath/vector3.hpp"
|
||||
@@ -177,4 +180,5 @@ TEST_F(UnitTestMatrix, AssignmentOperator_Move)
|
||||
EXPECT_FLOAT_EQ(m3.at(0, 0), 1.0f);
|
||||
EXPECT_EQ(m2.row_count(), 0); // m2 should be empty after the move
|
||||
EXPECT_EQ(m2.columns_count(), 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
7
writerside/c.list
Normal file
@@ -0,0 +1,7 @@
|
||||
<?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>
|
||||
13
writerside/cfg/buildprofiles.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?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>
|
||||
BIN
writerside/images/completion_procedure.png
Normal file
|
After Width: | Height: | Size: 125 KiB |
BIN
writerside/images/completion_procedure_dark.png
Normal file
|
After Width: | Height: | Size: 67 KiB |
BIN
writerside/images/convert_table_to_xml.png
Normal file
|
After Width: | Height: | Size: 341 KiB |
BIN
writerside/images/convert_table_to_xml_dark.png
Normal file
|
After Width: | Height: | Size: 119 KiB |
BIN
writerside/images/new_topic_options.png
Normal file
|
After Width: | Height: | Size: 306 KiB |
BIN
writerside/images/new_topic_options_dark.png
Normal file
|
After Width: | Height: | Size: 274 KiB |
14
writerside/o.tree
Normal file
@@ -0,0 +1,14 @@
|
||||
<?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>
|
||||
13
writerside/redirection-rules.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?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>
|
||||
95
writerside/topics/Code-Of-Conduct.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# 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.
|
||||
11
writerside/topics/Community.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# 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>
|
||||
54
writerside/topics/Documentation.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# 📥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 |
|
||||
9
writerside/topics/License.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# 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.
|
||||
67
writerside/topics/starter-topic.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# 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)
|
||||
5
writerside/v.list
Normal file
@@ -0,0 +1,5 @@
|
||||
<?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>
|
||||
8
writerside/writerside.cfg
Normal file
@@ -0,0 +1,8 @@
|
||||
<?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>
|
||||