Skip to content

Commit

Permalink
fix: #1 z-coordinate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mbillingr committed Jul 22, 2018
1 parent b48714a commit efff4d1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/bformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/bstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit efff4d1

Please sign in to comment.