emulate old reset behaviour
This commit is contained in:
parent
ab92ac9430
commit
8d822448f8
2 changed files with 28 additions and 50 deletions
35
src/main.rs
35
src/main.rs
|
@ -8,7 +8,7 @@ use engine::{PhysicsEngine, PhysicsState};
|
|||
use nalgebra::vector;
|
||||
use nannou::prelude::*;
|
||||
use rapier2d::{
|
||||
dynamics::{RigidBodyBuilder, RigidBodySet},
|
||||
dynamics::{RigidBodyBuilder, RigidBodyHandle, RigidBodySet},
|
||||
geometry::{ColliderBuilder, ColliderSet},
|
||||
};
|
||||
|
||||
|
@ -82,16 +82,37 @@ fn model(app: &App) -> Model {
|
|||
}
|
||||
|
||||
// Handle events related to the window and update the model if necessary
|
||||
fn event(app: &App, _model: &mut Model, event: WindowEvent) {
|
||||
fn event(app: &App, model: &mut Model, event: WindowEvent) {
|
||||
if let KeyReleased(Key::Escape) = event {
|
||||
app.quit()
|
||||
}
|
||||
|
||||
// if let Resized(_) = event {
|
||||
// model.particles.clear();
|
||||
//
|
||||
// fill_particles(app, &mut model.particles);
|
||||
// }
|
||||
if let Resized(_) = event {
|
||||
let handles: Vec<RigidBodyHandle> = model
|
||||
.engine
|
||||
.state
|
||||
.bodies
|
||||
.iter()
|
||||
.map(|(handle, _)| handle)
|
||||
.collect();
|
||||
|
||||
for handle in handles {
|
||||
model.engine.state.bodies.remove(
|
||||
handle,
|
||||
&mut model.engine.state.islands,
|
||||
&mut model.engine.state.colliders,
|
||||
&mut model.engine.state.joints,
|
||||
&mut model.engine.state.multibody_joints,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
fill_particles(
|
||||
app,
|
||||
&mut model.engine.state.colliders,
|
||||
&mut model.engine.state.bodies,
|
||||
);
|
||||
}
|
||||
|
||||
// println!("{:?}", event);
|
||||
}
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
use crate::drawable::Drawable;
|
||||
use crate::PARTICLE_SIZE;
|
||||
|
||||
use nannou::prelude::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Particle {
|
||||
pub pos: Vec2,
|
||||
pub start_pos: Vec2,
|
||||
pub radius: f32,
|
||||
pub time_offset: f32,
|
||||
}
|
||||
|
||||
impl Particle {
|
||||
pub fn new(pos: Vec2) -> Self {
|
||||
Self {
|
||||
pos,
|
||||
start_pos: pos,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Particle {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pos: Default::default(),
|
||||
radius: PARTICLE_SIZE,
|
||||
start_pos: Default::default(),
|
||||
time_offset: random_range(-PI, PI),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Particle {
|
||||
fn draw(&self, draw: &Draw) {
|
||||
draw.ellipse()
|
||||
.color(RED)
|
||||
.stroke_weight(1.0)
|
||||
.radius(self.radius)
|
||||
.xy(self.pos);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue