Merge pull request #8657 from Faless/fix_audio_listener_2d

Fixes to AudioListener2D
This commit is contained in:
Rémi Verschelde 2017-05-05 23:06:49 +02:00 committed by GitHub
commit cd403ecd9c
2 changed files with 3 additions and 6 deletions

View File

@ -697,7 +697,7 @@ void Viewport::_update_listener() {
void Viewport::_update_listener_2d() {
if (is_inside_tree() && audio_listener && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible())))
if (is_inside_tree() && audio_listener_2d && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible())))
SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, find_world_2d()->get_sound_space());
else
SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, RID());

View File

@ -832,10 +832,7 @@ void SpatialSound2DServerSW::update(float p_delta) {
float total_distance = 0;
for (Set<RID>::Element *L = space->listeners.front(); L; L = L->next()) {
Listener *listener = listener_owner.get(L->get());
float d = listener->transform.get_origin().distance_to(source->transform.get_origin());
if (d == 0)
d = 0.1;
total_distance += d;
total_distance += MAX(0.1, listener->transform.get_origin().distance_to(source->transform.get_origin()));
}
//compute spatialization variables, weighted according to distance
@ -852,7 +849,7 @@ void SpatialSound2DServerSW::update(float p_delta) {
Vector2 rel_vector = -listener->transform.xform_inv(source->transform.get_origin());
//Vector2 source_rel_vector = source->transform.xform_inv(listener->transform.get_origin()).normalized();
float distance = rel_vector.length();
float weight = distance / total_distance;
float weight = MAX(0.1, distance) / total_distance;
float pscale = 1.0;
float distance_scale = listener->params[LISTENER_PARAM_ATTENUATION_SCALE] * room->params[ROOM_PARAM_ATTENUATION_SCALE];