Compare commits

..

No commits in common. "4c36162aa571adce8b3601fa8a663debe203bedf" and "5bba4f019e943f002fb28aa858aea1e51a043134" have entirely different histories.

1 changed files with 7 additions and 27 deletions

View File

@ -23,7 +23,9 @@ struct Model {
engine: PhysicsEngine, engine: PhysicsEngine,
} }
fn random_vec_in_rect(boundary: &Rect) -> nalgebra::Vector2<f32> { fn random_vec(_app: &App) -> nalgebra::Vector2<f32> {
let boundary = _app.window_rect();
let x = random_range(-100., 100.); let x = random_range(-100., 100.);
let y = random_range(-150., boundary.top()); let y = random_range(-150., boundary.top());
@ -34,15 +36,13 @@ fn fill_particles(app: &App, colliders: &mut ColliderSet, bodies: &mut RigidBody
// Keeping track of already placed balls to avoid overlap // Keeping track of already placed balls to avoid overlap
// Need to look into a way to do this with rapier directly // Need to look into a way to do this with rapier directly
let mut positions: Vec<nalgebra::Vector2<f32>> = Vec::new(); let mut positions: Vec<nalgebra::Vector2<f32>> = Vec::new();
let boundary = &app.window_rect();
for _ in 0..PARTICLE_COUNT { for _ in 0..PARTICLE_COUNT {
let mut xy = random_vec_in_rect(boundary); let mut xy = random_vec(app);
while !positions while !positions
.iter() .iter()
.all(|pos| pos.metric_distance(&xy) > PARTICLE_SIZE * 2.) .all(|pos| pos.metric_distance(&xy) > PARTICLE_SIZE * 2.)
{ {
xy = random_vec_in_rect(boundary) xy = random_vec(app)
} }
positions.push(xy); positions.push(xy);
@ -79,27 +79,9 @@ fn model(app: &App) -> Model {
..Default::default() ..Default::default()
}; };
let boundary = app.window_rect();
/* Create the ground. */ /* Create the ground. */
let collider = ColliderBuilder::cuboid(boundary.w(), 4.) let collider = ColliderBuilder::cuboid(100., 10.)
.translation(vector![0., boundary.bottom()]) .translation(vector![0., -200.])
.build();
engine.state.colliders.insert(collider);
/* Create the walls. */
let collider = ColliderBuilder::cuboid(4., boundary.h())
.translation(vector![boundary.left(), 0.])
.build();
engine.state.colliders.insert(collider);
let collider = ColliderBuilder::cuboid(4., boundary.h())
.translation(vector![boundary.right(), 0.])
.build();
engine.state.colliders.insert(collider);
/* Create the ceiling. */
let collider = ColliderBuilder::cuboid(boundary.w(), 4.)
.translation(vector![0., boundary.top()])
.build(); .build();
engine.state.colliders.insert(collider); engine.state.colliders.insert(collider);
@ -115,8 +97,6 @@ fn event(app: &App, model: &mut Model, event: WindowEvent) {
} }
if let Resized(_) = event { if let Resized(_) = event {
// Rust borrowing rules means I need to first gather a list of handles,
// then delete them all
let handles: Vec<RigidBodyHandle> = model let handles: Vec<RigidBodyHandle> = model
.engine .engine
.state .state