diff --git a/include/Nazara/JoltPhysics3D/JoltCharacter.hpp b/include/Nazara/JoltPhysics3D/JoltCharacter.hpp index 8b2bfff57..ce702c212 100644 --- a/include/Nazara/JoltPhysics3D/JoltCharacter.hpp +++ b/include/Nazara/JoltPhysics3D/JoltCharacter.hpp @@ -16,6 +16,7 @@ namespace JPH { class Character; + class Body; } namespace Nz @@ -33,13 +34,18 @@ namespace Nz JoltCharacter(JoltCharacter&&) = delete; ~JoltCharacter(); + inline void DisableSleeping(); + void EnableSleeping(bool enable); + Vector3f GetLinearVelocity() const; Quaternionf GetRotation() const; Vector3f GetPosition() const; std::pair GetPositionAndRotation() const; + Vector3f GetUp() const; bool IsOnGround() const; + void SetFriction(float friction); void SetLinearVelocity(const Vector3f& linearVel); void SetRotation(const Quaternionf& rotation); void SetUp(const Vector3f& up); diff --git a/include/Nazara/JoltPhysics3D/JoltCharacter.inl b/include/Nazara/JoltPhysics3D/JoltCharacter.inl index a64c97e3d..6d391fd48 100644 --- a/include/Nazara/JoltPhysics3D/JoltCharacter.inl +++ b/include/Nazara/JoltPhysics3D/JoltCharacter.inl @@ -2,11 +2,14 @@ // This file is part of the "Nazara Engine - JoltPhysics3D module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include #include namespace Nz { + inline void JoltCharacter::DisableSleeping() + { + return EnableSleeping(false); + } } #include diff --git a/src/Nazara/JoltPhysics3D/JoltCharacter.cpp b/src/Nazara/JoltPhysics3D/JoltCharacter.cpp index f837d3513..df28556cd 100644 --- a/src/Nazara/JoltPhysics3D/JoltCharacter.cpp +++ b/src/Nazara/JoltPhysics3D/JoltCharacter.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace Nz @@ -37,6 +38,16 @@ namespace Nz m_physicsWorld.UnregisterCharacter(this); } + void JoltCharacter::EnableSleeping(bool enable) + { + const JPH::BodyLockInterfaceNoLock& bodyInterface = m_physicsWorld.GetPhysicsSystem()->GetBodyLockInterfaceNoLock(); + JPH::BodyLockWrite bodyLock(bodyInterface, m_character->GetBodyID()); + if (!bodyLock.Succeeded()) + return; + + bodyLock.GetBody().SetAllowSleeping(enable); + } + Vector3f JoltCharacter::GetLinearVelocity() const { return FromJolt(m_character->GetLinearVelocity(false)); @@ -61,11 +72,22 @@ namespace Nz return { FromJolt(position), FromJolt(rotation) }; } + Vector3f JoltCharacter::GetUp() const + { + return FromJolt(m_character->GetUp()); + } + bool JoltCharacter::IsOnGround() const { return m_character->IsSupported(); } + void JoltCharacter::SetFriction(float friction) + { + JPH::BodyInterface& bodyInterface = m_physicsWorld.GetPhysicsSystem()->GetBodyInterfaceNoLock(); + bodyInterface.SetFriction(m_character->GetBodyID(), friction); + } + void JoltCharacter::SetLinearVelocity(const Vector3f& linearVel) { m_character->SetLinearVelocity(ToJolt(linearVel), false);