JoltPhysics3D: Add some methods to JoltCharacter
This commit is contained in:
parent
74bfd8fa4e
commit
8d25495bab
|
|
@ -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<Vector3f, Quaternionf> 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);
|
||||
|
|
|
|||
|
|
@ -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 <Nazara/JoltPhysics3D/JoltCharacter.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void JoltCharacter::DisableSleeping()
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <Jolt/Jolt.h>
|
||||
#include <Jolt/Physics/Collision/ObjectLayer.h>
|
||||
#include <Jolt/Physics/Character/Character.h>
|
||||
#include <Jolt/Physics/PhysicsSystem.h>
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue