1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
use glam::{ivec2, vec2};
use crate::sim::{
cell::{cell::Cell, materials::MaterialId},
rb_manager::RbManager,
};
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 RbManager {
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);
}
}
|