summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 0b5704b4038ed1ea328b07b01f9e4984638f4edf (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
48
49
50
51
52
53
54
55
56
57
58
59
use std::path::PathBuf;

use force::{drag::Drag, gravity::Gravity};
use particle_system::{Particle, ParticleSystem, Point, Vector};
use ppm::PPM;
use solver::Solver;

mod constraint;
mod particle_system;
mod ppm;
mod solver;
mod force;
mod algebra;

fn main() {
    let ppm = PPM {
        width: 100,
        height: 200,
        prefix: PathBuf::from("./out"),
    };

    let dt = 0.01;
    let mut system = ParticleSystem {
        particles: vec![
            Particle::new(Point::origin(), 4.0),
            Particle::new(Point::new(-30.0, 0.0), 15.0),
            Particle::new(Point::new(20.0, 0.0), 30.0),
            Particle::new(Point::new(5.0, 20.0), 50.0),
        ],
        constraints: vec![],
        forces: vec![
            Box::new(Gravity {
                vector: Vector::y() * -9.8,
            }),
            Box::new(Drag { coefficient: 0.0 }),
        ],
        t: 0.0,
    };

    system.add_anchor_constraint(0);
    system.add_beam_constraint([0, 2]);
    system.add_beam_constraint([1, 2]);
    system.add_beam_constraint([1, 3]);
    system.add_beam_constraint([2, 3]);

    for i in 0..150_00 {
        system.apply_forces();

        if i % 10 == 0 {
            println!("Iteration #{i}");
            println!("{:#?}", system.particles);
            ppm.save_frame(&system.particles, system.t);
        }

        system.enforce_constraints(dt);

        system.step(dt);
    }
}