dynamis_model/
collider.rs1use crate::shape::Shape;
2
3#[derive(Clone, Copy, Debug)]
4pub struct ColliderDesc {
5 pub shape: Shape,
6 pub offset: [f32; 3],
7 pub rotation: [f32; 4],
8 pub friction: f32,
9 pub restitution: f32,
10 pub sensor: bool,
11}
12
13impl ColliderDesc {
14 pub fn new(shape: Shape) -> Self {
15 Self {
16 shape,
17 offset: [0.0; 3],
18 rotation: [0.0, 0.0, 0.0, 1.0],
19 friction: 0.5,
20 restitution: 0.0,
21 sensor: false,
22 }
23 }
24
25 pub fn offset(mut self, offset: [f32; 3]) -> Self {
26 self.offset = offset;
27 self
28 }
29
30 pub fn rotation(mut self, rotation: [f32; 4]) -> Self {
31 assert!(
32 (rotation[0] * rotation[0]
33 + rotation[1] * rotation[1]
34 + rotation[2] * rotation[2]
35 + rotation[3] * rotation[3]
36 - 1.0)
37 .abs()
38 < 1e-4,
39 "rotation must be a unit quaternion"
40 );
41 self.rotation = rotation;
42 self
43 }
44
45 pub fn friction(mut self, friction: f32) -> Self {
46 assert!(friction >= 0.0, "friction must be non-negative");
47 self.friction = friction;
48 self
49 }
50
51 pub fn restitution(mut self, restitution: f32) -> Self {
52 self.restitution = restitution;
53 self
54 }
55
56 pub fn sensor(mut self, sensor: bool) -> Self {
57 self.sensor = sensor;
58 self
59 }
60}