add add_velocity_source helper to WindSim

This commit is contained in:
Ludvig Böklin 2021-05-12 13:34:33 +02:00
parent 766897ce65
commit 91f96a57f5

View File

@ -55,12 +55,16 @@ impl WindSim {
cell_vel.map2(self.blocks_per_cell, |vi, si| vi * si as f32) cell_vel.map2(self.blocks_per_cell, |vi, si| vi * si as f32)
} }
pub fn add_velocity_source(&mut self, pos: Pos, vel: Vel) {
let cell_pos = self.world_to_grid(pos).unwrap_or(DEFAULT_POS);
let cell_vel = vel.0.map2(self.blocks_per_cell, |vi, si| vi / si as f32);
self.grid.add_velocity_source(cell_pos, cell_vel)
}
// Abstraction for running the simulation // Abstraction for running the simulation
pub fn tick(&mut self, sources: Vec<(Pos, Vel)>, dt: &DeltaTime) { pub fn tick(&mut self, sources: Vec<(Pos, Vel)>, dt: &DeltaTime) {
for (pos, vel) in sources { for (pos, vel) in sources {
let cell_pos = self.world_to_grid(pos).unwrap_or(DEFAULT_POS); self.add_velocity_source(pos, vel);
let cell_vel = vel.0.map2(self.blocks_per_cell, |vi, si| vi / si as f32);
self.grid.add_velocity_source(cell_pos, cell_vel)
} }
step_fluid( step_fluid(
&mut self.grid.density, &mut self.grid.density,