Merge pull request #69027 from Uxeron/AudioListener2DRotationFix

Fix AudioListener2D ignoring rotation for positional audio
This commit is contained in:
Rémi Verschelde 2023-06-21 10:17:37 +02:00
commit 5025d95d41
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -175,13 +175,14 @@ void AudioStreamPlayer2D::_update_panning() {
//screen in global is used for attenuation
AudioListener2D *listener = vp->get_audio_listener_2d();
Transform2D full_canvas_transform = vp->get_global_canvas_transform() * vp->get_canvas_transform();
if (listener) {
listener_in_global = listener->get_global_position();
relative_to_listener = global_pos - listener_in_global;
relative_to_listener = (global_pos - listener_in_global).rotated(-listener->get_global_rotation());
relative_to_listener *= full_canvas_transform.get_scale(); // Default listener scales with canvas size, do the same here.
} else {
Transform2D to_listener = vp->get_global_canvas_transform() * vp->get_canvas_transform();
listener_in_global = to_listener.affine_inverse().xform(screen_size * 0.5);
relative_to_listener = to_listener.xform(global_pos) - screen_size * 0.5;
listener_in_global = full_canvas_transform.affine_inverse().xform(screen_size * 0.5);
relative_to_listener = full_canvas_transform.xform(global_pos) - screen_size * 0.5;
}
float dist = global_pos.distance_to(listener_in_global); // Distance to listener, or screen if none.