diff --git a/SHADE_Engine/src/Physics/Collision/SHPhysicsRaycaster.cpp b/SHADE_Engine/src/Physics/Collision/SHPhysicsRaycaster.cpp index 11b9fcab..cab5c93b 100644 --- a/SHADE_Engine/src/Physics/Collision/SHPhysicsRaycaster.cpp +++ b/SHADE_Engine/src/Physics/Collision/SHPhysicsRaycaster.cpp @@ -63,7 +63,7 @@ namespace SHADE raycasts.clear(); } - SHPhysicsRaycastResult SHPhysicsRaycaster::Raycast(const SHRay& ray, float distance) noexcept + SHPhysicsRaycastResult SHPhysicsRaycaster::Raycast(const SHRay& ray, float distance, const SHCollisionTag& collisionTag) noexcept { // Reset temp temp = SHPhysicsRaycastResult{}; @@ -78,13 +78,13 @@ namespace SHADE // If distance in infinity, cast to the default max distance of 2 km. if (distance == std::numeric_limits::infinity()) { - world->raycast(ray, this); + world->raycast(ray, this, collisionTag); } else { const SHVec3 END_POINT = ray.position + ray.direction * distance; const rp3d::Ray RP3D_RAY{ ray.position, END_POINT }; - world->raycast(RP3D_RAY, this); + world->raycast(RP3D_RAY, this, collisionTag); } // If a hit was found, populate temp info for return. @@ -98,7 +98,7 @@ namespace SHADE return temp; } - SHPhysicsRaycastResult SHPhysicsRaycaster::Linecast(const SHVec3& start, const SHVec3& end) noexcept + SHPhysicsRaycastResult SHPhysicsRaycaster::Linecast(const SHVec3& start, const SHVec3& end, const SHCollisionTag& collisionTag) noexcept { temp = SHPhysicsRaycastResult{}; temp.distance = SHVec3::Distance(start, end); @@ -110,7 +110,7 @@ namespace SHADE } const rp3d::Ray RP3D_RAY{ start, end }; - world->raycast(RP3D_RAY, this); + world->raycast(RP3D_RAY, this, collisionTag); if (temp.hit) { diff --git a/SHADE_Engine/src/Physics/Collision/SHPhysicsRaycaster.h b/SHADE_Engine/src/Physics/Collision/SHPhysicsRaycaster.h index 81165b56..447207c7 100644 --- a/SHADE_Engine/src/Physics/Collision/SHPhysicsRaycaster.h +++ b/SHADE_Engine/src/Physics/Collision/SHPhysicsRaycaster.h @@ -19,6 +19,7 @@ #include "Physics/PhysicsObject/SHPhysicsObjectManager.h" #include "Physics/SHPhysicsWorld.h" #include "SH_API.h" +#include "SHCollisionTags.h" #include "SHPhysicsRaycastResult.h" namespace SHADE @@ -67,44 +68,46 @@ namespace SHADE SHPhysicsRaycastResult Raycast ( - const SHRay& ray - , float distance = std::numeric_limits::infinity() + const SHRay& ray + , float distance = std::numeric_limits::infinity() + , const SHCollisionTag& collisionTag = SHCollisionTag{} ) noexcept; SHPhysicsRaycastResult Linecast ( - const SHVec3& start - , const SHVec3& end + const SHVec3& start + , const SHVec3& end + , const SHCollisionTag& collisionTag = SHCollisionTag{} ) noexcept; SHPhysicsRaycastResult ColliderRaycast ( - EntityID eid - , const SHRay& ray - , float distance = std::numeric_limits::infinity() + EntityID eid + , const SHRay& ray + , float distance = std::numeric_limits::infinity() ) noexcept; SHPhysicsRaycastResult ColliderRaycast ( - EntityID eid - , int shapeIndex - , const SHRay& ray - , float distance = std::numeric_limits::infinity() + EntityID eid + , int shapeIndex + , const SHRay& ray + , float distance = std::numeric_limits::infinity() ) noexcept; SHPhysicsRaycastResult ColliderLinecast ( - EntityID eid - , const SHVec3& start - , const SHVec3& end + EntityID eid + , const SHVec3& start + , const SHVec3& end ) noexcept; SHPhysicsRaycastResult ColliderLinecast ( - EntityID eid - , int shapeIndex - , const SHVec3& start - , const SHVec3& end + EntityID eid + , int shapeIndex + , const SHVec3& start + , const SHVec3& end ) noexcept; rp3d::decimal notifyRaycastHit(const rp3d::RaycastInfo& raycastInfo) override; diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp index 79757867..768c9b77 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp @@ -258,14 +258,14 @@ namespace SHADE } } - SHPhysicsRaycastResult SHPhysicsSystem::Raycast(const SHRay& ray, float distance) noexcept + SHPhysicsRaycastResult SHPhysicsSystem::Raycast(const SHRay& ray, float distance, const SHCollisionTag& collisionTag) noexcept { - return raycaster.Raycast(ray, distance); + return raycaster.Raycast(ray, distance, collisionTag); } - SHPhysicsRaycastResult SHPhysicsSystem::Linecast(const SHVec3& start, const SHVec3& end) noexcept + SHPhysicsRaycastResult SHPhysicsSystem::Linecast(const SHVec3& start, const SHVec3& end, const SHCollisionTag& collisionTag) noexcept { - return raycaster.Linecast(start, end); + return raycaster.Linecast(start, end, collisionTag); } SHPhysicsRaycastResult SHPhysicsSystem::ColliderRaycast(EntityID eid, const SHRay& ray, float distance) noexcept diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h index 8d49450d..99db493e 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h @@ -85,24 +85,28 @@ namespace SHADE * @brief Casts a ray into the world. * @param ray The ray to cast. * @param distance The distance to cast the ray. Defaults to infinity. + * @param collisionTag The collision tag to use for filtering the raycast. * @return The result of the raycast. */ SHPhysicsRaycastResult Raycast ( - const SHRay& ray - , float distance = std::numeric_limits::infinity() + const SHRay& ray + , float distance = std::numeric_limits::infinity() + , const SHCollisionTag& collisionTag = SHCollisionTag{} ) noexcept; /** * @brief Casts a bounded ray into the world. * @param start The starting point of the ray. * @param end The end point of the ray. + * @param collisionTag The collision tag to use for filtering the bounded raycast. * @return The result of the raycast. */ SHPhysicsRaycastResult Linecast ( const SHVec3& start , const SHVec3& end + , const SHCollisionTag& collisionTag = SHCollisionTag{} ) noexcept; /** diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp index d133f562..6168d673 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp @@ -20,6 +20,7 @@ #include "Scripting/SHScriptEngine.h" #include "Input/SHInputManager.h" +#include "Physics/Collision/SHCollisionTagMatrix.h" /*-------------------------------------------------------------------------------------*/ /* Local Functions */ @@ -403,4 +404,13 @@ void testFunction() rb->AddForce(SHVec3::UnitX * forceModifier); } } + + // Cast rays + auto* tag = SHCollisionTagMatrix::GetTag(1); + tag->SetLayerState(SHCollisionTag::Layer::_1, false); + tag->SetLayerState(SHCollisionTag::Layer::_2, true); + + SHRay ray { SHVec3{3.0f, 3.5f, 0.0f}, -SHVec3::UnitX }; + auto* physicsSystem = SHSystemManager::GetSystem(); + physicsSystem->Raycast(ray, std::numeric_limits::infinity(), *tag); }