1use crate::*;
2
3#[derive(Clone, Debug)]
4pub struct DebugData {
5 pub bodies: Vec<DebugRigidBody>,
6 pub joints: Vec<DebugJoint>,
7 pub colliders: Vec<DebugCollider>,
8 pub springs: Vec<DebugSpring>,
9}
10
11#[derive(Copy, Clone, Debug)]
12pub struct DebugRigidBody {
13 pub transform: Affine2,
14}
15
16#[derive(Copy, Clone, Debug)]
17pub struct DebugJoint {
18 pub body_a: Vec2,
19 pub body_b: Vec2,
20}
21
22#[derive(Copy, Clone, Debug)]
23pub struct DebugCollider {
24 pub transform: Affine2,
25 pub radius: f32,
26}
27
28#[derive(Copy, Clone, Debug)]
29pub struct DebugSpring {
30 pub body_a: Vec2,
31 pub body_b: Vec2,
32}
33
34pub(crate) fn make_debug_data(physics: &Physics) -> DebugData {
35 let bodies = physics
36 .rbd_set
37 .arena
38 .iter()
39 .map(|(_, body)| {
40 let transform = Affine2::from_angle_translation(body.rotation, body.position);
41 DebugRigidBody { transform }
42 })
43 .collect();
44
45 let joints = physics
46 .joints
47 .iter()
48 .map(|(_, joint)| {
49 let body_a = physics.rbd_set.arena[*joint.rigid_body_a].position;
50 let body_b = physics.rbd_set.arena[*joint.rigid_body_b].position;
51 DebugJoint { body_a, body_b }
52 })
53 .collect();
54
55 let colliders = physics
56 .col_set
57 .arena
58 .iter()
59 .map(|(_, collider)| {
60 let radius = match collider.shape.as_ball() {
61 Some(ball) => ball.radius,
62 None => {
63 println!("Invalid shape, expected ball");
64 1.0
65 }
66 };
67
68 DebugCollider {
69 transform: collider.absolute_transform,
70 radius,
71 }
72 })
73 .collect();
74
75 let springs = physics
76 .springs
77 .iter()
78 .map(|(_, spring)| {
79 let body_a = physics.rbd_set.arena[*spring.rigid_body_a].position;
80 let body_b = physics.rbd_set.arena[*spring.rigid_body_b].position;
81 DebugSpring { body_a, body_b }
82 })
83 .collect();
84
85 DebugData {
86 bodies,
87 joints,
88 colliders,
89 springs,
90 }
91}