From a4408e624c16e422117d53e30e6be5edcddb41c8 Mon Sep 17 00:00:00 2001 From: Raptorox <70806316+Raptorox@users.noreply.github.com> Date: Thu, 15 May 2025 10:38:38 +0200 Subject: [PATCH] start functional --- src/main.rs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2864e67..9675dae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,24 +13,31 @@ use link::Link; //const GRAVITY: f32 = 100.; -fn populate_particles(particles: Vec) { +fn populate_particles(mut particles: Vec>>, num: u32) { + for i in 0..=num { + particles.push(Rc::new(RefCell::new(Particle::new(Vector2f::new(100. * i as f32, 300.))))); + } +} + +fn populate_links(links: Vec, particles: Vec>>) { } -fn populate_links(links: Vec) { +fn apply_forces(particles: Vec>>) { + for particle in particles { + let mut borrowed = particle.borrow_mut(); + // borrowed.apply_force(Vector2f::new(0., GRAVITY)); + borrowed.apply_force(Vector2f::new(1., 1.)); + } } -fn apply_forces(particles: Vec) { - -} - -fn update_particles(particles: Vec) { - +fn update_particles(particles: Vec>>, dt: f32) { + for particle in particles { particle.borrow_mut().update(dt); } } fn solve_links(links: Vec) { - + for mut link in links { link.solve(); } } fn update_positions(circles: Vec) { @@ -48,8 +55,8 @@ fn main() -> SfResult<()> { let mut clock = Clock::start()?; - let mut particles: Vec = vec![]; - populate_particles(particles); + let mut particles: Vec>> = vec![]; + populate_particles(particles, 3); let particle1 = Rc::new(RefCell::new(Particle::new(Vector2f::new(200., 300.)))); let particle2 = Rc::new(RefCell::new(Particle::new(Vector2f::new(300., 300.)))); let particle3 = Rc::new(RefCell::new(Particle::new(Vector2f::new(400., 300.))));