mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 23:13:26 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b5a7ed4fd | |||
|
|
362b818a71 | ||
| 29a96d64bb | |||
| 256365e52e | |||
| e333d81b81 | |||
| d66f60d419 | |||
| 4a4939b604 | |||
| ebe8d1a90e | |||
| 1a3376fe6c | |||
| 20188d7043 | |||
| f59e0d255f | |||
| 071cb15492 | |||
| f8812ed9e7 | |||
| 19d310d35f | |||
| c364879b5f | |||
| 418b7c0e7e | |||
| 69f46abce1 | |||
| de61f7a5d8 | |||
| 07a449b633 |
BIN
.github/images/yt_previews/img.png
vendored
Normal file
BIN
.github/images/yt_previews/img.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
@@ -100,6 +100,7 @@ target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
|
||||
if (OMATH_BUILD_TESTS)
|
||||
add_subdirectory(extlibs)
|
||||
add_subdirectory(tests)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_BUILD_TESTS)
|
||||
endif ()
|
||||
|
||||
if (OMATH_BUILD_EXAMPLES)
|
||||
|
||||
73
README.md
73
README.md
@@ -12,9 +12,24 @@
|
||||
[](https://discord.gg/eDgdaWbqwZ)
|
||||
[](https://t.me/orangennotes)
|
||||
|
||||
OMath is a 100% independent, constexpr template blazingly fast math library that doesn't have legacy C++ code.
|
||||
|
||||
It provides the latest features, is highly customizable, has all for cheat development, DirectX/OpenGL/Vulkan support, premade support for different game engines, much more constexpr stuff than in other libraries and more...
|
||||
<br>
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
**[<kbd> <br> Install <br> </kbd>][INSTALL]**
|
||||
**[<kbd> <br> Examples <br> </kbd>][EXAMPLES]**
|
||||
**[<kbd> <br> Contribute <br> </kbd>][CONTRIBUTING]**
|
||||
|
||||
---
|
||||
|
||||
<br>
|
||||
|
||||
</div>
|
||||
|
||||
Oranges's Math Library (omath) is a comprehensive, open-source library aimed at providing efficient, reliable, and versatile mathematical functions and algorithms. Developed primarily in C++, this library is designed to cater to a wide range of mathematical operations essential in scientific computing, engineering, and academic research.
|
||||
|
||||
<div align = center>
|
||||
<a href="https://www.star-history.com/#orange-cpp/omath&Date">
|
||||
@@ -36,6 +51,29 @@ Oranges's Math Library (omath) is a comprehensive, open-source library aimed at
|
||||
- **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution
|
||||
- **Ready for meta-programming**: Omath use templates for common types like Vectors, Matrixes etc, to handle all types!
|
||||
|
||||
# Gallery
|
||||
|
||||
<br>
|
||||
|
||||
[](https://youtu.be/lM_NJ1yCunw?si=-Qf5yzDcWbaxAXGQ)
|
||||
|
||||
<br>
|
||||
|
||||
![APEX Preview]
|
||||
|
||||
<br>
|
||||
|
||||
![BO2 Preview]
|
||||
|
||||
<br>
|
||||
|
||||
![CS2 Preview]
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
|
||||
|
||||
## Supported Render Pipelines
|
||||
| ENGINE | SUPPORT |
|
||||
|----------|---------|
|
||||
@@ -53,9 +91,6 @@ Oranges's Math Library (omath) is a comprehensive, open-source library aimed at
|
||||
| Linux | ✅YES |
|
||||
| Darwin (MacOS) | ✅YES |
|
||||
|
||||
## ⏬ Installation
|
||||
Please read our [installation guide](https://github.com/orange-cpp/omath/blob/main/INSTALL.md). If this link doesn't work check out INSTALL.md file.
|
||||
|
||||
## ❔ Usage
|
||||
ESP example
|
||||
```c++
|
||||
@@ -77,26 +112,16 @@ for (auto ent: apex_sdk::EntityList::GetAllEntities())
|
||||
// esp rendering...
|
||||
}
|
||||
```
|
||||
## Showcase
|
||||
<details>
|
||||
<summary>OMATH for making cheats (click to open)</summary>
|
||||
|
||||
With `omath/projection` module you can achieve simple ESP hack for powered by Source/Unreal/Unity engine games, like [Apex Legends](https://store.steampowered.com/app/1172470/Apex_Legends/).
|
||||
|
||||

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

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

|
||||
Or even advanced projectile aimbot
|
||||
[Watch Video](https://youtu.be/lM_NJ1yCunw?si=5E87OrQMeypxSJ3E)
|
||||
</details>
|
||||
|
||||
## 🫵🏻 Contributing
|
||||
Contributions to `omath` are welcome! Please read `CONTRIBUTING.md` for details on our code of conduct and the process for submitting pull requests.
|
||||
|
||||
## 📜 License
|
||||
This project is licensed under the ZLIB - see the `LICENSE` file for details.
|
||||
|
||||
## 💘 Acknowledgments
|
||||
- [All contributors](https://github.com/orange-cpp/omath/graphs/contributors)
|
||||
|
||||
<!----------------------------------{ Images }--------------------------------->
|
||||
[APEX Preview]: .github/images/showcase/apex.png
|
||||
[BO2 Preview]: .github/images/showcase/cod_bo2.png
|
||||
[CS2 Preview]: .github/images/showcase/cs2.jpeg
|
||||
|
||||
<!----------------------------------{ Buttons }--------------------------------->
|
||||
[INSTALL]: INSTALL.md
|
||||
[CONTRIBUTING]: CONTRIBUTING.md
|
||||
[EXAMPLES]: examples
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#pragma once
|
||||
#include "omath/angles.hpp"
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <format>
|
||||
#include <utility>
|
||||
|
||||
namespace omath
|
||||
{
|
||||
@@ -150,17 +150,22 @@ namespace omath
|
||||
}
|
||||
};
|
||||
} // namespace omath
|
||||
template<class Type, Type min, Type max, omath::AngleFlags flags>
|
||||
struct std::formatter<omath::Angle<Type, min, max, flags>> // NOLINT(*-dcl58-cpp)
|
||||
|
||||
template<class T, T MinV, T MaxV, omath::AngleFlags F, class CharT>
|
||||
struct std::formatter<omath::Angle<T, MinV, MaxV, F>, CharT>
|
||||
{
|
||||
using AngleT = omath::Angle<T, MinV, MaxV, F>;
|
||||
[[nodiscard]]
|
||||
static constexpr auto parse(std::format_parse_context& ctx)
|
||||
static constexpr auto parse(std::basic_format_parse_context<CharT>& ctx)
|
||||
-> std::basic_format_parse_context<CharT>::iterator
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
[[nodiscard]]
|
||||
static auto format(const omath::Angle<Type, min, max, flags>& deg, std::format_context& ctx)
|
||||
template<class FormatContext>
|
||||
auto format(const AngleT& deg, FormatContext& ctx) const
|
||||
{
|
||||
return std::format_to(ctx.out(), "{}deg", deg.as_degrees());
|
||||
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
|
||||
return std::format_to(ctx.out(), "{}deg", deg.as_degrees());
|
||||
return std::format_to(ctx.out(), L"{}deg", deg.as_degrees());
|
||||
}
|
||||
};
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
|
||||
// Matrix classes
|
||||
#include "linear_algebra/matrix.hpp"
|
||||
#include "omath/linear_algebra/mat.hpp"
|
||||
|
||||
// Color functionality
|
||||
@@ -81,4 +80,4 @@
|
||||
#include "omath/engines/unreal_engine/formulas.hpp"
|
||||
#include "omath/engines/unreal_engine/camera.hpp"
|
||||
#include "omath/engines/unreal_engine/traits/camera_trait.hpp"
|
||||
#include "omath/engines/unreal_engine/traits/pred_engine_trait.hpp"
|
||||
#include "omath/engines/unreal_engine/traits/pred_engine_trait.hpp"
|
||||
|
||||
@@ -4,13 +4,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "omath/projection/error_codes.hpp"
|
||||
#include "omath/linear_algebra/mat.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include "omath/projection/error_codes.hpp"
|
||||
#include <expected>
|
||||
#include <omath/angle.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef OMATH_BUILD_TESTS
|
||||
// ReSharper disable once CppInconsistentNaming
|
||||
class UnitTestProjection_Projection_Test;
|
||||
#endif
|
||||
|
||||
namespace omath::projection
|
||||
{
|
||||
class ViewPort final
|
||||
@@ -45,6 +50,9 @@ namespace omath::projection
|
||||
requires CameraEngineConcept<TraitClass, Mat4X4Type, ViewAnglesType>
|
||||
class Camera final
|
||||
{
|
||||
#ifdef OMATH_BUILD_TESTS
|
||||
friend UnitTestProjection_Projection_Test;
|
||||
#endif
|
||||
public:
|
||||
~Camera() = default;
|
||||
Camera(const Vector3<float>& position, const ViewAnglesType& view_angles, const ViewPort& view_port,
|
||||
@@ -164,6 +172,38 @@ namespace omath::projection
|
||||
|
||||
return Vector3<float>{projected.at(0, 0), projected.at(1, 0), projected.at(2, 0)};
|
||||
}
|
||||
[[nodiscard]]
|
||||
std::expected<Vector3<float>, Error> view_port_to_screen(const Vector3<float>& ndc) const noexcept
|
||||
{
|
||||
const auto inv_view_proj = get_view_projection_matrix().inverted();
|
||||
|
||||
if (!inv_view_proj)
|
||||
return std::unexpected(Error::INV_VIEW_PROJ_MAT_DET_EQ_ZERO);
|
||||
|
||||
auto inverted_projection =
|
||||
inv_view_proj.value() * mat_column_from_vector<float, Mat4X4Type::get_store_ordering()>(ndc);
|
||||
|
||||
if (!inverted_projection.at(3, 0))
|
||||
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
||||
|
||||
inverted_projection /= inverted_projection.at(3, 0);
|
||||
|
||||
return Vector3<float>{inverted_projection.at(0, 0), inverted_projection.at(1, 0),
|
||||
inverted_projection.at(2, 0)};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::expected<Vector3<float>, Error> screen_to_world(const Vector3<float>& screen_pos) const noexcept
|
||||
{
|
||||
return view_port_to_screen(screen_to_ndc(screen_pos));
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::expected<Vector3<float>, Error> screen_to_world(const Vector2<float>& screen_pos) const noexcept
|
||||
{
|
||||
const auto& [x, y] = screen_pos;
|
||||
return screen_to_world({x, y, 1.f});
|
||||
}
|
||||
|
||||
protected:
|
||||
ViewPort m_view_port{};
|
||||
@@ -186,19 +226,25 @@ namespace omath::projection
|
||||
|
||||
[[nodiscard]] Vector3<float> ndc_to_screen_position(const Vector3<float>& ndc) const noexcept
|
||||
{
|
||||
/*
|
||||
^
|
||||
| y
|
||||
1 |
|
||||
|
|
||||
|
|
||||
-1 ---------0--------- 1 --> x
|
||||
|
|
||||
|
|
||||
-1 |
|
||||
v
|
||||
*/
|
||||
/*
|
||||
^
|
||||
| y
|
||||
1 |
|
||||
|
|
||||
|
|
||||
-1 ---------0--------- 1 --> x
|
||||
|
|
||||
|
|
||||
-1 |
|
||||
v
|
||||
*/
|
||||
return {(ndc.x + 1.f) / 2.f * m_view_port.m_width, (1.f - ndc.y) / 2.f * m_view_port.m_height, ndc.z};
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector3<float> screen_to_ndc(const Vector3<float>& screen_pos) const noexcept
|
||||
{
|
||||
return {screen_pos.x / m_view_port.m_width * 2.f - 1.f, 1.f - screen_pos.y / m_view_port.m_height * 2.f,
|
||||
screen_pos.z};
|
||||
}
|
||||
};
|
||||
} // namespace omath::projection
|
||||
|
||||
@@ -10,5 +10,6 @@ namespace omath::projection
|
||||
enum class Error : uint16_t
|
||||
{
|
||||
WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS,
|
||||
INV_VIEW_PROJ_MAT_DET_EQ_ZERO,
|
||||
};
|
||||
}
|
||||
@@ -50,12 +50,10 @@ namespace omath::collision
|
||||
|
||||
const auto t_hit = side_b.dot(q) * inv_det;
|
||||
|
||||
if (ray.infinite_length)
|
||||
{
|
||||
if (t_hit <= k_epsilon)
|
||||
return ray.end;
|
||||
}
|
||||
else if (t_hit <= k_epsilon || t_hit > 1.0f - k_epsilon)
|
||||
if (ray.infinite_length && t_hit <= k_epsilon)
|
||||
return ray.end;
|
||||
|
||||
if (t_hit <= k_epsilon || t_hit > 1.0f - k_epsilon)
|
||||
return ray.end;
|
||||
|
||||
return ray.start + ray_dir * t_hit;
|
||||
|
||||
@@ -13,8 +13,12 @@ TEST(UnitTestProjection, Projection)
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, fov,
|
||||
0.01f, 1000.f);
|
||||
|
||||
const auto projected = cam.world_to_screen({1000, 0, 50});
|
||||
const auto projected = cam.world_to_screen({1000.f, 0, 50.f});
|
||||
const auto result = cam.screen_to_world(projected.value());
|
||||
const auto result2 = cam.world_to_screen(result.value());
|
||||
|
||||
EXPECT_EQ(static_cast<omath::Vector2<float>>(projected.value()),
|
||||
static_cast<omath::Vector2<float>>(result2.value()));
|
||||
EXPECT_NEAR(projected->x, 960.f, 0.001f);
|
||||
EXPECT_NEAR(projected->y, 504.f, 0.001f);
|
||||
EXPECT_NEAR(projected->z, 1.f, 0.001f);
|
||||
|
||||
Reference in New Issue
Block a user