Physics3D/PhysWorld3D: Add generic RaycastQuery

This commit is contained in:
SirLynix
2023-03-23 13:16:06 +01:00
committed by Jérôme Leclercq
parent 4d42c0cf9c
commit 63d75e8904
4 changed files with 68 additions and 7 deletions

View File

@@ -46,6 +46,24 @@ namespace Nz
m_updateTime = Time::Zero();
}
bool BulletPhysics3DSystem::RaycastQuery(const Vector3f& from, const Vector3f& to, const FunctionRef<std::optional<float>(const RaycastHit& hitInfo)>& callback)
{
return m_physWorld.RaycastQuery(from, to, [&](const BulletPhysWorld3D::RaycastHit& hitInfo)
{
RaycastHit hitWithEntity;
static_cast<BulletPhysWorld3D::RaycastHit&>(hitWithEntity) = hitInfo;
if (hitWithEntity.hitBody)
{
std::size_t uniqueIndex = hitWithEntity.hitBody->GetUniqueIndex();
if (uniqueIndex < m_physicsEntities.size())
hitWithEntity.hitEntity = entt::handle(m_registry, m_physicsEntities[uniqueIndex]);
}
return callback(hitWithEntity);
});
}
bool BulletPhysics3DSystem::RaycastQueryFirst(const Vector3f& from, const Vector3f& to, RaycastHit* hitInfo)
{
if (!m_physWorld.RaycastQueryFirst(from, to, hitInfo))