Implement joint removal.

This commit is contained in:
Crozet Sébastien
2020-11-02 18:47:27 +01:00
parent 9c72a0458b
commit a4a4ddb5b4
2 changed files with 42 additions and 0 deletions

View File

@@ -847,6 +847,16 @@ impl Testbed {
);
}
}
WindowEvent::Key(Key::J, Action::Release, _) => {
// Delete 10% of the remaining joints.
let joints: Vec<_> = self.physics.joints.iter().map(|e| e.0).collect();
let num_to_delete = (joints.len() / 10).max(1);
for to_delete in &joints[..num_to_delete] {
self.physics
.joints
.remove(*to_delete, &mut self.physics.bodies, true);
}
}
WindowEvent::CursorPos(x, y, _) => {
self.cursor_pos.x = x as f32;
self.cursor_pos.y = y as f32;