summaryrefslogtreecommitdiff
path: root/src/force/mod.rs
blob: ce10f9f8ee7310743b22e4a1ce200b7cfc26df38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::particle_system::{Particle, ParticleSystem};

pub mod gravity;
pub mod drag;
pub mod spring;

pub trait Force {
    fn apply(&self, particles: &mut Vec<Particle>);
}

impl ParticleSystem {
    fn reset_forces(&mut self) {
        for particle in &mut self.particles {
            particle.reset_force();
        }
    }
    pub fn apply_forces(&mut self) {
        self.reset_forces();

        for force in &self.forces {
            force.apply(&mut self.particles)
        }
    }
}