SDK/ListenerSystem: Handle velocity in a generic way (no longer require a VelocityComponent)

This commit is contained in:
Lynix 2018-04-08 17:52:12 +02:00
parent 3c4c0fab66
commit ae2fd0069a
2 changed files with 10 additions and 10 deletions

View File

@ -119,6 +119,7 @@ Nazara Development Kit:
- World now has an internal profiler, allowing to measure the refresh and system update time - 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). - 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. - 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: # 0.4:

View File

@ -6,7 +6,6 @@
#include <Nazara/Audio/Audio.hpp> #include <Nazara/Audio/Audio.hpp>
#include <NDK/Components/ListenerComponent.hpp> #include <NDK/Components/ListenerComponent.hpp>
#include <NDK/Components/NodeComponent.hpp> #include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/VelocityComponent.hpp>
namespace Ndk namespace Ndk
{ {
@ -34,7 +33,7 @@ namespace Ndk
* \param elapsedTime Delta time used for the update * \param elapsedTime Delta time used for the update
*/ */
void ListenerSystem::OnUpdate(float /*elapsedTime*/) void ListenerSystem::OnUpdate(float elapsedTime)
{ {
std::size_t activeListenerCount = 0; std::size_t activeListenerCount = 0;
@ -45,18 +44,18 @@ namespace Ndk
if (!listener.IsActive()) if (!listener.IsActive())
continue; continue;
Nz::Vector3f oldPos = Nz::Audio::GetListenerPosition();
// We get the position and the rotation to affect these to the listener // We get the position and the rotation to affect these to the listener
const NodeComponent& node = entity->GetComponent<NodeComponent>(); const NodeComponent& node = entity->GetComponent<NodeComponent>();
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)); Nz::Audio::SetListenerRotation(node.GetRotation(Nz::CoordSys_Global));
// We verify the presence of a component of velocity // Compute listener velocity based on their old/new position
// (The listener'speed does not move it, but disturbs the sound like Doppler effect) Nz::Vector3f velocity = (newPos - oldPos) / elapsedTime;
if (entity->HasComponent<VelocityComponent>()) Nz::Audio::SetListenerVelocity(velocity);
{
const VelocityComponent& velocity = entity->GetComponent<VelocityComponent>();
Nz::Audio::SetListenerVelocity(velocity.linearVelocity);
}
activeListenerCount++; activeListenerCount++;
} }