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
72
use crate::bind;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Direction {
Polar {
degree_100: i32,
},
Cartesian {
x: i32,
y: i32,
z: i32,
},
Spherical {
z_degree_100: i32,
elevation_degree_100: i32,
},
}
impl Direction {
pub(super) fn into_raw(self) -> bind::SDL_HapticDirection {
match self {
Direction::Polar { degree_100 } => bind::SDL_HapticDirection {
type_: bind::SDL_HAPTIC_POLAR as u8,
dir: [degree_100, 0, 0],
},
Direction::Cartesian { x, y, z } => bind::SDL_HapticDirection {
type_: bind::SDL_HAPTIC_CARTESIAN as u8,
dir: [x, y, z],
},
Direction::Spherical {
z_degree_100,
elevation_degree_100,
} => bind::SDL_HapticDirection {
type_: bind::SDL_HAPTIC_SPHERICAL as u8,
dir: [z_degree_100, elevation_degree_100, 0],
},
}
}
}
impl From<bind::SDL_HapticDirection> for Direction {
fn from(raw: bind::SDL_HapticDirection) -> Self {
match raw.type_ as u32 {
bind::SDL_HAPTIC_POLAR => Self::Polar {
degree_100: raw.dir[0],
},
bind::SDL_HAPTIC_CARTESIAN => Self::Cartesian {
x: raw.dir[0],
y: raw.dir[0],
z: raw.dir[0],
},
bind::SDL_HAPTIC_SPHERICAL => Self::Spherical {
z_degree_100: raw.dir[0],
elevation_degree_100: raw.dir[1],
},
_ => unreachable!(),
}
}
}