tirbofish/dropbear
main / crates / eucalyptus-core / src / debug.rs · 2594 bytes
crates/eucalyptus-core/src/debug.rs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use glam::Quat;
use dropbear_engine::debug::DebugDraw;
use crate::physics::collider::ColliderShape;
/// Extension traits for [`DebugDraw`](dropbear_engine::debug::DebugDraw)
pub trait DebugDrawExt {
fn draw_collider(&mut self, shape: &ColliderShape, translation: glam::Vec3, scale: glam::Vec3, rotation: Quat, colour: [f32; 4]);
}
impl DebugDrawExt for DebugDraw {
fn draw_collider(&mut self, shape: &ColliderShape, translation: glam::Vec3, scale: glam::Vec3, rotation: Quat, colour: [f32; 4]) {
match &shape {
ColliderShape::Box { half_extents } => {
let he = glam::Vec3::new(
half_extents.x as f32 * scale.x,
half_extents.y as f32 * scale.y,
half_extents.z as f32 * scale.z,
);
self.draw_obb(translation, he, rotation, colour);
}
ColliderShape::Sphere { radius } => {
let r = radius * scale.x.max(scale.y).max(scale.z);
self.draw_sphere(translation, r, colour);
}
ColliderShape::Capsule {
half_height,
radius,
} => {
let axis = rotation * glam::Vec3::Y;
let top = translation + axis * (half_height * scale.y);
let bottom = translation - axis * (half_height * scale.y);
self.draw_capsule(
bottom,
top,
radius * scale.x.max(scale.z),
colour,
);
}
ColliderShape::Cylinder {
half_height,
radius,
} => {
let axis = rotation * glam::Vec3::Y;
self.draw_cylinder(
translation,
half_height * scale.y,
radius * scale.x.max(scale.z),
axis,
colour,
);
}
ColliderShape::Cone {
half_height,
radius,
} => {
let axis = rotation * glam::Vec3::Y;
let apex = translation + axis * (half_height * scale.y);
let height = 2.0 * half_height * scale.y;
let r = radius * scale.x.max(scale.z);
self.draw_cone(
apex,
-(rotation * glam::Vec3::Y),
(r / height).atan(),
height,
colour,
);
}
}
}
}