Physics3D: Add raycast support

This commit is contained in:
SirLynix
2023-03-14 18:03:05 +01:00
committed by Jérôme Leclercq
parent 5ee25e9621
commit 522315dbca
4 changed files with 90 additions and 13 deletions

View File

@@ -13,6 +13,7 @@
#include <Nazara/Physics3D/Components/RigidBody3DComponent.hpp>
#include <NazaraUtils/TypeList.hpp>
#include <entt/entt.hpp>
#include <vector>
namespace Nz
{
@@ -22,6 +23,8 @@ namespace Nz
static constexpr Int64 ExecutionOrder = 0;
using Components = TypeList<RigidBody3DComponent, class NodeComponent>;
struct RaycastHit;
Physics3DSystem(entt::registry& registry);
Physics3DSystem(const Physics3DSystem&) = delete;
Physics3DSystem(Physics3DSystem&&) = delete;
@@ -32,16 +35,27 @@ namespace Nz
inline PhysWorld3D& GetPhysWorld();
inline const PhysWorld3D& GetPhysWorld() const;
bool RaycastQueryFirst(const Vector3f& from, const Vector3f& to, RaycastHit* hitInfo = nullptr);
void Update(Time elapsedTime);
Physics3DSystem& operator=(const Physics3DSystem&) = delete;
Physics3DSystem& operator=(Physics3DSystem&&) = delete;
private:
static void OnConstruct(entt::registry& registry, entt::entity entity);
struct RaycastHit : PhysWorld3D::RaycastHit
{
entt::handle hitEntity;
};
private:
void OnConstruct(entt::registry& registry, entt::entity entity);
void OnDestruct(entt::registry& registry, entt::entity entity);
std::vector<entt::entity> m_physicsEntities;
entt::registry& m_registry;
entt::observer m_physicsConstructObserver;
entt::scoped_connection m_constructConnection;
entt::scoped_connection m_destructConnection;
PhysWorld3D m_physWorld;
};
}