Compare commits
3 Commits
5bba4f019e
...
4c36162aa5
Author | SHA1 | Date |
---|---|---|
Zynh0722 | 4c36162aa5 | |
Zynh0722 | 8cde3ba399 | |
Zynh0722 | 1e90b2c514 |
34
src/main.rs
34
src/main.rs
|
@ -23,9 +23,7 @@ struct Model {
|
|||
engine: PhysicsEngine,
|
||||
}
|
||||
|
||||
fn random_vec(_app: &App) -> nalgebra::Vector2<f32> {
|
||||
let boundary = _app.window_rect();
|
||||
|
||||
fn random_vec_in_rect(boundary: &Rect) -> nalgebra::Vector2<f32> {
|
||||
let x = random_range(-100., 100.);
|
||||
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
|
||||
// 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(app);
|
||||
let mut xy = random_vec_in_rect(boundary);
|
||||
while !positions
|
||||
.iter()
|
||||
.all(|pos| pos.metric_distance(&xy) > PARTICLE_SIZE * 2.)
|
||||
{
|
||||
xy = random_vec(app)
|
||||
xy = random_vec_in_rect(boundary)
|
||||
}
|
||||
positions.push(xy);
|
||||
|
||||
|
@ -79,9 +79,27 @@ fn model(app: &App) -> Model {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let boundary = app.window_rect();
|
||||
|
||||
/* Create the ground. */
|
||||
let collider = ColliderBuilder::cuboid(100., 10.)
|
||||
.translation(vector![0., -200.])
|
||||
let collider = ColliderBuilder::cuboid(boundary.w(), 4.)
|
||||
.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();
|
||||
engine.state.colliders.insert(collider);
|
||||
|
||||
|
@ -97,6 +115,8 @@ fn event(app: &App, model: &mut Model, event: WindowEvent) {
|
|||
}
|
||||
|
||||
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
|
||||
.engine
|
||||
.state
|
||||
|
|
Loading…
Reference in New Issue