SDK/ListenerSystem: Handle velocity in a generic way (no longer require a VelocityComponent)
This commit is contained in:
parent
3c4c0fab66
commit
ae2fd0069a
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include <Nazara/Audio/Audio.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
|
||||
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<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));
|
||||
|
||||
// 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<VelocityComponent>())
|
||||
{
|
||||
const VelocityComponent& velocity = entity->GetComponent<VelocityComponent>();
|
||||
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++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue