webxr_api/
input.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use euclid::RigidTransform3D;
6use serde::{Deserialize, Serialize};
7
8use crate::{Hand, Input, JointFrame, Native};
9
10#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
11pub struct InputId(pub u32);
12
13#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
14pub enum Handedness {
15    None,
16    Left,
17    Right,
18}
19
20#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
21pub enum TargetRayMode {
22    Gaze,
23    TrackedPointer,
24    Screen,
25    TransientPointer,
26}
27
28#[derive(Clone, Debug, Serialize, Deserialize)]
29pub struct InputSource {
30    pub handedness: Handedness,
31    pub target_ray_mode: TargetRayMode,
32    pub id: InputId,
33    pub supports_grip: bool,
34    pub hand_support: Option<Hand<()>>,
35    pub profiles: Vec<String>,
36}
37
38#[derive(Clone, Debug, Serialize, Deserialize)]
39pub struct InputFrame {
40    pub id: InputId,
41    pub target_ray_origin: Option<RigidTransform3D<f32, Input, Native>>,
42    pub grip_origin: Option<RigidTransform3D<f32, Input, Native>>,
43    pub pressed: bool,
44    pub hand: Option<Box<Hand<JointFrame>>>,
45    pub squeezed: bool,
46    pub button_values: Vec<f32>,
47    pub axis_values: Vec<f32>,
48    pub input_changed: bool,
49}
50
51#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
52pub enum SelectEvent {
53    /// Selection started
54    Start,
55    /// Selection ended *without* it being a contiguous select event
56    End,
57    /// Selection ended *with* it being a contiguous select event
58    Select,
59}
60
61#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
62pub enum SelectKind {
63    Select,
64    Squeeze,
65}