Compare commits

...

38 Commits

Author SHA1 Message Date
4779a38911 patch 2026-01-29 19:44:35 +03:00
f273c2fc7e added shit 2026-01-29 19:44:35 +03:00
d5233dd00b Merge pull request #139 from orange-cpp/feature/mesh_line_tracer
Feature/mesh line tracer
2026-01-27 01:42:41 +03:00
bd1d437d7d fixed naming 2026-01-27 01:25:49 +03:00
f67ad8ef42 mesh improvement 2026-01-27 01:25:07 +03:00
acc24f8438 WIP on feature/rotation_improved 2026-01-27 01:07:37 +03:00
8bccbdb620 Merge pull request #138 from orange-cpp/feature/primitives_improvement
Feature/primitives improvement
2026-01-27 01:07:15 +03:00
91a96fb97a dropped uselss cpp files 2026-01-27 00:51:17 +03:00
5fcac74a25 fixed naming 2026-01-27 00:39:34 +03:00
d2cf62bdbe added primitives to other engine triplets 2026-01-27 00:37:23 +03:00
2a2832c75f added opengl primitives 2026-01-27 00:33:35 +03:00
26fda5402e fix 2026-01-26 20:59:19 +03:00
906ddd75d4 fix 2026-01-26 19:01:39 +03:00
68505a77ae fix 2026-01-26 18:59:34 +03:00
d6746f6243 ppatch 2026-01-26 17:21:23 +03:00
ee2f084e0b added stuff 2026-01-26 17:07:38 +03:00
9bd42d9c8c added files 2026-01-26 15:44:46 +03:00
47d82fe083 Merge pull request #137 from luadebug/xm
xmake Add tests
2026-01-22 12:57:19 +03:00
Saikari
217fc108c2 fixup 2026-01-22 08:53:23 +03:00
Saikari
9c1c4fe6f3 Add tests 2026-01-22 08:52:18 +03:00
958156e6b7 Merge pull request #136 from luadebug/xmake
Add build configuration for omath and examples
2026-01-20 01:27:48 +03:00
Saikari
450f3a3ab0 Add rules for CMake and pkg-config imports 2026-01-19 04:45:41 +03:00
Saikari
8159686658 Add build configuration for omath and examples 2026-01-19 04:43:21 +03:00
9fc31d03e5 Update copyright year in LICENSE file 2026-01-17 21:35:34 +03:00
6017d40579 Merge pull request #135 from orange-cpp/feature/crypto_var
Feature/crypto var
2026-01-04 23:41:24 +03:00
618d4aa1c0 added final 2026-01-04 23:24:07 +03:00
8366c48965 improvement 2026-01-04 23:22:25 +03:00
d2e418c50b added cmake option 2026-01-04 23:02:58 +03:00
eae10d92ca forgot to remove 2026-01-04 22:53:57 +03:00
3f940c8e35 removed 128 bit int 2026-01-04 22:46:09 +03:00
0846022f8a improvement 2026-01-04 22:41:28 +03:00
8812abdf33 fixed test 2026-01-04 22:23:57 +03:00
d56d05f01e silenced warn 2026-01-04 22:16:40 +03:00
aabdebbbbe improved stuff 2026-01-04 22:16:40 +03:00
2b75b33d60 fix 2026-01-04 22:16:40 +03:00
9a3f5abb7c added check 2026-01-04 22:16:40 +03:00
be1049db93 changed algorithm 2026-01-04 22:16:40 +03:00
525b273a84 added stuff 2026-01-04 22:16:40 +03:00
25 changed files with 1679 additions and 261 deletions

3
.idea/editor.xml generated
View File

@@ -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" />

View File

@@ -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}"

View File

@@ -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.

View File

@@ -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

View File

@@ -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 (03 bottom, 47 top)
std::array<Vector3<float>, 8> p;
p[0] = bottom + (dir_forward + dir_right) * side_size; // frontrightbottom
p[1] = bottom + (dir_forward - dir_right) * side_size; // frontleftbottom
p[2] = bottom + (-dir_forward + dir_right) * side_size; // backrightbottom
p[3] = bottom + (-dir_forward - dir_right) * side_size; // backleftbottom
p[4] = top + (dir_forward + dir_right) * side_size; // frontrighttop
p[5] = top + (dir_forward - dir_right) * side_size; // frontlefttop
p[6] = top + (-dir_forward + dir_right) * side_size; // backrighttop
p[7] = top + (-dir_forward - dir_right) * side_size; // backlefttop
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

View File

@@ -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:

View File

@@ -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

View File

@@ -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 cant 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;

View File

@@ -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

View 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)>

View 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

View 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

View 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

View 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

View File

@@ -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

View 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

View 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

View File

@@ -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 (03 bottom, 47 top)
std::array<Vector3<float>, 8> p;
p[0] = bottom + (dir_forward + dir_right) * side_size; // frontrightbottom
p[1] = bottom + (dir_forward - dir_right) * side_size; // frontleftbottom
p[2] = bottom + (-dir_forward + dir_right) * side_size; // backrightbottom
p[3] = bottom + (-dir_forward - dir_right) * side_size; // backleftbottom
p[4] = top + (dir_forward + dir_right) * side_size; // frontrighttop
p[5] = top + (dir_forward - dir_right) * side_size; // frontlefttop
p[6] = top + (-dir_forward + dir_right) * side_size; // backrighttop
p[7] = top + (-dir_forward - dir_right) * side_size; // backlefttop
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

View File

@@ -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

View 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);
}

View 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
View File

@@ -0,0 +1,8 @@
#include <gtest/gtest.h>
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@@ -30,7 +30,8 @@
"description": "Build benchmarks",
"dependencies": [
"glfw3",
"glew"
"glew",
"tinygltf"
]
},
"imgui": {

113
xmake.lua Normal file
View 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 = {}
}