File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
lighthouse-protocol/src/input Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,10 @@ impl InputEvent {
3434
3535 /// Parses the input event as an arbitrary direction.
3636 pub fn direction ( & self ) -> Option < Direction > {
37- self . left_direction ( ) . or_else ( || self . right_direction ( ) )
37+ match self {
38+ InputEvent :: Orientation ( orientation) => orientation. direction ( ) ,
39+ _ => self . left_direction ( ) . or_else ( || self . right_direction ( ) ) ,
40+ }
3841 }
3942
4043 /// The direction if the input event represents a WASD key, D-pad or left stick.
Original file line number Diff line number Diff line change 11use serde:: { Deserialize , Serialize } ;
22
3+ use crate :: { Direction , Vec2 } ;
4+
35use super :: EventSource ;
46
57/// A device orientation event.
@@ -17,3 +19,18 @@ pub struct OrientationEvent {
1719 /// The motion of the device around the y-axis (left to right motion), in degrees from -90 (inclusive) to 90 (exclusive).
1820 pub gamma : Option < f64 > ,
1921}
22+
23+ impl OrientationEvent {
24+ /// The approximate direction (outside of a small deadzone) for a phone tilted against a flat surface.
25+ 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. max ( gamma) < deadzone_radius {
31+ return None ;
32+ }
33+
34+ Direction :: approximate_from ( Vec2 :: new ( gamma, beta) )
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments