mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 15:03:27 +00:00
Compare commits
38 Commits
v4.6.1
...
feature/ex
| Author | SHA1 | Date | |
|---|---|---|---|
| 4779a38911 | |||
| f273c2fc7e | |||
| d5233dd00b | |||
| bd1d437d7d | |||
| f67ad8ef42 | |||
| acc24f8438 | |||
| 8bccbdb620 | |||
| 91a96fb97a | |||
| 5fcac74a25 | |||
| d2cf62bdbe | |||
| 2a2832c75f | |||
| 26fda5402e | |||
| 906ddd75d4 | |||
| 68505a77ae | |||
| d6746f6243 | |||
| ee2f084e0b | |||
| 9bd42d9c8c | |||
| 47d82fe083 | |||
|
|
217fc108c2 | ||
|
|
9c1c4fe6f3 | ||
| 958156e6b7 | |||
|
|
450f3a3ab0 | ||
|
|
8159686658 | ||
| 9fc31d03e5 | |||
| 6017d40579 | |||
| 618d4aa1c0 | |||
| 8366c48965 | |||
| d2e418c50b | |||
| eae10d92ca | |||
| 3f940c8e35 | |||
| 0846022f8a | |||
| 8812abdf33 | |||
| d56d05f01e | |||
| aabdebbbbe | |||
| 2b75b33d60 | |||
| 9a3f5abb7c | |||
| be1049db93 | |||
| 525b273a84 |
3
.idea/editor.xml
generated
3
.idea/editor.xml
generated
@@ -17,7 +17,7 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="HINT" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
@@ -56,6 +56,7 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultInitializationWithNoUserConstructor/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultIsUsedAsIdentifier/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultedSpecialMemberFunctionIsImplicitlyDeleted/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefinitionsOrder/@EntryIndexedValue" value="HINT" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeletingVoidPointer/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTemplateWithoutTemplateKeyword/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTypeWithoutTypenameKeyword/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
|
||||
@@ -27,7 +27,7 @@ option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build
|
||||
option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF)
|
||||
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" ON)
|
||||
option(OMATH_ENABLE_COVERAGE "Enable coverage" OFF)
|
||||
|
||||
option(OMATH_ENABLE_FORCE_INLINE "Will for compiler to make some functions to be force inlined no matter what" ON)
|
||||
if (VCPKG_MANIFEST_FEATURES)
|
||||
foreach (omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
|
||||
if (omath_feature STREQUAL "imgui")
|
||||
@@ -112,6 +112,10 @@ if (OMATH_ENABLE_LEGACY)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LEGACY)
|
||||
endif ()
|
||||
|
||||
if (OMATH_ENABLE_FORCE_INLINE)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_FORCE_INLINE)
|
||||
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}"
|
||||
|
||||
4
LICENSE
4
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (C) 2023-2025 Orange++ orange_github@proton.me
|
||||
Copyright (C) 2023-2026 Orange++ orange_github@proton.me
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -14,4 +14,4 @@ freely, subject to the following restrictions:
|
||||
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.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
@@ -30,6 +30,9 @@ find_package(GLEW REQUIRED)
|
||||
find_package(glfw3 CONFIG REQUIRED)
|
||||
target_link_libraries(example_glfw3 PRIVATE omath::omath GLEW::GLEW glfw)
|
||||
|
||||
find_path(TINYGLTF_INCLUDE_DIRS "tiny_gltf.h")
|
||||
target_include_directories(example_glfw3 PRIVATE ${TINYGLTF_INCLUDE_DIRS})
|
||||
|
||||
if(OMATH_ENABLE_VALGRIND)
|
||||
omath_setup_valgrind(example_projection_matrix_builder)
|
||||
omath_setup_valgrind(example_signature_scan)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,14 +3,60 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "mesh.hpp"
|
||||
#include "omath/engines/opengl_engine/camera.hpp"
|
||||
#include "omath/engines/opengl_engine/traits/mesh_trait.hpp"
|
||||
#include "omath/linear_algebra/triangle.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include <array>
|
||||
|
||||
namespace omath::primitives
|
||||
{
|
||||
template<class BoxMeshType>
|
||||
[[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) noexcept;
|
||||
}
|
||||
BoxMeshType create_box(const Vector3<float>& top, const Vector3<float>& bottom, const Vector3<float>& dir_forward,
|
||||
const Vector3<float>& dir_right, const float ratio = 4.f) noexcept
|
||||
{
|
||||
const auto height = top.distance_to(bottom);
|
||||
const auto side_size = height / ratio;
|
||||
|
||||
// corner layout (0‑3 bottom, 4‑7 top)
|
||||
std::array<Vector3<float>, 8> p;
|
||||
p[0] = bottom + (dir_forward + dir_right) * side_size; // front‑right‑bottom
|
||||
p[1] = bottom + (dir_forward - dir_right) * side_size; // front‑left‑bottom
|
||||
p[2] = bottom + (-dir_forward + dir_right) * side_size; // back‑right‑bottom
|
||||
p[3] = bottom + (-dir_forward - dir_right) * side_size; // back‑left‑bottom
|
||||
p[4] = top + (dir_forward + dir_right) * side_size; // front‑right‑top
|
||||
p[5] = top + (dir_forward - dir_right) * side_size; // front‑left‑top
|
||||
p[6] = top + (-dir_forward + dir_right) * side_size; // back‑right‑top
|
||||
p[7] = top + (-dir_forward - dir_right) * side_size; // back‑left‑top
|
||||
|
||||
std::array<Vector3<std::uint32_t>, 12> poly;
|
||||
|
||||
// bottom face (+Y up ⇒ wind CW when viewed from above)
|
||||
poly[0] = {0, 2, 3};
|
||||
poly[1] = {0, 3, 1};
|
||||
|
||||
// top face
|
||||
poly[2] = {4, 7, 6};
|
||||
poly[3] = {4, 5, 7};
|
||||
|
||||
// front face
|
||||
poly[4] = {0, 5, 1};
|
||||
poly[5] = {0, 4, 5};
|
||||
|
||||
// right face
|
||||
poly[6] = {0, 6, 2};
|
||||
poly[7] = {0, 4, 6};
|
||||
|
||||
// back face
|
||||
poly[8] = {2, 7, 3};
|
||||
poly[9] = {2, 6, 7};
|
||||
|
||||
// left face
|
||||
poly[10] = {1, 7, 5};
|
||||
poly[11] = {1, 3, 7};
|
||||
|
||||
return BoxMeshType{std::move(p), std::move(poly)};
|
||||
}
|
||||
} // namespace omath::primitives
|
||||
|
||||
@@ -25,16 +25,17 @@ namespace omath::primitives
|
||||
template<typename T> concept HasNormal = requires(T vertex) { vertex.normal; };
|
||||
template<typename T> concept HasUv = requires(T vertex) { vertex.uv; };
|
||||
|
||||
template<class Mat4X4, class RotationAngles, class MeshTypeTrait, class VertType = Vertex<>>
|
||||
template<class Mat4X4, class RotationAngles, class MeshTypeTrait, class VertType = Vertex<>,
|
||||
class VboType = std::vector<VertType>, class EboType = std::vector<Vector3<std::uint32_t>>>
|
||||
class Mesh final
|
||||
{
|
||||
public:
|
||||
using VectorType = VertType::VectorType;
|
||||
using VertexType = VertType;
|
||||
using VertexType = VboType::value_type;
|
||||
|
||||
private:
|
||||
using Vbo = std::vector<VertexType>;
|
||||
using Ebo = std::vector<Vector3<std::uint32_t>>;
|
||||
using Vbo = VboType;
|
||||
using Ebo = EboType;
|
||||
|
||||
public:
|
||||
Vbo m_vertex_buffer;
|
||||
@@ -100,20 +101,26 @@ namespace omath::primitives
|
||||
|
||||
[[nodiscard]]
|
||||
VectorType vertex_position_to_world_space(const Vector3<float>& vertex_position) const
|
||||
requires HasPosition<VertexType>
|
||||
{
|
||||
auto abs_vec = get_to_world_matrix() * mat_column_from_vector<typename Mat4X4::ContainedType, Mat4X4::get_store_ordering()>(vertex_position);
|
||||
auto abs_vec = get_to_world_matrix()
|
||||
* mat_column_from_vector<typename Mat4X4::ContainedType, Mat4X4::get_store_ordering()>(
|
||||
vertex_position);
|
||||
|
||||
return {abs_vec.at(0, 0), abs_vec.at(1, 0), abs_vec.at(2, 0)};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Triangle<VectorType> make_face_in_world_space(const Ebo::const_iterator vao_iterator) const
|
||||
requires HasPosition<VertexType>
|
||||
{
|
||||
return {vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->x).position),
|
||||
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->y).position),
|
||||
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->z).position)};
|
||||
if constexpr (HasPosition<VertexType>)
|
||||
{
|
||||
return {vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->x).position),
|
||||
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->y).position),
|
||||
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->z).position)};
|
||||
}
|
||||
return {vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->x)),
|
||||
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->y)),
|
||||
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->z))};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -3,14 +3,30 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "mesh.hpp"
|
||||
#include "omath/engines/opengl_engine/camera.hpp"
|
||||
#include "omath/engines/opengl_engine/mesh.hpp"
|
||||
#include "omath/engines/opengl_engine/traits/mesh_trait.hpp"
|
||||
#include "omath/linear_algebra/triangle.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include <array>
|
||||
|
||||
namespace omath::primitives
|
||||
{
|
||||
template<class PlaneMeshType>
|
||||
[[nodiscard]]
|
||||
std::array<Triangle<Vector3<float>>, 2> create_plane(const Vector3<float>& vertex_a,
|
||||
const Vector3<float>& vertex_b,
|
||||
const Vector3<float>& direction, float size) noexcept;
|
||||
}
|
||||
PlaneMeshType create_plane(const Vector3<float>& vertex_a, const Vector3<float>& vertex_b,
|
||||
const Vector3<float>& direction, const float size) noexcept
|
||||
{
|
||||
const auto second_vertex_a = vertex_a + direction * size;
|
||||
const auto second_vertex_b = vertex_b + direction * size;
|
||||
|
||||
std::array<Vector3<float>, 4> grid = {vertex_a, vertex_b, second_vertex_a, second_vertex_b};
|
||||
|
||||
std::array<Vector3<std::uint32_t>, 2> poly;
|
||||
poly[0] = {1, 1, 2};
|
||||
poly[1] = {0, 1, 3};
|
||||
|
||||
return PlaneMeshType(std::move(grid), std::move(poly));
|
||||
}
|
||||
} // namespace omath::primitives
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <memory_resource>
|
||||
#include <ostream>
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -86,6 +87,7 @@ namespace omath::collision
|
||||
// Converged if we can’t push the face closer than tolerance
|
||||
if (p_dist - face.d <= params.tolerance)
|
||||
{
|
||||
std::println("Vectex size {}, Faces size {}",vertexes.size(), faces.size());
|
||||
out.normal = face.n;
|
||||
out.depth = face.d; // along unit normal
|
||||
out.iterations = it + 1;
|
||||
@@ -118,7 +120,6 @@ namespace omath::collision
|
||||
|
||||
if (faces.empty())
|
||||
return std::nullopt;
|
||||
|
||||
const auto best = *std::ranges::min_element(faces, [](const auto& first, const auto& second)
|
||||
{ return first.d < second.d; });
|
||||
out.normal = best.n;
|
||||
|
||||
@@ -33,5 +33,25 @@ namespace omath::collision
|
||||
// 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) noexcept;
|
||||
|
||||
template<class MeshType>
|
||||
[[nodiscard]]
|
||||
static Vector3<float> get_ray_hit_point(const Ray& ray, const MeshType& mesh) noexcept
|
||||
{
|
||||
Vector3<float> mesh_hit = ray.end;
|
||||
|
||||
auto begin = mesh.m_element_buffer_object.cbegin();
|
||||
auto end = mesh.m_element_buffer_object.cend();
|
||||
for (auto current = begin; current < end; current = std::next(current))
|
||||
{
|
||||
auto face = mesh.make_face_in_world_space(current);
|
||||
|
||||
auto ray_stop_point = get_ray_hit_point(ray, face);
|
||||
if (ray_stop_point.distance_to(ray.start) < mesh_hit.distance_to(ray.start))
|
||||
mesh_hit = ray_stop_point;
|
||||
}
|
||||
|
||||
return mesh_hit;
|
||||
}
|
||||
};
|
||||
} // namespace omath::collision
|
||||
|
||||
201
include/omath/containers/encrypted_variable.hpp
Normal file
201
include/omath/containers/encrypted_variable.hpp
Normal file
@@ -0,0 +1,201 @@
|
||||
//
|
||||
// Created by Vladislav on 04.01.2026.
|
||||
//
|
||||
#pragma once
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#ifdef OMATH_ENABLE_FORCE_INLINE
|
||||
#ifdef _MSC_VER
|
||||
#define OMATH_FORCE_INLINE __forceinline
|
||||
#else
|
||||
#define OMATH_FORCE_INLINE __attribute__((always_inline)) inline
|
||||
#endif
|
||||
#else
|
||||
#define OMATH_FORCE_INLINE
|
||||
#endif
|
||||
|
||||
namespace omath::detail
|
||||
{
|
||||
[[nodiscard]]
|
||||
consteval std::uint64_t fnv1a_64(const char* s)
|
||||
{
|
||||
std::uint64_t h = 14695981039346656037ull;
|
||||
while (*s)
|
||||
{
|
||||
h ^= static_cast<unsigned char>(*s++);
|
||||
h *= 1099511628211ull;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
// SplitMix64 mixer (good quality for seeding / scrambling)
|
||||
[[nodiscard]]
|
||||
consteval std::uint64_t splitmix64(std::uint64_t x)
|
||||
{
|
||||
x += 0x9E3779B97F4A7C15ull;
|
||||
x = (x ^ (x >> 30)) * 0xBF58476D1CE4E5B9ull;
|
||||
x = (x ^ (x >> 27)) * 0x94D049BB133111EBull;
|
||||
return x ^ (x >> 31);
|
||||
}
|
||||
|
||||
// Choose your policy:
|
||||
// - If you want reproducible builds, REMOVE __DATE__/__TIME__.
|
||||
// - If you want "different each build", keep them.
|
||||
[[nodiscard]]
|
||||
consteval std::uint64_t base_seed()
|
||||
{
|
||||
std::uint64_t h = 0;
|
||||
h ^= fnv1a_64(__FILE__);
|
||||
h ^= splitmix64(fnv1a_64(__DATE__));
|
||||
h ^= splitmix64(fnv1a_64(__TIME__));
|
||||
return splitmix64(h);
|
||||
}
|
||||
|
||||
// Produce a "random" 64-bit value for a given stream index (compile-time)
|
||||
template<std::uint64_t Stream>
|
||||
[[nodiscard]]
|
||||
consteval std::uint64_t rand_u64()
|
||||
{
|
||||
// Stream is usually __COUNTER__ so each call site differs
|
||||
return splitmix64(base_seed() + 0xD1B54A32D192ED03ull * (Stream + 1));
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
consteval std::uint64_t bounded_u64(const std::uint64_t x, const std::uint64_t bound)
|
||||
{
|
||||
return (x * bound) >> 64;
|
||||
}
|
||||
|
||||
template<std::int64_t Lo, std::int64_t Hi, std::uint64_t Stream>
|
||||
[[nodiscard]]
|
||||
consteval std::int64_t rand_uint8_t()
|
||||
{
|
||||
static_assert(Lo <= Hi);
|
||||
const std::uint64_t span = static_cast<std::uint64_t>(Hi - Lo) + 1ull;
|
||||
const std::uint64_t r = rand_u64<Stream>();
|
||||
return static_cast<std::int64_t>(bounded_u64(r, span)) + Lo;
|
||||
}
|
||||
[[nodiscard]]
|
||||
consteval std::uint64_t rand_u64(const std::uint64_t seed, const std::uint64_t i)
|
||||
{
|
||||
return splitmix64(seed + 0xD1B54A32D192ED03ull * (i + 1ull));
|
||||
}
|
||||
|
||||
// Convert to int (uses low 32 bits; you can also use high bits if you prefer)
|
||||
[[nodiscard]]
|
||||
consteval std::uint8_t rand_uint8t(const std::uint64_t seed, const std::uint64_t i)
|
||||
{
|
||||
return static_cast<std::uint8_t>(rand_u64(seed, i)); // narrowing is fine/deterministic
|
||||
}
|
||||
template<std::size_t N, std::uint64_t Seed, std::size_t... I>
|
||||
[[nodiscard]]
|
||||
consteval std::array<std::uint8_t, N> make_array_impl(std::index_sequence<I...>)
|
||||
{
|
||||
return {rand_uint8t(Seed, static_cast<std::uint64_t>(I))...};
|
||||
}
|
||||
|
||||
template<std::size_t N, std::uint64_t Seed>
|
||||
[[nodiscard]]
|
||||
consteval std::array<std::uint8_t, N> make_array()
|
||||
{
|
||||
return make_array_impl<N, Seed>(std::make_index_sequence<N>{});
|
||||
}
|
||||
} // namespace omath::detail
|
||||
|
||||
namespace omath
|
||||
{
|
||||
template<class T>
|
||||
class VarAnchor;
|
||||
|
||||
template<class T, std::size_t key_size, std::array<std::uint8_t, key_size> key>
|
||||
class EncryptedVariable final
|
||||
{
|
||||
using value_type = std::remove_cvref_t<T>;
|
||||
|
||||
bool m_is_encrypted{};
|
||||
value_type m_data{};
|
||||
|
||||
OMATH_FORCE_INLINE constexpr void xor_contained_var_by_key()
|
||||
{
|
||||
// Safe, keeps const-correctness, and avoids reinterpret_cast issues
|
||||
auto bytes = std::as_writable_bytes(std::span<value_type, 1>{&m_data, 1});
|
||||
|
||||
for (std::size_t i = 0; i < bytes.size(); ++i)
|
||||
{
|
||||
const std::uint8_t k = static_cast<std::uint8_t>(key[i % key_size] + (i * key_size));
|
||||
bytes[i] ^= static_cast<std::byte>(k);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
OMATH_FORCE_INLINE constexpr explicit EncryptedVariable(const value_type& data)
|
||||
: m_is_encrypted(false), m_data(data)
|
||||
{
|
||||
encrypt();
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool is_encrypted() const
|
||||
{
|
||||
return m_is_encrypted;
|
||||
}
|
||||
|
||||
OMATH_FORCE_INLINE constexpr void decrypt()
|
||||
{
|
||||
if (!m_is_encrypted)
|
||||
return;
|
||||
xor_contained_var_by_key();
|
||||
m_is_encrypted = false;
|
||||
}
|
||||
|
||||
OMATH_FORCE_INLINE constexpr void encrypt()
|
||||
{
|
||||
if (m_is_encrypted)
|
||||
return;
|
||||
xor_contained_var_by_key();
|
||||
m_is_encrypted = true;
|
||||
}
|
||||
|
||||
[[nodiscard]] OMATH_FORCE_INLINE constexpr value_type& value()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
[[nodiscard]] OMATH_FORCE_INLINE constexpr const value_type& value() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
constexpr OMATH_FORCE_INLINE ~EncryptedVariable()
|
||||
{
|
||||
decrypt();
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr OMATH_FORCE_INLINE auto drop_anchor()
|
||||
{
|
||||
return VarAnchor{*this};
|
||||
}
|
||||
};
|
||||
|
||||
template<class EncryptedVarType>
|
||||
class VarAnchor final
|
||||
{
|
||||
public:
|
||||
// ReSharper disable once CppNonExplicitConvertingConstructor
|
||||
OMATH_FORCE_INLINE constexpr VarAnchor(EncryptedVarType& var): m_var(var)
|
||||
{
|
||||
m_var.decrypt();
|
||||
}
|
||||
OMATH_FORCE_INLINE constexpr ~VarAnchor()
|
||||
{
|
||||
m_var.encrypt();
|
||||
}
|
||||
|
||||
private:
|
||||
EncryptedVarType& m_var;
|
||||
};
|
||||
} // namespace omath
|
||||
|
||||
#define OMATH_CT_RAND_ARRAY_BYTE(N) \
|
||||
(::omath::detail::make_array<(N), (::omath::detail::base_seed() ^ static_cast<std::uint64_t>(__COUNTER__))>())
|
||||
#define OMATH_DEF_CRYPT_VAR(TYPE, KEY_SIZE) omath::EncryptedVariable<TYPE, KEY_SIZE, OMATH_CT_RAND_ARRAY_BYTE(KEY_SIZE)>
|
||||
17
include/omath/engines/frostbite_engine/primitives.hpp
Normal file
17
include/omath/engines/frostbite_engine/primitives.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Vladislav on 27.01.2026.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "mesh.hpp"
|
||||
#include "omath/engines/frostbite_engine/traits/mesh_trait.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include <array>
|
||||
namespace omath::frostbite_engine
|
||||
{
|
||||
using BoxMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>, std::array<Vector3<float>, 8>,
|
||||
std::array<Vector3<std::uint32_t>, 12>>;
|
||||
|
||||
using PlaneMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>,
|
||||
std::array<Vector3<float>, 4>, std::array<Vector3<std::uint32_t>, 2>>;
|
||||
} // namespace omath::frostbite_engine
|
||||
17
include/omath/engines/iw_engine/primitives.hpp
Normal file
17
include/omath/engines/iw_engine/primitives.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Vladislav on 27.01.2026.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "mesh.hpp"
|
||||
#include "omath/engines/iw_engine/traits/mesh_trait.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include <array>
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
using BoxMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>, std::array<Vector3<float>, 8>,
|
||||
std::array<Vector3<std::uint32_t>, 12>>;
|
||||
|
||||
using PlaneMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>,
|
||||
std::array<Vector3<float>, 4>, std::array<Vector3<std::uint32_t>, 2>>;
|
||||
} // namespace omath::iw_engine
|
||||
17
include/omath/engines/opengl_engine/primitives.hpp
Normal file
17
include/omath/engines/opengl_engine/primitives.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Vladislav on 27.01.2026.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "mesh.hpp"
|
||||
#include "omath/engines/opengl_engine/traits/mesh_trait.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include <array>
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
using BoxMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>, std::array<Vector3<float>, 8>,
|
||||
std::array<Vector3<std::uint32_t>, 12>>;
|
||||
|
||||
using PlaneMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>,
|
||||
std::array<Vector3<float>, 4>, std::array<Vector3<std::uint32_t>, 2>>;
|
||||
} // namespace omath::opengl_engine
|
||||
17
include/omath/engines/source_engine/primitives.hpp
Normal file
17
include/omath/engines/source_engine/primitives.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Vladislav on 27.01.2026.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "mesh.hpp"
|
||||
#include "omath/engines/source_engine/traits/mesh_trait.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include <array>
|
||||
namespace omath::source_engine
|
||||
{
|
||||
using BoxMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>, std::array<Vector3<float>, 8>,
|
||||
std::array<Vector3<std::uint32_t>, 12>>;
|
||||
|
||||
using PlaneMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>,
|
||||
std::array<Vector3<float>, 4>, std::array<Vector3<std::uint32_t>, 2>>;
|
||||
} // namespace omath::source_engine
|
||||
@@ -9,5 +9,5 @@
|
||||
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
|
||||
} // namespace omath::unity_engine
|
||||
17
include/omath/engines/unity_engine/primitives.hpp
Normal file
17
include/omath/engines/unity_engine/primitives.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Vladislav on 27.01.2026.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "mesh.hpp"
|
||||
#include "omath/engines/unity_engine/traits/mesh_trait.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include <array>
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
using BoxMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>, std::array<Vector3<float>, 8>,
|
||||
std::array<Vector3<std::uint32_t>, 12>>;
|
||||
|
||||
using PlaneMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>,
|
||||
std::array<Vector3<float>, 4>, std::array<Vector3<std::uint32_t>, 2>>;
|
||||
} // namespace omath::unity_engine
|
||||
17
include/omath/engines/unreal_engine/primitives.hpp
Normal file
17
include/omath/engines/unreal_engine/primitives.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Vladislav on 27.01.2026.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "mesh.hpp"
|
||||
#include "omath/engines/unreal_engine/traits/mesh_trait.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include <array>
|
||||
namespace omath::unreal_engine
|
||||
{
|
||||
using BoxMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>, std::array<Vector3<float>, 8>,
|
||||
std::array<Vector3<std::uint32_t>, 12>>;
|
||||
|
||||
using PlaneMesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait, primitives::Vertex<>,
|
||||
std::array<Vector3<float>, 4>, std::array<Vector3<std::uint32_t>, 2>>;
|
||||
} // namespace omath::unreal_engine
|
||||
@@ -1,54 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 4/18/2025.
|
||||
//
|
||||
#include "omath/3d_primitives/box.hpp"
|
||||
|
||||
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) noexcept
|
||||
{
|
||||
const auto height = top.distance_to(bottom);
|
||||
const auto side_size = height / ratio;
|
||||
|
||||
// corner layout (0‑3 bottom, 4‑7 top)
|
||||
std::array<Vector3<float>, 8> p;
|
||||
p[0] = bottom + (dir_forward + dir_right) * side_size; // front‑right‑bottom
|
||||
p[1] = bottom + (dir_forward - dir_right) * side_size; // front‑left‑bottom
|
||||
p[2] = bottom + (-dir_forward + dir_right) * side_size; // back‑right‑bottom
|
||||
p[3] = bottom + (-dir_forward - dir_right) * side_size; // back‑left‑bottom
|
||||
p[4] = top + (dir_forward + dir_right) * side_size; // front‑right‑top
|
||||
p[5] = top + (dir_forward - dir_right) * side_size; // front‑left‑top
|
||||
p[6] = top + (-dir_forward + dir_right) * side_size; // back‑right‑top
|
||||
p[7] = top + (-dir_forward - dir_right) * side_size; // back‑left‑top
|
||||
|
||||
std::array<Triangle<Vector3<float>>, 12> poly;
|
||||
|
||||
// bottom face (+Y up ⇒ wind CW when viewed from above)
|
||||
poly[0] = {p[0], p[2], p[3]};
|
||||
poly[1] = {p[0], p[3], p[1]};
|
||||
|
||||
// top face
|
||||
poly[2] = {p[4], p[7], p[6]};
|
||||
poly[3] = {p[4], p[5], p[7]};
|
||||
|
||||
// front face
|
||||
poly[4] = {p[0], p[5], p[1]};
|
||||
poly[5] = {p[0], p[4], p[5]};
|
||||
|
||||
// right face
|
||||
poly[6] = {p[0], p[6], p[2]};
|
||||
poly[7] = {p[0], p[4], p[6]};
|
||||
|
||||
// back face
|
||||
poly[8] = {p[2], p[7], p[3]};
|
||||
poly[9] = {p[2], p[6], p[7]};
|
||||
|
||||
// left face
|
||||
poly[10] = {p[1], p[7], p[5]};
|
||||
poly[11] = {p[1], p[3], p[7]};
|
||||
|
||||
return poly;
|
||||
}
|
||||
} // namespace omath::primitives
|
||||
@@ -1,19 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 8/28/2025.
|
||||
//
|
||||
#include "omath/3d_primitives/plane.hpp"
|
||||
|
||||
namespace omath::primitives
|
||||
{
|
||||
std::array<Triangle<Vector3<float>>, 2> create_plane(const Vector3<float>& vertex_a,
|
||||
const Vector3<float>& vertex_b,
|
||||
const Vector3<float>& direction, const float size) noexcept
|
||||
{
|
||||
const auto second_vertex_a = vertex_a + direction * size;
|
||||
return std::array
|
||||
{
|
||||
Triangle{second_vertex_a, vertex_a, vertex_b},
|
||||
Triangle{second_vertex_a, vertex_b + direction * size, vertex_b}
|
||||
};
|
||||
}
|
||||
} // namespace omath::primitives
|
||||
16
tests/general/unit_test_primitive_box.cpp
Normal file
16
tests/general/unit_test_primitive_box.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Created by Vladislav on 11.01.2026.
|
||||
//
|
||||
#include "omath/3d_primitives/box.hpp"
|
||||
#include "omath/collision/line_tracer.hpp"
|
||||
#include "omath/engines/opengl_engine/primitives.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(test, test)
|
||||
{
|
||||
auto result = omath::primitives::create_box<omath::opengl_engine::BoxMesh>(
|
||||
{0.f, 30.f, 0.f}, {}, omath::opengl_engine::k_abs_forward, omath::opengl_engine::k_abs_right);
|
||||
|
||||
omath::collision::Ray ray{.start = {0, 0, 0}, .end = {-100, 0, 0}};
|
||||
std::ignore = omath::collision::LineTracer::get_ray_hit_point(ray, result);
|
||||
}
|
||||
17
tests/general/unit_test_var_encryption.cpp
Normal file
17
tests/general/unit_test_var_encryption.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Vladislav on 04.01.2026.
|
||||
//
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/containers/encrypted_variable.hpp>
|
||||
TEST(Enc, Test)
|
||||
{
|
||||
constexpr omath::Vector3<float> original = {1.f, 2.f, 3.f};
|
||||
OMATH_DEF_CRYPT_VAR(omath::Vector3<float>, 128) var{original};
|
||||
{
|
||||
omath::VarAnchor _ = var.drop_anchor();
|
||||
|
||||
EXPECT_EQ(original, var.value());
|
||||
}
|
||||
EXPECT_NE(original, var.value());
|
||||
}
|
||||
8
tests/main.cpp
Normal file
8
tests/main.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -30,7 +30,8 @@
|
||||
"description": "Build benchmarks",
|
||||
"dependencies": [
|
||||
"glfw3",
|
||||
"glew"
|
||||
"glew",
|
||||
"tinygltf"
|
||||
]
|
||||
},
|
||||
"imgui": {
|
||||
|
||||
113
xmake.lua
Normal file
113
xmake.lua
Normal file
@@ -0,0 +1,113 @@
|
||||
add_rules("mode.debug", "mode.release")
|
||||
|
||||
add_rules("utils.install.cmake_importfiles")
|
||||
add_rules("utils.install.pkgconfig_importfiles")
|
||||
|
||||
set_version("4.6.1", {soname = "4.6"})
|
||||
set_languages("cxx23")
|
||||
set_warnings("all")
|
||||
|
||||
option("avx2")
|
||||
set_default(true)
|
||||
set_showmenu(true)
|
||||
|
||||
after_check(function (option)
|
||||
import("core.base.cpu")
|
||||
option:enable(cpu.has_feature("avx2"))
|
||||
end)
|
||||
option_end()
|
||||
|
||||
option("imgui")
|
||||
set_default(true)
|
||||
set_showmenu(true)
|
||||
option_end()
|
||||
|
||||
option("examples")
|
||||
set_default(true)
|
||||
set_showmenu(true)
|
||||
option_end()
|
||||
|
||||
option("tests")
|
||||
set_default(true)
|
||||
set_showmenu(true)
|
||||
option_end()
|
||||
|
||||
if has_config("avx2") then
|
||||
add_defines("OMATH_ENABLE_AVX2")
|
||||
add_vectorexts("avx2")
|
||||
end
|
||||
|
||||
if has_config("imgui") then
|
||||
add_defines("OMATH_IMGUI_INTEGRATION")
|
||||
add_requires("imgui")
|
||||
add_packages("imgui")
|
||||
end
|
||||
|
||||
if has_config("examples") then
|
||||
add_requires("glew", "glfw")
|
||||
end
|
||||
|
||||
if has_config("tests") then
|
||||
add_requires("gtest")
|
||||
end
|
||||
|
||||
target("omath")
|
||||
set_kind("static")
|
||||
add_files("source/**.cpp")
|
||||
add_includedirs("include", {public = true})
|
||||
add_headerfiles("include/(**.hpp)", {prefixdir = "omath"})
|
||||
on_config(function (target)
|
||||
if has_config("avx2") then
|
||||
cprint("${green} ✔️ AVX2 supported")
|
||||
else
|
||||
cprint("${red} ❌ AVX2 not supported")
|
||||
end
|
||||
end)
|
||||
|
||||
target("example_projection_matrix_builder")
|
||||
set_languages("cxx26")
|
||||
set_kind("binary")
|
||||
add_files("examples/example_proj_mat_builder.cpp")
|
||||
add_deps("omath")
|
||||
set_enabled(has_config("examples"))
|
||||
|
||||
target("example_signature_scan")
|
||||
set_languages("cxx26")
|
||||
set_kind("binary")
|
||||
add_files("examples/example_signature_scan.cpp")
|
||||
add_deps("omath")
|
||||
set_enabled(has_config("examples"))
|
||||
|
||||
target("example_glfw3")
|
||||
set_languages("cxx26")
|
||||
set_kind("binary")
|
||||
add_files("examples/example_glfw3.cpp")
|
||||
add_deps("omath")
|
||||
add_packages("glew", "glfw")
|
||||
set_enabled(has_config("examples"))
|
||||
|
||||
for _, file in ipairs(os.files("tests/**.cpp")) do
|
||||
local name = path.basename(file)
|
||||
target(name)
|
||||
set_languages("cxx23")
|
||||
set_kind("binary")
|
||||
add_files(file, "tests/main.cpp")
|
||||
add_deps("omath")
|
||||
add_packages("gtest")
|
||||
add_defines("OMATH_BUILD_TESTS")
|
||||
add_tests("default")
|
||||
set_default(false)
|
||||
set_enabled(has_config("tests"))
|
||||
end
|
||||
|
||||
task("check")
|
||||
on_run(function ()
|
||||
import("core.project.task")
|
||||
for _, file in ipairs(os.files("tests/**.cpp")) do
|
||||
local name = path.basename(file)
|
||||
task.run("run", {target = name})
|
||||
end
|
||||
end)
|
||||
set_menu {
|
||||
usage = "xmake check", description = "Run tests !", options = {}
|
||||
}
|
||||
Reference in New Issue
Block a user