// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - JoltPhysics3D module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP #define NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP #include #include #include #include #include #include #include #include #include namespace JPH { class PhysicsSystem; } namespace Nz { class JoltCharacter; class JoltRigidBody3D; class NAZARA_JOLTPHYSICS3D_API JoltPhysWorld3D { friend JoltCharacter; public: struct RaycastHit; JoltPhysWorld3D(); JoltPhysWorld3D(const JoltPhysWorld3D&) = delete; JoltPhysWorld3D(JoltPhysWorld3D&& ph) = delete; ~JoltPhysWorld3D(); UInt32 GetActiveBodyCount() const; Vector3f GetGravity() const; std::size_t GetMaxStepCount() const; JPH::PhysicsSystem* GetPhysicsSystem(); Time GetStepSize() const; inline bool IsBodyActive(UInt32 bodyIndex) const; bool RaycastQueryFirst(const Vector3f& from, const Vector3f& to, RaycastHit* hitInfo = nullptr); void SetGravity(const Vector3f& gravity); void SetMaxStepCount(std::size_t maxStepCount); void SetStepSize(Time stepSize); void Step(Time timestep); JoltPhysWorld3D& operator=(const JoltPhysWorld3D&) = delete; JoltPhysWorld3D& operator=(JoltPhysWorld3D&&) = delete; struct RaycastHit { float fraction; JoltRigidBody3D* hitBody = nullptr; Vector3f hitPosition; Vector3f hitNormal; }; private: class BodyActivationListener; friend BodyActivationListener; struct JoltWorld; inline void RegisterCharacter(JoltCharacter* character); inline void UnregisterCharacter(JoltCharacter* character); std::size_t m_maxStepCount; std::unique_ptr m_activeBodies; std::unique_ptr m_world; std::vector m_characters; Vector3f m_gravity; Time m_stepSize; Time m_timestepAccumulator; }; } #include #endif // NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP