diff --git a/include/bounce/dynamics/shapes/mesh_shape.h b/include/bounce/dynamics/shapes/mesh_shape.h index c8215e6..7436e3c 100644 --- a/include/bounce/dynamics/shapes/mesh_shape.h +++ b/include/bounce/dynamics/shapes/mesh_shape.h @@ -41,6 +41,8 @@ public: bool TestSphere(b3TestSphereOutput* output, const b3Sphere& sphere, const b3Transform& xf) const; + bool TestSphere(b3TestSphereOutput* output, const b3Sphere& sphere, const b3Transform& xf, u32 childIndex) const; + bool RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf) const; bool RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf, u32 childIndex) const; diff --git a/include/bounce/dynamics/shapes/shape.h b/include/bounce/dynamics/shapes/shape.h index 53aa35e..c62df71 100644 --- a/include/bounce/dynamics/shapes/shape.h +++ b/include/bounce/dynamics/shapes/shape.h @@ -153,6 +153,7 @@ protected: friend class b3Body; friend class b3Contact; friend class b3ContactManager; + friend class b3MeshShape; friend class b3MeshContact; friend class b3ContactSolver; friend class b3List1; diff --git a/src/bounce/dynamics/shapes/mesh_shape.cpp b/src/bounce/dynamics/shapes/mesh_shape.cpp index 7d2fa9e..012028e 100644 --- a/src/bounce/dynamics/shapes/mesh_shape.cpp +++ b/src/bounce/dynamics/shapes/mesh_shape.cpp @@ -17,7 +17,9 @@ */ #include +#include #include +#include b3MeshShape::b3MeshShape() { @@ -88,6 +90,24 @@ bool b3MeshShape::TestSphere(b3TestSphereOutput* output, const b3Sphere& sphere, return false; } +bool b3MeshShape::TestSphere(b3TestSphereOutput* output, const b3Sphere& sphere, const b3Transform& xf, u32 index) const +{ + B3_ASSERT(index < m_mesh->triangleCount); + b3Triangle* triangle = m_mesh->triangles + index; + b3Vec3 v1 = m_mesh->vertices[triangle->v1]; + b3Vec3 v2 = m_mesh->vertices[triangle->v2]; + b3Vec3 v3 = m_mesh->vertices[triangle->v3]; + + b3TriangleHull hull(v1, v2, v3); + + b3HullShape hullShape; + hullShape.m_body = m_body; + hullShape.m_hull = &hull; + hullShape.m_radius = B3_HULL_RADIUS; + + return hullShape.TestSphere(output, sphere, xf); +} + bool b3MeshShape::RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf, u32 index) const { B3_ASSERT(index < m_mesh->triangleCount);