Repository navigation
Expand file tree
/
Copy pathrs_debug_render2.rs
More file actions
51 lines (44 loc) · 1.58 KB
/
Copy pathrs_debug_render2.rs
File metadata and controls
51 lines (44 loc) · 1.58 KB
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
49
50
51
use rapier2d::prelude::*;
// DOCUSAURUS: DebugRenderBackend start
// The backend receives the lines to be drawn. A real one would push them to the renderer of the
// application instead of collecting them.
struct LineCollector {
lines: Vec<(Vector, Vector, DebugColor)>,
}
impl DebugRenderBackend for LineCollector {
fn draw_line(&mut self, _object: DebugRenderObject, a: Vector, b: Vector, color: DebugColor) {
self.lines.push((a, b, color));
}
}
// DOCUSAURUS: DebugRenderBackend stop
fn main() {
let mut world = PhysicsWorld::new();
world.insert_collider(ColliderBuilder::cuboid(100.0, 0.1), None);
world.insert(
RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 1.0)),
ColliderBuilder::ball(0.5),
);
// DOCUSAURUS: DebugRender start
// The style gives the colors and sizes, the mode selects what is drawn.
let mut debug_render = DebugRenderPipeline::new(
DebugRenderStyle::default(),
DebugRenderMode::COLLIDER_SHAPES | DebugRenderMode::CONTACTS,
);
let mut backend = LineCollector { lines: vec![] };
for _ in 0..10 {
world.step();
// The debug-rendering is done after the step, once per frame to be drawn.
backend.lines.clear();
debug_render.render(
&mut backend,
&world.bodies,
&world.colliders,
&world.impulse_joints,
&world.multibody_joints,
&world.narrow_phase,
&world.soft_bodies,
);
}
println!("{} lines to draw", backend.lines.len());
// DOCUSAURUS: DebugRender stop
}