JoltPhysics3D:: Improve characters
This commit is contained in:
committed by
Jérôme Leclercq
parent
2b0239b8f0
commit
a4ba7d6115
@@ -39,24 +39,24 @@ namespace Nz
|
||||
|
||||
Vector3f JoltCharacter::GetLinearVelocity() const
|
||||
{
|
||||
return FromJolt(m_character->GetLinearVelocity());
|
||||
return FromJolt(m_character->GetLinearVelocity(false));
|
||||
}
|
||||
|
||||
Quaternionf JoltCharacter::GetRotation() const
|
||||
{
|
||||
return FromJolt(m_character->GetRotation());
|
||||
return FromJolt(m_character->GetRotation(false));
|
||||
}
|
||||
|
||||
Vector3f JoltCharacter::GetPosition() const
|
||||
{
|
||||
return FromJolt(m_character->GetPosition());
|
||||
return FromJolt(m_character->GetPosition(false));
|
||||
}
|
||||
|
||||
std::pair<Vector3f, Quaternionf> JoltCharacter::GetPositionAndRotation() const
|
||||
{
|
||||
JPH::Vec3 position;
|
||||
JPH::Quat rotation;
|
||||
m_character->GetPositionAndRotation(position, rotation);
|
||||
m_character->GetPositionAndRotation(position, rotation, false);
|
||||
|
||||
return { FromJolt(position), FromJolt(rotation) };
|
||||
}
|
||||
@@ -68,7 +68,26 @@ namespace Nz
|
||||
|
||||
void JoltCharacter::SetLinearVelocity(const Vector3f& linearVel)
|
||||
{
|
||||
m_character->SetLinearVelocity(ToJolt(linearVel));
|
||||
m_character->SetLinearVelocity(ToJolt(linearVel), false);
|
||||
}
|
||||
|
||||
void JoltCharacter::SetRotation(const Quaternionf& rotation)
|
||||
{
|
||||
m_character->SetRotation(ToJolt(rotation), JPH::EActivation::Activate, false);
|
||||
}
|
||||
|
||||
void JoltCharacter::SetUp(const Vector3f& up)
|
||||
{
|
||||
m_character->SetUp(ToJolt(up));
|
||||
}
|
||||
|
||||
void JoltCharacter::WakeUp()
|
||||
{
|
||||
m_character->Activate(false);
|
||||
}
|
||||
|
||||
void JoltCharacter::PreSimulate(float elapsedTime)
|
||||
{
|
||||
}
|
||||
|
||||
void JoltCharacter::PostSimulate()
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <Jolt/Physics/Collision/BroadPhase/BroadPhaseLayer.h>
|
||||
#include <Jolt/Physics/PhysicsSettings.h>
|
||||
#include <Jolt/Physics/PhysicsSystem.h>
|
||||
#include <Jolt/Physics/PhysicsStepListener.h>
|
||||
#include <Jolt/Physics/Body/BodyActivationListener.h>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
@@ -245,12 +246,30 @@ namespace Nz
|
||||
JoltPhysWorld3D& m_physWorld;
|
||||
};
|
||||
|
||||
class JoltPhysWorld3D::StepListener : public JPH::PhysicsStepListener
|
||||
{
|
||||
public:
|
||||
StepListener(JoltPhysWorld3D& physWorld) :
|
||||
m_physWorld(physWorld)
|
||||
{
|
||||
}
|
||||
|
||||
void OnStep(float inDeltaTime, JPH::PhysicsSystem& /*inPhysicsSystem*/) override
|
||||
{
|
||||
m_physWorld.OnPreStep(inDeltaTime);
|
||||
}
|
||||
|
||||
private:
|
||||
JoltPhysWorld3D& m_physWorld;
|
||||
};
|
||||
|
||||
struct JoltPhysWorld3D::JoltWorld
|
||||
{
|
||||
JPH::TempAllocatorImpl tempAllocator;
|
||||
JPH::PhysicsSystem physicsSystem;
|
||||
|
||||
JoltPhysWorld3D::BodyActivationListener bodyActivationListener;
|
||||
JoltPhysWorld3D::StepListener stepListener;
|
||||
|
||||
DitchMeAsap::BPLayerInterfaceImpl layerInterface;
|
||||
DitchMeAsap::ObjectLayerPairFilterImpl objectLayerFilter;
|
||||
@@ -258,7 +277,8 @@ namespace Nz
|
||||
|
||||
JoltWorld(JoltPhysWorld3D& world, JPH::uint tempAllocatorSize) :
|
||||
tempAllocator(tempAllocatorSize),
|
||||
bodyActivationListener(world)
|
||||
bodyActivationListener(world),
|
||||
stepListener(world)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -279,6 +299,8 @@ namespace Nz
|
||||
m_world->physicsSystem.Init(0xFFFF, 0, 0xFFFF, 10 * 1024, m_world->layerInterface, m_world->objectBroadphaseLayerFilter, m_world->objectLayerFilter);
|
||||
m_world->physicsSystem.SetBodyActivationListener(&m_world->bodyActivationListener);
|
||||
|
||||
m_world->physicsSystem.AddStepListener(&m_world->stepListener);
|
||||
|
||||
std::size_t blockCount = (m_world->physicsSystem.GetMaxBodies() - 1) / 64 + 1;
|
||||
m_activeBodies = std::make_unique<std::atomic_uint64_t[]>(blockCount);
|
||||
for (std::size_t i = 0; i < blockCount; ++i)
|
||||
@@ -390,4 +412,10 @@ namespace Nz
|
||||
stepCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void JoltPhysWorld3D::OnPreStep(float deltatime)
|
||||
{
|
||||
for (JoltCharacter* character : m_characters)
|
||||
character->PreSimulate(deltatime);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user