diff --git a/.idea/editor.xml b/.idea/editor.xml
index 373c50f..fde5348 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -201,7 +201,7 @@
-
+
@@ -215,7 +215,7 @@
-
+
diff --git a/include/omath/3d_primitives/mesh.hpp b/include/omath/3d_primitives/mesh.hpp
index 3779776..311b10f 100644
--- a/include/omath/3d_primitives/mesh.hpp
+++ b/include/omath/3d_primitives/mesh.hpp
@@ -6,25 +6,44 @@
#include
#include
#include
+#include
#include
namespace omath::primitives
{
- template
+ struct Vertex
+ {
+ using VectorType = Vector3;
+ Vector3 position;
+ Vector3 normal;
+ Vector3 uv;
+ };
+
+ template concept HasPosition = requires(T vertex) { vertex.position; };
+ template concept HasNormal = requires(T vertex) { vertex.normal; };
+ template concept HasUv = requires(T vertex) { vertex.uv; };
+
+ template
class Mesh final
{
public:
- using NumericType = Type;
-
+ using NumericType = float;
+ using VertexType = Vertex;
private:
- using Vbo = std::vector>;
+ using Vbo = std::vector;
using Vao = std::vector>;
public:
Vbo m_vertex_buffer;
Vao m_vertex_array_object;
- Mesh(Vbo vbo, Vao vao, const Vector3 scale = {1, 1, 1,})
+ Mesh(Vbo vbo, Vao vao,
+ const Vector3 scale =
+ {
+ 1,
+ 1,
+ 1,
+ })
: m_vertex_buffer(std::move(vbo)), m_vertex_array_object(std::move(vao)), m_scale(std::move(scale))
{
}
@@ -76,19 +95,20 @@ namespace omath::primitives
}
[[nodiscard]]
- Vector3 vertex_to_world_space(const Vector3& vertex) const
+ Vector3 vertex_to_world_space(const Vector3& vertex_position) const
{
- auto abs_vec = get_to_world_matrix() * mat_column_from_vector(vertex);
+ auto abs_vec = get_to_world_matrix() * mat_column_from_vector(vertex_position);
return {abs_vec.at(0, 0), abs_vec.at(1, 0), abs_vec.at(2, 0)};
}
[[nodiscard]]
Triangle> make_face_in_world_space(const Vao::const_iterator vao_iterator) const
+ requires HasPosition
{
- return {vertex_to_world_space(m_vertex_buffer.at(vao_iterator->x)),
- vertex_to_world_space(m_vertex_buffer.at(vao_iterator->y)),
- vertex_to_world_space(m_vertex_buffer.at(vao_iterator->z))};
+ return {vertex_to_world_space(m_vertex_buffer.at(vao_iterator->x).position),
+ vertex_to_world_space(m_vertex_buffer.at(vao_iterator->y).position),
+ vertex_to_world_space(m_vertex_buffer.at(vao_iterator->z).position)};
}
private:
diff --git a/include/omath/collision/epa_algorithm.hpp b/include/omath/collision/epa_algorithm.hpp
index f8bc3db..c7eac7e 100644
--- a/include/omath/collision/epa_algorithm.hpp
+++ b/include/omath/collision/epa_algorithm.hpp
@@ -24,13 +24,13 @@ namespace omath::collision
class Epa final
{
public:
- using Vertex = typename ColliderType::VertexType;
- static_assert(EpaVector, "VertexType must satisfy EpaVector concept");
+ using VectorType = typename ColliderType::VectorType;
+ static_assert(EpaVector, "VertexType must satisfy EpaVector concept");
struct Result final
{
- Vertex normal{}; // outward normal (from B to A)
- Vertex penetration_vector;
+ VectorType normal{}; // outward normal (from B to A)
+ VectorType penetration_vector;
float depth{0.0f};
int iterations{0};
int num_vertices{0};
@@ -45,11 +45,11 @@ namespace omath::collision
// Precondition: simplex.size()==4 and contains the origin.
[[nodiscard]]
- static std::optional solve(const ColliderType& a, const ColliderType& b, const Simplex& simplex,
+ static std::optional solve(const ColliderType& a, const ColliderType& b, const Simplex& simplex,
const Params params = {})
{
// --- Build initial polytope from simplex (4 points) ---
- std::vector vertexes;
+ std::vector vertexes;
vertexes.reserve(64);
for (std::size_t i = 0; i < simplex.size(); ++i)
vertexes.push_back(simplex[i]);
@@ -84,7 +84,7 @@ namespace omath::collision
const Face f = faces[fidx];
// Get farthest point in face normal direction
- const Vertex p = support_point(a, b, f.n);
+ const VectorType p = support_point(a, b, f.n);
const float p_dist = f.n.dot(p);
// Converged if we can’t push the face closer than tolerance
@@ -172,7 +172,7 @@ namespace omath::collision
struct Face final
{
int i0, i1, i2;
- Vertex n; // unit outward normal
+ VectorType n; // unit outward normal
float d; // n · v0 (>=0 ideally because origin is inside)
};
@@ -205,7 +205,7 @@ namespace omath::collision
}
[[nodiscard]]
- static bool visible_from(const Face& f, const Vertex& p)
+ static bool visible_from(const Face& f, const VectorType& p)
{
// positive if p is in front of the face
return (f.n.dot(p) - f.d) > 1e-7f;
@@ -223,12 +223,12 @@ namespace omath::collision
}
[[nodiscard]]
- static Face make_face(const std::vector& vertexes, int i0, int i1, int i2)
+ static Face make_face(const std::vector& vertexes, int i0, int i1, int i2)
{
- const Vertex& a0 = vertexes[i0];
- const Vertex& a1 = vertexes[i1];
- const Vertex& a2 = vertexes[i2];
- Vertex n = (a1 - a0).cross(a2 - a0);
+ const VectorType& a0 = vertexes[i0];
+ const VectorType& a1 = vertexes[i1];
+ const VectorType& a2 = vertexes[i2];
+ VectorType n = (a1 - a0).cross(a2 - a0);
if (n.dot(n) <= 1e-30f)
{
n = any_perp_vec(a1 - a0); // degenerate guard
@@ -246,9 +246,9 @@ namespace omath::collision
}
[[nodiscard]]
- static Vertex support_point(const ColliderType& a, const ColliderType& b, const Vertex& dir)
+ static VectorType support_point(const ColliderType& a, const ColliderType& b, const VectorType& dir)
{
- return a.find_abs_furthest_vertex(dir) - b.find_abs_furthest_vertex(-dir);
+ return a.find_abs_furthest_vertex(dir).position - b.find_abs_furthest_vertex(-dir).position;
}
template
diff --git a/include/omath/collision/gjk_algorithm.hpp b/include/omath/collision/gjk_algorithm.hpp
index 81a648c..c3db4ea 100644
--- a/include/omath/collision/gjk_algorithm.hpp
+++ b/include/omath/collision/gjk_algorithm.hpp
@@ -17,14 +17,14 @@ namespace omath::collision
template
class GjkAlgorithm final
{
- using VertexType = typename ColliderType::VertexType;
-
+ using VertexType = ColliderType::VertexType;
+ using VectorType = VertexType::VectorType;
public:
[[nodiscard]]
- static VertexType find_support_vertex(const ColliderType& collider_a, const ColliderType& collider_b,
- const VertexType& direction)
+ static VectorType find_support_vertex(const ColliderType& collider_a, const ColliderType& collider_b,
+ const VectorType& direction)
{
- return collider_a.find_abs_furthest_vertex(direction) - collider_b.find_abs_furthest_vertex(-direction);
+ return collider_a.find_abs_furthest_vertex(direction).position - collider_b.find_abs_furthest_vertex(-direction).position;
}
[[nodiscard]]
@@ -34,12 +34,12 @@ namespace omath::collision
}
[[nodiscard]]
- static GjkHitInfo is_collide_with_simplex_info(const ColliderType& collider_a,
+ static GjkHitInfo is_collide_with_simplex_info(const ColliderType& collider_a,
const ColliderType& collider_b)
{
- auto support = find_support_vertex(collider_a, collider_b, {1, 0, 0});
+ auto support = find_support_vertex(collider_a, collider_b, VectorType{1, 0, 0});
- Simplex simplex;
+ Simplex simplex;
simplex.push_front(support);
auto direction = -support;
diff --git a/include/omath/collision/mesh_collider.hpp b/include/omath/collision/mesh_collider.hpp
index 247b652..8603e44 100644
--- a/include/omath/collision/mesh_collider.hpp
+++ b/include/omath/collision/mesh_collider.hpp
@@ -11,31 +11,37 @@ namespace omath::collision
class MeshCollider
{
public:
- using NumericType = typename MeshType::NumericType;
+ using NumericType = MeshType::NumericType;
- using VertexType = Vector3;
+ using VertexType = MeshType::VertexType;
+ using VectorType = VertexType::VectorType;
explicit MeshCollider(MeshType mesh): m_mesh(std::move(mesh))
{
}
[[nodiscard]]
- const VertexType& find_furthest_vertex(const VertexType& direction) const
+ const VertexType& find_furthest_vertex(const VectorType& direction) const
{
- return *std::ranges::max_element(m_mesh.m_vertex_buffer, [&direction](const auto& first, const auto& second)
- { return first.dot(direction) < second.dot(direction); });
+ return *std::ranges::max_element(
+ m_mesh.m_vertex_buffer, [&direction](const auto& first, const auto& second)
+ { return first.position.dot(direction) < second.position.dot(direction); });
}
[[nodiscard]]
- VertexType find_abs_furthest_vertex(const VertexType& direction) const
+ VertexType find_abs_furthest_vertex(const VectorType& direction) const
{
- return m_mesh.vertex_to_world_space(find_furthest_vertex(direction));
+ const auto& vertex = find_furthest_vertex(direction);
+ auto new_vertex = vertex;
+ new_vertex.position = m_mesh.vertex_to_world_space(find_furthest_vertex(direction).position);
+ return new_vertex;
}
[[nodiscard]]
- const VertexType& get_origin() const
+ const VectorType& get_origin() const
{
return m_mesh.get_origin();
}
+
private:
MeshType m_mesh;
};
diff --git a/include/omath/engines/source_engine/mesh.hpp b/include/omath/engines/source_engine/mesh.hpp
index 31956b3..a8b2ef3 100644
--- a/include/omath/engines/source_engine/mesh.hpp
+++ b/include/omath/engines/source_engine/mesh.hpp
@@ -8,5 +8,5 @@
namespace omath::source_engine
{
- using Mesh = primitives::Mesh;
+ using Mesh = primitives::Mesh;
}
\ No newline at end of file
diff --git a/source/utility/pe_pattern_scan.cpp b/source/utility/pe_pattern_scan.cpp
index 931f241..23edc90 100644
--- a/source/utility/pe_pattern_scan.cpp
+++ b/source/utility/pe_pattern_scan.cpp
@@ -320,7 +320,7 @@ namespace omath
return std::visit(
[base_address, &pattern](const auto& nt_header) -> std::optional
{
- // Define .code segment as scan area
+ // Define .text segment as scan area
const auto start = nt_header.optional_header.base_of_code;
const auto scan_size = nt_header.optional_header.size_code;
diff --git a/tests/general/unit_test_colider.cpp b/tests/general/unit_test_colider.cpp
index 57d8b08..e5d08e6 100644
--- a/tests/general/unit_test_colider.cpp
+++ b/tests/general/unit_test_colider.cpp
@@ -7,20 +7,32 @@
TEST(UnitTestColider, CheckToWorld)
{
- omath::source_engine::Mesh mesh = {std::vector>{{1.f, 1.f, 1.f}, {-1.f, -1.f, -1.f}}, {}};
+ omath::source_engine::Mesh mesh = {
+ std::vector{
+ { { 1.f, 1.f, 1.f }, {}, {} },
+ { {-1.f, -1.f, -1.f }, {}, {} }
+ },
+ {}
+ };
mesh.set_origin({0, 2, 0});
const omath::source_engine::MeshCollider collider(mesh);
- const auto vertex = collider.find_abs_furthest_vertex({1.f, 0.f, 0.f});
+ const auto vertex = collider.find_abs_furthest_vertex({1.f, 0.f, 0.f}).position;
EXPECT_EQ(vertex, omath::Vector3(1.f, 3.f, 1.f));
}
TEST(UnitTestColider, FindFurthestVertex)
{
- const omath::source_engine::Mesh mesh = {{{1.f, 1.f, 1.f}, {-1.f, -1.f, -1.f}}, {}};
+ const omath::source_engine::Mesh mesh = {
+ {
+ { { 1.f, 1.f, 1.f }, {}, {} }, // position, normal, uv
+ { {-1.f, -1.f, -1.f }, {}, {} }
+ },
+ {}
+ };
const omath::source_engine::MeshCollider collider(mesh);
- const auto vertex = collider.find_furthest_vertex({1.f, 0.f, 0.f});
+ const auto vertex = collider.find_furthest_vertex({1.f, 0.f, 0.f}).position;
EXPECT_EQ(vertex, omath::Vector3(1.f, 1.f, 1.f));
}
diff --git a/tests/general/unit_test_epa.cpp b/tests/general/unit_test_epa.cpp
index 30f02ae..5131405 100644
--- a/tests/general/unit_test_epa.cpp
+++ b/tests/general/unit_test_epa.cpp
@@ -14,8 +14,16 @@ using EPA = omath::collision::Epa;
TEST(UnitTestEpa, TestCollisionTrue)
{
// Unit cube [-1,1]^3
- std::vector> vbo = {{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1},
- {1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {1, -1, -1}};
+ std::vector vbo = {
+ { {-1.f, -1.f, -1.f}, {}, {} },
+ { {-1.f, -1.f, 1.f}, {}, {} },
+ { {-1.f, 1.f, -1.f}, {}, {} },
+ { {-1.f, 1.f, 1.f}, {}, {} },
+ { { 1.f, 1.f, 1.f}, {}, {} },
+ { { 1.f, 1.f, -1.f}, {}, {} },
+ { { 1.f, -1.f, 1.f}, {}, {} },
+ { { 1.f, -1.f, -1.f}, {}, {} }
+ };
std::vector> vao; // not needed
Mesh a(vbo, vao, {1, 1, 1});
@@ -80,8 +88,16 @@ TEST(UnitTestEpa, TestCollisionTrue)
}
TEST(UnitTestEpa, TestCollisionTrue2)
{
- std::vector> vbo = {{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1},
- {1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {1, -1, -1}};
+ std::vector vbo = {
+ { { -1.f, -1.f, -1.f }, {}, {} },
+ { { -1.f, -1.f, 1.f }, {}, {} },
+ { { -1.f, 1.f, -1.f }, {}, {} },
+ { { -1.f, 1.f, 1.f }, {}, {} },
+ { { 1.f, 1.f, 1.f }, {}, {} },
+ { { 1.f, 1.f, -1.f }, {}, {} },
+ { { 1.f, -1.f, 1.f }, {}, {} },
+ { { 1.f, -1.f, -1.f }, {}, {} }
+ };
std::vector> vao; // not needed
Mesh a(vbo, vao, {1, 1, 1});
diff --git a/tests/general/unit_test_gjk.cpp b/tests/general/unit_test_gjk.cpp
index ea29f78..722fae7 100644
--- a/tests/general/unit_test_gjk.cpp
+++ b/tests/general/unit_test_gjk.cpp
@@ -8,15 +8,18 @@
namespace
{
const omath::source_engine::Mesh mesh = {
- {{-1.f, -1.f, -1.f},
- {-1.f, -1.f, 1.f},
- {-1.f, 1.f, -1.f},
- {-1.f, 1.f, 1.f},
- {1.f, 1.f, 1.f},
- {1.f, 1.f, -1.f},
- {1.f, -1.f, 1.f},
- {1.f, -1.f, -1.f}},
- {}};
+ {
+ { {-1.f, -1.f, -1.f}, {}, {} },
+ { {-1.f, -1.f, 1.f}, {}, {} },
+ { {-1.f, 1.f, -1.f}, {}, {} },
+ { {-1.f, 1.f, 1.f}, {}, {} },
+ { { 1.f, 1.f, 1.f}, {}, {} },
+ { { 1.f, 1.f, -1.f}, {}, {} },
+ { { 1.f, -1.f, 1.f}, {}, {} },
+ { { 1.f, -1.f, -1.f}, {}, {} }
+ },
+ {}
+ };
}
TEST(UnitTestGjk, TestCollisionTrue)
{