diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-18 20:20:32 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-18 20:20:32 -0700 |
| commit | 92dd02d7cc4d9fc930760d26d81edbe2197a3fc0 (patch) | |
| tree | 6dfde8d306d20266c2185882c635360478a2b6ef /src/sim/rb_sim/debug_ops.rs | |
| parent | 5877fbf3991b1f35696bf86d9e1b3da3ece01f42 (diff) | |
marching rigid bodies
Diffstat (limited to 'src/sim/rb_sim/debug_ops.rs')
| -rw-r--r-- | src/sim/rb_sim/debug_ops.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/sim/rb_sim/debug_ops.rs b/src/sim/rb_sim/debug_ops.rs new file mode 100644 index 0000000..d6852da --- /dev/null +++ b/src/sim/rb_sim/debug_ops.rs @@ -0,0 +1,48 @@ +use glam::{ivec2, vec2}; + +use crate::sim::{ + cell::{cell::Cell, materials::MaterialId}, + rb_sim::RbSimManager, +}; + +pub trait DebugOperator { + fn test_spawn_box(&mut self, x: f32, y: f32, material: MaterialId) -> (); + fn test_spawn_ball(&mut self, x: f32, y: f32, material: MaterialId) -> (); +} + +impl DebugOperator for RbSimManager { + fn test_spawn_box(&mut self, x: f32, y: f32, material: MaterialId) { + let w = 10; + let h = 10; + let mut test_cells = vec![Cell::void(); (w * h) as usize]; + + for x in 0..w { + for y in 0..h { + let cell_idx = x + y * w; + test_cells[cell_idx as usize] = Cell::from_material(material); + test_cells[cell_idx as usize].set_rb(true); + } + } + + self.create_rb_entity(vec2(x, y), test_cells, w, h); + } + + fn test_spawn_ball(&mut self, x: f32, y: f32, material: MaterialId) { + let r = 5; + let w = r * 2; + let h = r * 2; + let mut test_cells = vec![Cell::void(); (w * h) as usize]; + + for x in 0..w { + for y in 0..h { + let cell_idx = x + y * w; + if ivec2(x, y).distance_squared(ivec2(w / 2, h / 2)) < r.pow(2) { + test_cells[cell_idx as usize] = Cell::from_material(material); + test_cells[cell_idx as usize].set_rb(true); + } + } + } + + self.create_rb_entity(vec2(x, y), test_cells, w, h); + } +} |
