mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
Implements GJK collision detection
Adds GJK algorithm implementation for detecting collisions between mesh colliders. Includes mesh collider definition and unit tests for basic collision detection. Provides a foundation for more complex collision handling and physics interactions.
This commit is contained in:
29
tests/general/unit_test_colider.cpp
Normal file
29
tests/general/unit_test_colider.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by Vlad on 11/9/2025.
|
||||
//
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/collision/mesh_collider.hpp>
|
||||
|
||||
|
||||
|
||||
TEST(UnitTestColider, CheckToWorld)
|
||||
{
|
||||
const std::vector<omath::Vector3<float>> mesh = {{1.f, 1.f, 1.f}, {-1.f, -1.f, -1.f}};
|
||||
|
||||
const omath::collision::MeshCollider collider(mesh, {0.f, 2.f, 0.f});
|
||||
|
||||
const auto vertex = collider.find_abs_furthest_vertex({1.f, 0.f, 0.f});
|
||||
|
||||
EXPECT_EQ(vertex, omath::Vector3<float>(1.f, 3.f, 1.f));
|
||||
}
|
||||
|
||||
TEST(UnitTestColider, FindFurthestVertex)
|
||||
{
|
||||
const std::vector<omath::Vector3<float>> mesh = {{1.f, 1.f, 1.f}, {-1.f, -1.f, -1.f}};
|
||||
const omath::collision::MeshCollider collider(mesh, {0.f, 0.f, 0.f});
|
||||
const auto vertex = collider.find_furthest_vertex({1.f, 0.f, 0.f});
|
||||
EXPECT_EQ(vertex, omath::Vector3<float>(1.f, 1.f, 1.f));
|
||||
}
|
||||
|
||||
|
||||
|
||||
24
tests/general/unit_test_gjk.cpp
Normal file
24
tests/general/unit_test_gjk.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Vlad on 11/9/2025.
|
||||
//
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/collision/gjk_algorithm.hpp>
|
||||
|
||||
TEST(UnitTestGjk, TestCollision)
|
||||
{
|
||||
const std::vector<omath::Vector3<float>> 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}, // x = +1 vertices (put {1,1,1} first in case your support breaks ties by first-hit)
|
||||
{ 1.f, 1.f, -1.f},
|
||||
{ 1.f, -1.f, 1.f},
|
||||
{ 1.f, -1.f, -1.f}
|
||||
};
|
||||
|
||||
const omath::collision::MeshCollider collider_a(mesh, {0.f, 0.f, 0.f});
|
||||
const omath::collision::MeshCollider collider_b(mesh, {0.f, 3.f, 0.f});
|
||||
|
||||
const auto result = omath::collision::GjkAlgorithm::check_collision(collider_a, collider_b);
|
||||
}
|
||||
Reference in New Issue
Block a user