Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds mesh scaling to mesh collider
Updates the mesh collider to include a scale parameter, allowing for non-uniform scaling of the collision mesh.

This provides more flexibility in defining collision shapes and supports a wider range of scenarios.
  • Loading branch information
orange-cpp committed Nov 9, 2025
commit b2a512eafe1aea429e7786b056dc1aafd5a3407f
8 changes: 5 additions & 3 deletions include/omath/collision/mesh_collider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ namespace omath::collision
{
public:
using VertexType = Vector3<float>;
MeshCollider(const std::vector<Vector3<float>>& vertexes, const Vector3<float> origin)
: m_vertexes(vertexes), m_origin(origin)
MeshCollider(const std::vector<VertexType>& vertexes, const VertexType& origin, const VertexType& scale = {1.f, 1.f, 1.f})
: m_vertexes(vertexes),m_scale(scale), m_origin(origin)
{
if (m_vertexes.empty())
throw std::runtime_error("Collider cannot have 0 vertexes");
}
std::vector<Vector3<float>> m_vertexes;
Vector3<float> m_scale;

Vector3<float> m_origin;
source_engine::ViewAngles m_rotation;

[[nodiscard]]
source_engine::Mat4X4 to_world() const
{
return mat_translation(m_origin) * source_engine::rotation_matrix(m_rotation);
return mat_scale(m_scale) * mat_translation(m_origin) * source_engine::rotation_matrix(m_rotation);
}

[[nodiscard]]
Expand Down
27 changes: 4 additions & 23 deletions tests/general/unit_test_gjk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <gtest/gtest.h>
#include <omath/collision/gjk_algorithm.hpp>

TEST(UnitTestGjk, TestCollisionTrue)
namespace
{
const std::vector<omath::Vector3<float>> mesh = {
{-1.f, -1.f, -1.f},
Expand All @@ -16,7 +16,10 @@
{ 1.f, -1.f, 1.f},
{ 1.f, -1.f, -1.f}
};
}
TEST(UnitTestGjk, TestCollisionTrue)
{

Check notice on line 22 in tests/general/unit_test_gjk.cpp

View check run for this annotation

codefactor.io / CodeFactor

tests/general/unit_test_gjk.cpp#L22

Redundant blank line at the start of a code block should be deleted. (whitespace/blank_line)
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});

Expand All @@ -26,17 +29,6 @@
}
TEST(UnitTestGjk, TestCollisionFalse)
{
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, 2.1f, 0.f});

Expand All @@ -47,17 +39,6 @@

TEST(UnitTestGjk, TestCollisionEqualOrigin)
{
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, 0.f, 0.f});

Expand Down
Loading