better window bounding boxes
I also switch to using generalized Rect instead of an app for places where i was using the window boundary
This commit is contained in:
parent
4c36162aa5
commit
e259bf6019
1 changed files with 11 additions and 8 deletions
19
src/main.rs
19
src/main.rs
|
@ -18,7 +18,7 @@ const PARTICLE_SIZE: f32 = 5.;
|
|||
|
||||
struct Model {
|
||||
// Store the window ID so we can refer to this specific window later if needed.
|
||||
_window: WindowId,
|
||||
window: WindowId,
|
||||
// particles: Vec<Particle>,
|
||||
engine: PhysicsEngine,
|
||||
}
|
||||
|
@ -30,11 +30,10 @@ fn random_vec_in_rect(boundary: &Rect) -> nalgebra::Vector2<f32> {
|
|||
vector![x, y]
|
||||
}
|
||||
|
||||
fn fill_particles(app: &App, colliders: &mut ColliderSet, bodies: &mut RigidBodySet) {
|
||||
fn fill_particles(boundary: &Rect, colliders: &mut ColliderSet, bodies: &mut RigidBodySet) {
|
||||
// Keeping track of already placed balls to avoid overlap
|
||||
// Need to look into a way to do this with rapier directly
|
||||
let mut positions: Vec<nalgebra::Vector2<f32>> = Vec::new();
|
||||
let boundary = &app.window_rect();
|
||||
|
||||
for _ in 0..PARTICLE_COUNT {
|
||||
let mut xy = random_vec_in_rect(boundary);
|
||||
|
@ -62,7 +61,7 @@ fn model(app: &App) -> Model {
|
|||
// per app
|
||||
|
||||
// Create a new window! Store the ID so we can refer to it later.
|
||||
let _window = app
|
||||
let window = app
|
||||
.new_window()
|
||||
.size(WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||
.title("nannou")
|
||||
|
@ -79,7 +78,7 @@ fn model(app: &App) -> Model {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let boundary = app.window_rect();
|
||||
let boundary = app.window(window).unwrap().rect();
|
||||
|
||||
/* Create the ground. */
|
||||
let collider = ColliderBuilder::cuboid(boundary.w(), 4.)
|
||||
|
@ -103,9 +102,13 @@ fn model(app: &App) -> Model {
|
|||
.build();
|
||||
engine.state.colliders.insert(collider);
|
||||
|
||||
fill_particles(app, &mut engine.state.colliders, &mut engine.state.bodies);
|
||||
fill_particles(
|
||||
&boundary,
|
||||
&mut engine.state.colliders,
|
||||
&mut engine.state.bodies,
|
||||
);
|
||||
|
||||
Model { _window, engine }
|
||||
Model { window, engine }
|
||||
}
|
||||
|
||||
// Handle events related to the window and update the model if necessary
|
||||
|
@ -137,7 +140,7 @@ fn event(app: &App, model: &mut Model, event: WindowEvent) {
|
|||
}
|
||||
|
||||
fill_particles(
|
||||
app,
|
||||
&app.window(model.window).unwrap().rect(),
|
||||
&mut model.engine.state.colliders,
|
||||
&mut model.engine.state.bodies,
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue