Compare commits

...

3 Commits

Author SHA1 Message Date
Zynh0722 4c36162aa5 walls! 2024-02-17 02:29:06 -08:00
Zynh0722 8cde3ba399 switch to using a generic rect 2024-02-17 02:28:54 -08:00
Zynh0722 1e90b2c514 comments 2: electric boogaloo 2024-02-17 02:27:32 -08:00
1 changed files with 27 additions and 7 deletions

View File

@ -23,9 +23,7 @@ struct Model {
engine: PhysicsEngine, engine: PhysicsEngine,
} }
fn random_vec(_app: &App) -> nalgebra::Vector2<f32> { fn random_vec_in_rect(boundary: &Rect) -> 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());
@ -36,13 +34,15 @@ 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(app); let mut xy = random_vec_in_rect(boundary);
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(app) xy = random_vec_in_rect(boundary)
} }
positions.push(xy); positions.push(xy);
@ -79,9 +79,27 @@ fn model(app: &App) -> Model {
..Default::default() ..Default::default()
}; };
let boundary = app.window_rect();
/* Create the ground. */ /* Create the ground. */
let collider = ColliderBuilder::cuboid(100., 10.) let collider = ColliderBuilder::cuboid(boundary.w(), 4.)
.translation(vector![0., -200.]) .translation(vector![0., boundary.bottom()])
.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);
@ -97,6 +115,8 @@ 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