rich_sdl2_rust/haptic/
direction.rs1use crate::bind;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum Direction {
9 Polar {
11 degree_100: i32,
13 },
14 Cartesian {
16 x: i32,
18 y: i32,
20 z: i32,
22 },
23 Spherical {
25 z_degree_100: i32,
27 elevation_degree_100: i32,
29 },
30}
31
32impl Direction {
33 pub(super) fn into_raw(self) -> bind::SDL_HapticDirection {
34 match self {
35 Direction::Polar { degree_100 } => bind::SDL_HapticDirection {
36 type_: bind::SDL_HAPTIC_POLAR as u8,
37 dir: [degree_100, 0, 0],
38 },
39 Direction::Cartesian { x, y, z } => bind::SDL_HapticDirection {
40 type_: bind::SDL_HAPTIC_CARTESIAN as u8,
41 dir: [x, y, z],
42 },
43 Direction::Spherical {
44 z_degree_100,
45 elevation_degree_100,
46 } => bind::SDL_HapticDirection {
47 type_: bind::SDL_HAPTIC_SPHERICAL as u8,
48 dir: [z_degree_100, elevation_degree_100, 0],
49 },
50 }
51 }
52}
53
54impl From<bind::SDL_HapticDirection> for Direction {
55 fn from(raw: bind::SDL_HapticDirection) -> Self {
56 match raw.type_ as u32 {
57 bind::SDL_HAPTIC_POLAR => Self::Polar {
58 degree_100: raw.dir[0],
59 },
60 bind::SDL_HAPTIC_CARTESIAN => Self::Cartesian {
61 x: raw.dir[0],
62 y: raw.dir[0],
63 z: raw.dir[0],
64 },
65 bind::SDL_HAPTIC_SPHERICAL => Self::Spherical {
66 z_degree_100: raw.dir[0],
67 elevation_degree_100: raw.dir[1],
68 },
69 _ => unreachable!(),
70 }
71 }
72}