diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp index d63e669a..84b36ac5 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp @@ -172,6 +172,30 @@ namespace SHADE return results; } + bool SHPhysicsSystem::TestAABBOverlap(const SHAABB& aabb, uint16_t layers) + { + if (!worldState.world) + { + SHLOG_ERROR("Cannot test AABB overlap without a physics world!") + return false; + } + + // Create a temporary collider to test against the world + auto* tempRP3DBody = worldState.world->createCollisionBody(rp3d::Transform { aabb.GetCenter(), SHQuaternion::Identity }); + auto* tempRP3DBox = factory.createBoxShape(aabb.GetExtents()); + auto* tempRP3DCollider = tempRP3DBody->addCollider(tempRP3DBox, rp3d::Transform{}); + tempRP3DCollider->setCollisionCategoryBits(layers); + tempRP3DCollider->setCollideWithMaskBits(layers); + + // Test the temp collider against the world + const bool IS_COLLIDING = worldState.world->testOverlap(tempRP3DBody); + + tempRP3DBody->removeCollider(tempRP3DCollider); + factory.destroyBoxShape(tempRP3DBox); + worldState.world->destroyCollisionBody(tempRP3DBody); + + return IS_COLLIDING; + } /*-----------------------------------------------------------------------------------*/ /* Private Function Member Definitions */ diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h index bd233bfe..06476c6b 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h @@ -18,6 +18,7 @@ // Project Headers #include "ECS_Base/System/SHSystemRoutine.h" #include "ECS_Base/System/SHFixedSystemRoutine.h" +#include "Math/Geometry/SHAABB.h" #include "Physics/Collision/SHCollisionInfo.h" #include "Physics/Interface/PhysicsObject/SHPhysicsObjectManager.h" #include "Physics/RP3DWrapper/SHPhysicsWorld.h" @@ -92,6 +93,18 @@ namespace SHADE */ [[nodiscard]] const std::vector& Raycast(const SHRaycaster::RaycastInfo& info) noexcept; + /** + * \brief + * Tests if an AABB overlaps with anything in the scene. + * \param aabb + * The AABB to test. + * \param layers + * The layer(s) to test the overlap on. Defaults to all layers. + * \return + * True if there is any overlap. + */ + [[nodiscard]] bool TestAABBOverlap(const SHAABB& aabb, uint16_t layers = static_cast(SHCollisionTag::Layer::ALL)); + /*---------------------------------------------------------------------------------*/ /* System Routines */ /*---------------------------------------------------------------------------------*/