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
|
use std::path::PathBuf;
use particle_system::{Particle, ParticleSystem, Point, Vector};
use ppm::PPM;
use solver::Solver;
mod constraint;
mod particle_system;
mod ppm;
mod solver;
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![],
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]);
let gravity = -9.8 * Vector::y();
for i in 0..150_00 {
for particle in &mut system.particles {
particle.reset_force();
// Apply custom forces
particle.apply_force(gravity * particle.mass);
}
system.particles[0].apply_force(gravity); // Extra force on particle 0
if i % 10 == 0 {
println!("Iteration #{i}");
println!("{:#?}", system.particles);
ppm.save_frame(&system.particles, system.t);
}
system.enforce_constraints(dt);
system.step(dt);
}
}
|