diff options
-rw-r--r-- | playground/src/main.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/playground/src/main.rs b/playground/src/main.rs index f585efa..5b5c157 100644 --- a/playground/src/main.rs +++ b/playground/src/main.rs @@ -31,7 +31,7 @@ fn main() { Particle::new(Point::new(5.0, 20.0), 50.0), Particle::new(Point::origin(), 25.0), Particle::new(Point::new(50.0, 0.0), 10.0), - Particle::new(Point::new(-100.0, -100.0), 100.0), + Particle::new(Point::new(-30.0, -30.0), 10.0), ], constraints: vec![], forces: vec![ @@ -58,7 +58,8 @@ fn main() { system.add_beam_constraint([5, 4]); let mut selected_particle_id = None; - let mut watch_particle_id = 0; + let mut watch_particle_id = None; + let mouse_particle_id = system.particles.len() - 1; let (mut rl, thread) = raylib::init() .size(640, 480) @@ -85,7 +86,13 @@ fn main() { ); let camera = Camera::new( - system.particles[watch_particle_id].position, + match watch_particle_id { + Some(id) => { + let particle: &Particle = &system.particles[id]; + particle.position + }, + None => Point::origin(), + }, Vector::y(), Vector::x(), ); @@ -98,7 +105,6 @@ fn main() { let screen_space = raylib_to_screen_space(mouse_point, &d); let world_mouse = camera.screen_space_to_world(screen_space); - let mouse_particle_id = system.particles.len() - 1; system.particles[mouse_particle_id].position = world_mouse; system.forces.push(Box::new(Spring { @@ -149,7 +155,7 @@ fn main() { PointBase::<f32, 2>::new(d.get_mouse_x() as f32, d.get_mouse_y() as f32); let position = PointBase::<f32, 2>::new(position.x as f32, position.y as f32); if (position - mouse_point).norm() < radius { - watch_particle_id = particle_id + watch_particle_id = Some(particle_id) } } @@ -159,7 +165,7 @@ fn main() { radius, if selected_particle_id.is_some_and(|v| v == particle_id) { Color::RED - } else if watch_particle_id == particle_id { + } else if watch_particle_id.is_some_and(|v| v == particle_id) { Color::YELLOW } else { Color::BLACK |