35 lines
1,004 B
Rust
35 lines
1,004 B
Rust
use raidillon_app::prelude::*;
|
|
|
|
/// renders aabb wireframes for all physics colliders
|
|
#[derive(Default)]
|
|
pub struct PhysicsDebugSystem;
|
|
|
|
impl System for PhysicsDebugSystem {
|
|
fn frame_update(&mut self, res: &mut EngineResources, scene: &mut Scene) {
|
|
let pctx = res.get::<PlatformContext>().expect("PlatformContext missing").clone();
|
|
|
|
let mut debug_wireframes = pctx.debug_wireframes.borrow_mut();
|
|
if !debug_wireframes.enabled {
|
|
return;
|
|
}
|
|
|
|
let physics = match scene.resources.get::<Physics>() {
|
|
Some(p) => p,
|
|
None => return,
|
|
};
|
|
|
|
let color = [1.0, 0.0, 0.0, 1.0];
|
|
|
|
for (_, collider) in physics.collider_set.iter() {
|
|
let aabb = collider.compute_aabb();
|
|
let min = aabb.mins;
|
|
let max = aabb.maxs;
|
|
|
|
debug_wireframes.add_box(
|
|
[min.x, min.y, min.z],
|
|
[max.x, max.y, max.z],
|
|
color,
|
|
);
|
|
}
|
|
}
|
|
}
|