mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
added mesh class, added mesh trair
This commit is contained in:
@@ -1,47 +1,55 @@
|
||||
//
|
||||
// Created by Vlad on 11/9/2025.
|
||||
//
|
||||
#include "omath/engines/source_engine/collider.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/collision/gjk_algorithm.hpp>
|
||||
|
||||
#include <omath/engines/source_engine/mesh.hpp>
|
||||
namespace
|
||||
{
|
||||
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::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}, // 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}},
|
||||
{}};
|
||||
}
|
||||
TEST(UnitTestGjk, TestCollisionTrue)
|
||||
{
|
||||
const omath::collision::MeshCollider collider_a(mesh, {0.f, 0.f, 0.f});
|
||||
const omath::collision::MeshCollider collider_b(mesh, {0.f, 0.5f, 0.f});
|
||||
|
||||
const auto result = omath::collision::GjkAlgorithm<>::is_collide(collider_a, collider_b);
|
||||
const omath::source_engine::MeshCollider collider_a(mesh);
|
||||
|
||||
auto mesh_b = mesh;
|
||||
mesh_b.set_origin({0.f, 0.5f, 0.f});
|
||||
const omath::source_engine::MeshCollider collider_b(mesh_b);
|
||||
|
||||
const auto result =
|
||||
omath::collision::GjkAlgorithm<omath::source_engine::MeshCollider>::is_collide(collider_a, collider_b);
|
||||
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
TEST(UnitTestGjk, TestCollisionFalse)
|
||||
{
|
||||
const omath::collision::MeshCollider collider_a(mesh, {0.f, 0.f, 0.f});
|
||||
const omath::collision::MeshCollider collider_b(mesh, {0.f, 2.1f, 0.f});
|
||||
const omath::source_engine::MeshCollider collider_a(mesh);
|
||||
auto mesh_b = mesh;
|
||||
mesh_b.set_origin({0.f, 2.1f, 0.f});
|
||||
const omath::source_engine::MeshCollider collider_b(mesh_b);
|
||||
|
||||
const auto result = omath::collision::GjkAlgorithm<>::is_collide(collider_a, collider_b);
|
||||
const auto result = omath::collision::GjkAlgorithm<omath::source_engine::MeshCollider>::is_collide(collider_a, collider_b);
|
||||
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
TEST(UnitTestGjk, TestCollisionEqualOrigin)
|
||||
{
|
||||
const omath::collision::MeshCollider collider_a(mesh, {0.f, 0.f, 0.f});
|
||||
const omath::collision::MeshCollider collider_b(mesh, {0.f, 0.f, 0.f});
|
||||
const omath::source_engine::MeshCollider collider_a(mesh);
|
||||
const omath::source_engine::MeshCollider collider_b(mesh);
|
||||
|
||||
const auto result = omath::collision::GjkAlgorithm<>::is_collide(collider_a, collider_b);
|
||||
const auto result = omath::collision::GjkAlgorithm<omath::source_engine::MeshCollider>::is_collide(collider_a, collider_b);
|
||||
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
Reference in New Issue
Block a user