Added function to test an AABB against the physics world
Update React Dependency
This commit is contained in:
parent
550b99b3d7
commit
78a3bf4575
|
@ -172,6 +172,30 @@ namespace SHADE
|
||||||
return results;
|
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 */
|
/* Private Function Member Definitions */
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
// Project Headers
|
// Project Headers
|
||||||
#include "ECS_Base/System/SHSystemRoutine.h"
|
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||||
#include "ECS_Base/System/SHFixedSystemRoutine.h"
|
#include "ECS_Base/System/SHFixedSystemRoutine.h"
|
||||||
|
#include "Math/Geometry/SHAABB.h"
|
||||||
#include "Physics/Collision/SHCollisionInfo.h"
|
#include "Physics/Collision/SHCollisionInfo.h"
|
||||||
#include "Physics/Interface/PhysicsObject/SHPhysicsObjectManager.h"
|
#include "Physics/Interface/PhysicsObject/SHPhysicsObjectManager.h"
|
||||||
#include "Physics/RP3DWrapper/SHPhysicsWorld.h"
|
#include "Physics/RP3DWrapper/SHPhysicsWorld.h"
|
||||||
|
@ -92,6 +93,18 @@ namespace SHADE
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::vector<SHPhysicsRaycastResult>& Raycast(const SHRaycaster::RaycastInfo& info) noexcept;
|
[[nodiscard]] const std::vector<SHPhysicsRaycastResult>& 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<uint16_t>(SHCollisionTag::Layer::ALL));
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* System Routines */
|
/* System Routines */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in New Issue