only substep solving; set only 3 attachment points

This commit is contained in:
Raptorox 2026-04-03 14:20:29 +02:00
parent fb06e9cb9e
commit 4b1933f3f8
No known key found for this signature in database
GPG key ID: 8B3556FC3ED1F6D8

View file

@ -23,9 +23,9 @@ const SUBSTEP_COUNT: u32 = 16;
fn populate_particles(particles: &mut Vec<Rc<RefCell<Particle>>>, num: u32, cols: u32) {
for i in 0..num {
const OFFSET: u32 = 10;
let x_pos = (/* WIN_WIDTH/2 - cols/2*OFFSET */ 40 + OFFSET * (i % cols)) as f32;
let y_pos = (/* WIN_HEIGHT/2 - (num/cols)/2*OFFSET */ 40 + OFFSET * (i / cols)) as f32;
let immovable = i < cols;
let x_pos = (/* WIN_WIDTH/2 - cols/2*OFFSET */120 + OFFSET * (i % cols)) as f32;
let y_pos = (/* WIN_HEIGHT/2 - (num/cols)/2*OFFSET */40 + OFFSET * (i / cols)) as f32;
let immovable = i == 0 || i == cols - 1 || i == (cols / 2);
let particle = Particle::new((x_pos, y_pos), immovable);
particles.push(Rc::new(RefCell::new(particle)));
}
@ -119,7 +119,12 @@ fn draw_all(
}
fn main() -> SfResult<()> {
let mut window = RenderWindow::new((WIN_WIDTH, WIN_HEIGHT), "Verlet", Style::CLOSE, &Default::default())?;
let mut window = RenderWindow::new(
(WIN_WIDTH, WIN_HEIGHT),
"Verlet",
Style::CLOSE,
&Default::default(),
)?;
window.set_framerate_limit(60);
let mut clock = Clock::start()?;
@ -170,21 +175,23 @@ fn main() -> SfResult<()> {
let dist_vec = mouse_coords - p_pos;
let dist = math::vec_len(dist_vec);
if dist < 40. {
particle.borrow_mut().apply_force(mouse_vel * 8000.);
particle.borrow_mut().apply_force(mouse_vel * 800.);
}
}
}
let dt = clock.restart().as_seconds();
let substep_dt = dt/SUBSTEP_COUNT as f32;
let substep_dt = dt / SUBSTEP_COUNT as f32;
//for _ in 0..SUBSTEP_COUNT {
apply_forces(&particles);
update_particles(&particles, dt);
for _ in 0..SUBSTEP_COUNT {
apply_forces(&particles);
update_particles(&particles, substep_dt);
solve_links(&mut links);
update_particle_derivatives(&particles, substep_dt);
update_positions(&mut circles, &particles);
}
update_particle_derivatives(&particles, dt);
update_positions(&mut circles, &particles);
//}
window.clear(Color::BLACK);
draw_all(&mut window, &circles /* &lines */);