The listener should query the global transform first.

This commit is contained in:
Nolan Darilek 2021-01-08 14:06:13 -06:00
parent c33a28efce
commit 2ca07730ab

View File

@ -236,10 +236,12 @@ fn source_update(
source.set_gain(gain).unwrap(); source.set_gain(gain).unwrap();
source.set_looping(looping); source.set_looping(looping);
source.set_pitch(pitch).unwrap(); source.set_pitch(pitch).unwrap();
//println!("Global: {:?}, transform: {:?}", global_transform, transform);
let translation = global_transform let translation = global_transform
.map(|v| v.translation) .map(|v| v.translation)
.or_else(|| transform.map(|v| v.translation)); .or_else(|| transform.map(|v| v.translation));
if let Some(translation) = translation { if let Some(translation) = translation {
//println!("Translation: {:?}", translation);
source.set_relative(false); source.set_relative(false);
source source
.set_position([translation.x, translation.y, translation.z]) .set_position([translation.x, translation.y, translation.z])
@ -291,12 +293,12 @@ fn listener_update(
query: Query<(&Listener, Option<&Transform>, Option<&GlobalTransform>)>, query: Query<(&Listener, Option<&Transform>, Option<&GlobalTransform>)>,
) { ) {
for (_, transform, global_transform) in query.iter() { for (_, transform, global_transform) in query.iter() {
let transform = transform.cloned().or_else(|| { let transform: Option<Transform> = global_transform
global_transform.map(|v| { .map(|v| {
let matrix = v.compute_matrix(); let matrix = v.compute_matrix();
Transform::from_matrix(matrix) Transform::from_matrix(matrix)
}) })
}); .or_else(|| transform.cloned());
if let Some(transform) = transform { if let Some(transform) = transform {
let matrix = transform.compute_matrix().inverse(); let matrix = transform.compute_matrix().inverse();
let look = matrix.x_axis; let look = matrix.x_axis;