From ae2fd0069a866c8330f1d35479dfb2d7dd32776a Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 8 Apr 2018 17:52:12 +0200 Subject: [PATCH] SDK/ListenerSystem: Handle velocity in a generic way (no longer require a VelocityComponent) --- ChangeLog.md | 1 + SDK/src/NDK/Systems/ListenerSystem.cpp | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 4e02e78df..2dc442e04 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -119,6 +119,7 @@ Nazara Development Kit: - World now has an internal profiler, allowing to measure the refresh and system update time - CollisionComponent[2D|3D] and PhysicsComponent[2D|3D] now configures their internal RigidBody userdata to the entity ID they belong to (useful for callbacks). - Fixed EntityList copy/movement assignment operator which was not properly unregistering contained entities. +- ListenerSystem now handles velocity in a generic way (no longer require a VelocityComponent and is compatible with physics) # 0.4: diff --git a/SDK/src/NDK/Systems/ListenerSystem.cpp b/SDK/src/NDK/Systems/ListenerSystem.cpp index b6cdd55d9..c725bc368 100644 --- a/SDK/src/NDK/Systems/ListenerSystem.cpp +++ b/SDK/src/NDK/Systems/ListenerSystem.cpp @@ -6,7 +6,6 @@ #include #include #include -#include namespace Ndk { @@ -34,7 +33,7 @@ namespace Ndk * \param elapsedTime Delta time used for the update */ - void ListenerSystem::OnUpdate(float /*elapsedTime*/) + void ListenerSystem::OnUpdate(float elapsedTime) { std::size_t activeListenerCount = 0; @@ -45,18 +44,18 @@ namespace Ndk if (!listener.IsActive()) continue; + Nz::Vector3f oldPos = Nz::Audio::GetListenerPosition(); + // We get the position and the rotation to affect these to the listener const NodeComponent& node = entity->GetComponent(); - Nz::Audio::SetListenerPosition(node.GetPosition(Nz::CoordSys_Global)); + Nz::Vector3f newPos = node.GetPosition(Nz::CoordSys_Global); + + Nz::Audio::SetListenerPosition(newPos); Nz::Audio::SetListenerRotation(node.GetRotation(Nz::CoordSys_Global)); - // We verify the presence of a component of velocity - // (The listener'speed does not move it, but disturbs the sound like Doppler effect) - if (entity->HasComponent()) - { - const VelocityComponent& velocity = entity->GetComponent(); - Nz::Audio::SetListenerVelocity(velocity.linearVelocity); - } + // Compute listener velocity based on their old/new position + Nz::Vector3f velocity = (newPos - oldPos) / elapsedTime; + Nz::Audio::SetListenerVelocity(velocity); activeListenerCount++; }