Add debug wireframe rendering support
This commit is contained in:
parent
8041c7e01d
commit
73692b710e
12 changed files with 221 additions and 7 deletions
35
game/src/systems/physics_debug.rs
Normal file
35
game/src/systems/physics_debug.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue