summaryrefslogtreecommitdiff
path: root/src/particle_system.rs
blob: 52e6284d8dd66623e890b3b02e59cb28ba9964bf (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use nalgebra::{Point as PointBase, SVector};

pub const N: usize = 2;
pub type Scalar = f32;

pub type Vector = SVector<Scalar, N>;
pub type Point = PointBase<Scalar, N>;

#[derive(Debug)]
pub struct Particle {
    pub mass: Scalar,
    pub position: Point,
    pub velocity: Vector,

    /// Force accumulator
    pub force: Vector,
}

impl Particle {
    pub fn new(position: Point, mass: Scalar) -> Self {
        Self {
            mass,
            position,
            velocity: Vector::zeros(),
            force: Vector::zeros(),
        }
    }

    pub fn apply_force(&mut self, force: Vector) {
        self.force += force;
    }
    pub fn reset_force(&mut self) {
        self.force = Vector::zeros()
    }
}

#[derive(Debug)]
pub struct ParticleSystem {
    pub particles: Vec<Particle>,

    /// Simulation clock
    pub t: Scalar,
}

pub trait Solver {
    fn step(&mut self, dt: Scalar);
}