lighthouse_protocol/input/
orientation_event.rs1use serde::{Deserialize, Serialize};
2
3use crate::{Direction, Vec2};
4
5use super::EventSource;
6
7#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
9#[serde(rename_all = "camelCase")]
10pub struct OrientationEvent {
11 pub source: EventSource,
13 pub absolute: Option<bool>,
15 pub alpha: Option<f64>,
17 pub beta: Option<f64>,
19 pub gamma: Option<f64>,
21}
22
23impl OrientationEvent {
24 pub fn direction(&self) -> Option<Direction> {
26 let Some(beta) = self.beta else { return None };
27 let Some(gamma) = self.gamma else { return None };
28
29 let deadzone_radius: f64 = 10.0;
30 if beta.abs().max(gamma.abs()) < deadzone_radius {
31 return None;
32 }
33
34 Direction::approximate_from(Vec2::new(gamma, beta))
35 }
36}