diff options
author | eug-vs <eugene@eug-vs.xyz> | 2024-12-12 15:23:01 +0100 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2024-12-12 18:14:54 +0100 |
commit | 783070635b568b44b6902bfdc01bdadf12b86bc8 (patch) | |
tree | 89718706dc37d02761bb30f9e0b15e7110cc4e7e /src/main.rs | |
parent | ecdafb45dd9c416cb0810d6687a20ac97e480ac9 (diff) | |
download | particle-physics-783070635b568b44b6902bfdc01bdadf12b86bc8.tar.gz |
feat: implement constraint system and PPM rendering
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index 0a51789..718abf8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,30 +1,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(), 1.0)], + 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..3 { - println!("Iteration #{i}"); + 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 - for particle in &mut system.particles { - particle.apply_force(gravity); + if i % 10 == 0 { + println!("Iteration #{i}"); + println!("{:#?}", system.particles); + ppm.save_frame(&system.particles, system.t); } - system.step(dt); + system.enforce_constraints(dt); - println!("{:?}", system); + system.step(dt); } } |