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 73 74 75 76 77
use std::sync::Arc; use std::cell::RefCell; use VRPose; pub type VRGamepadPtr = Arc<RefCell<VRGamepad>>; pub trait VRGamepad { fn id(&self) -> u32; fn data(&self) -> VRGamepadData; fn state(&self) -> VRGamepadState; } #[derive(Debug, Clone)] #[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))] pub struct VRGamepadState { pub gamepad_id: u32, pub connected: bool, pub timestamp: f64, pub axes: Vec<f64>, pub buttons: Vec<VRGamepadButton>, pub pose: VRPose } impl Default for VRGamepadState { fn default() -> VRGamepadState { VRGamepadState { gamepad_id: 0, connected: false, timestamp: 0.0, axes: Vec::new(), buttons: Vec::new(), pose: VRPose::default() } } } #[derive(Debug, Clone)] #[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))] pub enum VRGamepadHand { Unknown, Left, Right } #[derive(Debug, Clone)] #[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))] pub struct VRGamepadData { pub display_id: u32, pub name: String, pub hand: VRGamepadHand } impl Default for VRGamepadData { fn default() -> VRGamepadData { Self { display_id: 0, name: String::new(), hand: VRGamepadHand::Unknown } } } #[derive(Debug, Clone)] #[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))] pub struct VRGamepadButton { pub pressed: bool, pub touched: bool } impl VRGamepadButton { pub fn new(pressed: bool) -> Self { Self { pressed: pressed, touched: pressed, } } }