Skip to content

Commit 37c1387

Browse files
committed
Old code cleanup
1 parent 0bdb07c commit 37c1387

File tree

4 files changed

+92
-130
lines changed

4 files changed

+92
-130
lines changed

demo/src/demos/balls.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pub struct BallsDemo {
77
pub sim: Simulation,
88
pub drag: Option<DragState>,
99
pub hover: Option<HoverState>,
10+
11+
pub mouse_rbd: RigidBodyHandle,
1012
}
1113

1214
impl BallsDemo {
@@ -18,10 +20,10 @@ impl BallsDemo {
1820

1921
let mut sim = make_world(gravity);
2022

21-
let a = sim.balls.insert(TestObject {
22-
position: Vec2::ZERO,
23-
color: PINK,
24-
});
23+
// let a = sim.balls.insert(TestObject {
24+
// position: Vec2::ZERO,
25+
// color: PINK,
26+
// });
2527

2628
let mouse_rbd = sim.spawn_ball(
2729
RigidBodyDesc {
@@ -57,10 +59,10 @@ impl BallsDemo {
5759
//
5860
// let rbd_handle = sim.physics.insert_rbd(rbd);
5961

60-
let a = sim.balls.insert(TestObject {
61-
position: Vec2::ZERO,
62-
color: GREEN,
63-
});
62+
// let a = sim.balls.insert(TestObject {
63+
// position: Vec2::ZERO,
64+
// color: GREEN,
65+
// });
6466

6567
// let torque_test_rbd = spawn_rbd_entity(
6668
// &mut sim.physics,
@@ -82,6 +84,8 @@ impl BallsDemo {
8284
sim,
8385
drag: None,
8486
hover: None,
87+
88+
mouse_rbd,
8589
}
8690
}
8791

demo/src/demos/springs.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// {
2+
// let spacing = 0.3;
3+
// let num = 10;
4+
// let w = num;
5+
// let h = num;
6+
//
7+
// let offset = -vec2(w as f32 * spacing, h as f32 * spacing) / 2.0;
8+
//
9+
// let grid = grids::Grid::filled_with(w, h, |x, y| {
10+
// let idx = sim.balls.insert(TestObject {
11+
// position: Vec2::ZERO,
12+
// color: YELLOW,
13+
// });
14+
//
15+
// let rbd_handle = spawn_rbd_entity(
16+
// &mut sim.physics,
17+
// idx,
18+
// RigidBodyDesc {
19+
// position: vec2(x as f32 * spacing, y as f32 * spacing) + offset,
20+
// radius: 0.1,
21+
// // gravity_mod: 0.0,
22+
// ..Default::default()
23+
// },
24+
// );
25+
//
26+
// (idx, rbd_handle)
27+
// });
28+
//
29+
// for (x, y, (_, rbd_handle_a)) in grid.iter() {
30+
// if x < grid.width() - 1 {
31+
// let rbd_handle_b = grid[(x + 1, y)].1;
32+
// sim.physics
33+
// .create_fixed_joint(*rbd_handle_a, rbd_handle_b, Vec2::ZERO, Vec2::ZERO);
34+
// }
35+
// if y < grid.width() - 1 {
36+
// let rbd_handle_b = grid[(x, y + 1)].1;
37+
// sim.physics
38+
// .create_fixed_joint(*rbd_handle_a, rbd_handle_b, Vec2::ZERO, Vec2::ZERO);
39+
// }
40+
// }
41+
//
42+
// let a = sim.balls.insert(TestObject {
43+
// position: Vec2::ZERO,
44+
// color: ORANGE,
45+
// });
46+
//
47+
// let cloth_pin = spawn_rbd_entity(
48+
// &mut sim.physics,
49+
// a,
50+
// RigidBodyDesc {
51+
// position: vec2(0.0, 3.5),
52+
// body_type: RigidBodyType::Static,
53+
// collision_groups: groups(0, 0),
54+
// // gravity_mod: 0.0,
55+
// ..Default::default()
56+
// },
57+
// );
58+
//
59+
// let grid_anchor = grid[(5, 0)].1;
60+
//
61+
// // let spring = blobs.springs.insert(Spring {
62+
// // rigid_body_a: grid_anchor,
63+
// // rigid_body_b: cloth_pin,
64+
// // rest_length: 1.0,
65+
// // stiffness: 3000.0,
66+
// // damping: 50.0,
67+
// // });
68+
//
69+
// sim.physics.create_fixed_joint_with_distance(
70+
// grid_anchor,
71+
// cloth_pin,
72+
// Vec2::ZERO,
73+
// Vec2::ZERO,
74+
// 0.1,
75+
// );
76+
// }

demo/src/main.rs

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -55,83 +55,6 @@ fn make_world(gravity: Vec2) -> Simulation {
5555

5656
let sim = Simulation::new(blob_physics);
5757

58-
// {
59-
// let spacing = 0.3;
60-
// let num = 10;
61-
// let w = num;
62-
// let h = num;
63-
//
64-
// let offset = -vec2(w as f32 * spacing, h as f32 * spacing) / 2.0;
65-
//
66-
// let grid = grids::Grid::filled_with(w, h, |x, y| {
67-
// let idx = sim.balls.insert(TestObject {
68-
// position: Vec2::ZERO,
69-
// color: YELLOW,
70-
// });
71-
//
72-
// let rbd_handle = spawn_rbd_entity(
73-
// &mut sim.physics,
74-
// idx,
75-
// RigidBodyDesc {
76-
// position: vec2(x as f32 * spacing, y as f32 * spacing) + offset,
77-
// radius: 0.1,
78-
// // gravity_mod: 0.0,
79-
// ..Default::default()
80-
// },
81-
// );
82-
//
83-
// (idx, rbd_handle)
84-
// });
85-
//
86-
// for (x, y, (_, rbd_handle_a)) in grid.iter() {
87-
// if x < grid.width() - 1 {
88-
// let rbd_handle_b = grid[(x + 1, y)].1;
89-
// sim.physics
90-
// .create_fixed_joint(*rbd_handle_a, rbd_handle_b, Vec2::ZERO, Vec2::ZERO);
91-
// }
92-
// if y < grid.width() - 1 {
93-
// let rbd_handle_b = grid[(x, y + 1)].1;
94-
// sim.physics
95-
// .create_fixed_joint(*rbd_handle_a, rbd_handle_b, Vec2::ZERO, Vec2::ZERO);
96-
// }
97-
// }
98-
//
99-
// let a = sim.balls.insert(TestObject {
100-
// position: Vec2::ZERO,
101-
// color: ORANGE,
102-
// });
103-
//
104-
// let cloth_pin = spawn_rbd_entity(
105-
// &mut sim.physics,
106-
// a,
107-
// RigidBodyDesc {
108-
// position: vec2(0.0, 3.5),
109-
// body_type: RigidBodyType::Static,
110-
// collision_groups: groups(0, 0),
111-
// // gravity_mod: 0.0,
112-
// ..Default::default()
113-
// },
114-
// );
115-
//
116-
// let grid_anchor = grid[(5, 0)].1;
117-
//
118-
// // let spring = blobs.springs.insert(Spring {
119-
// // rigid_body_a: grid_anchor,
120-
// // rigid_body_b: cloth_pin,
121-
// // rest_length: 1.0,
122-
// // stiffness: 3000.0,
123-
// // damping: 50.0,
124-
// // });
125-
//
126-
// sim.physics.create_fixed_joint_with_distance(
127-
// grid_anchor,
128-
// cloth_pin,
129-
// Vec2::ZERO,
130-
// Vec2::ZERO,
131-
// 0.1,
132-
// );
133-
// }
134-
13558
// spawn_body(&mut sim, vec2(0.5, 0.5), BLUE);
13659
// spawn_body(&mut sim, vec2(0.5, 0.5), BLUE);
13760

demo/src/simulation.rs

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -72,59 +72,18 @@ impl Simulation {
7272
self.physics.borrow().col_set.len()
7373
}
7474

75-
pub fn spawn_ball(&mut self, desc: RigidBodyDesc, color: Color) {
75+
pub fn spawn_ball(&mut self, desc: RigidBodyDesc, color: Color) -> RigidBodyHandle {
7676
let id = self.balls.insert(TestObject {
7777
position: Vec2::ZERO,
7878
color,
7979
});
80+
8081
spawn_rbd_entity(&mut self.physics.borrow_mut(), id, desc);
82+
83+
RigidBodyHandle(id)
8184
}
8285
}
8386

84-
// pub trait PhysicsEngine {
85-
// fn as_any(&mut self) -> &mut dyn Any;
86-
// fn step(&mut self, delta: f64);
87-
//
88-
// fn spawn_ball(&mut self, id: Index, desc: RigidBodyDesc);
89-
// fn collider_count(&self) -> usize;
90-
// }
91-
92-
// fn collider(&self, index: Index) -> SimpleCollider;
93-
// impl PhysicsEngine for blobs::Physics {
94-
// fn as_any(&mut self) -> &mut dyn Any {
95-
// self
96-
// }
97-
//
98-
// fn step(&mut self, delta: f64) {
99-
// self.fixed_step(delta);
100-
// }
101-
//
102-
// fn spawn_ball(&mut self, id: Index, desc: RigidBodyDesc) {
103-
// spawn_rbd_entity(self, id, desc);
104-
// }
105-
//
106-
// fn collider_count(&self) -> usize {
107-
// self.col_set.arena.len()
108-
// }
109-
//
110-
// fn colliders(&self) -> Vec<(Vec2, f32)> {
111-
// self.rbd_set
112-
// .arena
113-
// .iter()
114-
// .map(|(_, x)| (x.position, x.radius))
115-
// .collect()
116-
// }
117-
//
118-
// fn collider(&self, index: Index) -> SimpleCollider {
119-
// let collider = self.col_set.arena.get(index).unwrap();
120-
//
121-
// SimpleCollider {
122-
// position: collider.absolute_translation(),
123-
// radius: collider.radius,
124-
// }
125-
// }
126-
// }
127-
12887
pub fn rbd_from_desc(id: Index, desc: RigidBodyDesc) -> RigidBody {
12988
let user_data: u128 = id.to_bits() as u128;
13089

0 commit comments

Comments
 (0)