From efff4d15d1271c0c9e347cdc93fdbfeaf7ac199d Mon Sep 17 00:00:00 2001 From: Martin Billinger Date: Mon, 23 Jul 2018 00:13:57 +0200 Subject: [PATCH] fix: #1 z-coordinate bug --- src/bformat.rs | 2 +- src/bstream.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bformat.rs b/src/bformat.rs index 1bc148c..606cc84 100644 --- a/src/bformat.rs +++ b/src/bformat.rs @@ -102,7 +102,7 @@ impl Bweights { /// Compute weights that correspond to a sound source at given position. pub fn from_position(pos: [f32; 3]) -> Self { - let dist = (pos[0] * pos[0] + pos[1] * pos[1] + pos[1] * pos[2]).sqrt(); + let dist = (pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]).sqrt(); let falloff = 1.0 / dist.max(1.0); // todo: proper falloff and distance model(s) Bweights { w: falloff / 2f32.sqrt(), diff --git a/src/bstream.rs b/src/bstream.rs index 13072da..af86b3e 100644 --- a/src/bstream.rs +++ b/src/bstream.rs @@ -209,12 +209,12 @@ impl SoundController { fn doppler_rate(&self) -> f32 { let dist = (self.position[0] * self.position[0] + self.position[1] * self.position[1] - + self.position[1] * self.position[2]) + + self.position[2] * self.position[2]) .sqrt(); let relative_velocity = (self.position[0] * self.velocity[0] + self.position[1] * self.velocity[1] - + self.position[1] * self.velocity[2]) / dist; + + self.position[2] * self.velocity[2]) / dist; self.speed_of_sound / (self.speed_of_sound + self.doppler_factor * relative_velocity) }