#[repr(C)]pub struct Controller {
pub pose: Pose,
pub palm: Pose,
pub aim: Pose,
pub tracked: BtnState,
pub tracked_pos: TrackState,
pub tracked_rot: TrackState,
pub stick_click: BtnState,
pub x1: BtnState,
pub x2: BtnState,
pub trigger: f32,
pub grip: f32,
pub stick: Vec2,
}
Expand description
This represents a physical controller input device! Tracking information, buttons, analog sticks and triggers! There’s also a Menu button that’s tracked separately at Input.ContollerMenu. https://stereokit.net/Pages/StereoKit/Controller.html
see also Input::controller
§Examples
use stereokit_rust::{system::{Hierarchy, Input, Handed},
maths::{Matrix}, model::Model, material::Material};
let model_left = Input::get_controller_model(Handed::Left);
let model_right = Input::get_controller_model(Handed::Right);
let transform_left = Matrix::t_r([-0.05, 0.0, 0.93], [90.0, 00.0, 0.0]);
let transform_right = Matrix::t_r([0.05, 0.0, 0.93], [90.0, 00.0, 0.0]);
filename_scr = "screenshots/controller.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
model_left.draw(token, transform_left, None, None);
model_right.draw(token, transform_right, None, None);
);

use stereokit_rust::{system::{Input, Handed, BtnState, TrackState},
maths::{Vec2, Vec3, Quat, Pose}};
let controller = Input::controller(Handed::Left);
let controller = Input::controller(Handed::Right);
assert_eq!(controller.pose, Pose::ZERO);
assert_eq!(controller.palm, Pose::ZERO);
assert_eq!(controller.aim, Pose::ZERO);
assert_eq!(controller.tracked, BtnState::Inactive);
assert_eq!(controller.tracked_pos, TrackState::Lost);
assert_eq!(controller.tracked_rot, TrackState::Lost);
assert_eq!(controller.x1, BtnState::Inactive);
assert_eq!(controller.x2, BtnState::Inactive);
assert_eq!(controller.trigger, 0.0);
assert_eq!(controller.grip, 0.0);
assert_eq!(controller.stick, Vec2::ZERO);
assert_eq!(controller.is_just_tracked(), false);
assert_eq!(controller.is_just_untracked(), false);
assert_eq!(controller.is_stick_clicked(), false);
assert_eq!(controller.is_stick_just_clicked(), false);
assert_eq!(controller.is_tracked(), false);
assert_eq!(controller.is_x1_just_pressed(), false);
assert_eq!(controller.is_x1_just_unpressed(), false);
assert_eq!(controller.is_x1_pressed(), false);
assert_eq!(controller.is_x2_just_pressed(), false);
assert_eq!(controller.is_x2_just_unpressed(), false);
assert_eq!(controller.is_x2_pressed(), false);
Fields§
§pose: Pose
The grip pose of the controller. This approximately represents the center of the hand’s position. Check trackedPos and trackedRot for the current state of the pose data.
palm: Pose
§aim: Pose
The aim pose of a controller is where the controller ‘points’ from and to. This is great for pointer rays and far interactions.
tracked: BtnState
This tells the current tracking state of this controller overall. If either position or rotation are trackable, then this will report tracked. Typically, positional tracking will be lost first, when the controller goes out of view, and rotational tracking will often remain as long as the controller is still connected. This is a good way to check if the controller is connected to the system at all.
tracked_pos: TrackState
This tells the current tracking state of the controller’s position information. This is often the first part of tracking data to go, so it can often be good to account for this on occasions.
tracked_rot: TrackState
This tells the current tracking state of the controller’s rotational information.
stick_click: BtnState
This represents the click state of the controller’s analog stick or directional controller.
x1: BtnState
The current state of the controller’s X1 button. Depending on the specific hardware, this is the first general purpose button on the controller. For example, on an Oculus Quest Touch controller this would represent ‘X’ on the left controller, and ‘A’ on the right controller.
x2: BtnState
The current state of the controller’s X2 button. Depending on the specific hardware, this is the second general purpose button on the controller. For example, on an Oculus Quest Touch controller this would represent ‘Y’ on the left controller, and ‘B’ on the right controller.
trigger: f32
The trigger button at the user’s index finger. These buttons typically have a wide range of activation, so this is provided as a value from 0.0 -> 1.0, where 0 is no interaction, and 1 is full interaction. If a controller has binary activation, this will jump straight from 0 to 1.
grip: f32
The grip button typically sits under the user’s middle finger. These buttons occasionally have a wide range of activation, so this is provided as a value from 0.0 -> 1.0, where 0 is no interaction, and 1 is full interaction. If a controller has binary activation, this will jump straight from 0 to 1.
stick: Vec2
This is the current 2-axis position of the analog stick or equivalent directional controller. This generally ranges from -1 to +1 on each axis. This is a raw input, so dead-zones and similar issues are not accounted for here, unless modified by the OpenXR platform itself.
Implementations§
Source§impl Controller
impl Controller
Sourcepub fn is_x1_pressed(&self) -> bool
pub fn is_x1_pressed(&self) -> bool
Is the controller’s X1 button currently pressed? Depending on the specific hardware, this is the first general purpose button on the controller. For example, on an Oculus Quest Touch controller this would represent ‘X’ on the left controller, and ‘A’ on the right controller. https://stereokit.net/Pages/StereoKit/Controller/IsX1Pressed.html
Sourcepub fn is_x1_just_pressed(&self) -> bool
pub fn is_x1_just_pressed(&self) -> bool
Has the controller’s X1 button just been pressed this frame? Depending on the specific hardware, this is the first general purpose button on the controller. For example, on an Oculus Quest Touch controller this would represent ‘X’ on the left controller, and ‘A’ on the right controller. https://stereokit.net/Pages/StereoKit/Controller/IsX1JustPressed.html
Sourcepub fn is_x1_just_unpressed(&self) -> bool
pub fn is_x1_just_unpressed(&self) -> bool
Has the controller’s X1 button just been released this frame? Depending on the specific hardware, this is the first general purpose button on the controller. For example, on an Oculus Quest Touch controller this would represent ‘X’ on the left controller, and ‘A’ on the right controller. https://stereokit.net/Pages/StereoKit/Controller/IsX1JustUnPressed.html
Sourcepub fn is_x2_pressed(&self) -> bool
pub fn is_x2_pressed(&self) -> bool
Is the controller’s X2 button currently pressed? Depending on the specific hardware, this is the second general purpose button on the controller. For example, on an Oculus Quest Touch controller this would represent ‘Y’ on the left controller, and ‘B’ on the right controller. https://stereokit.net/Pages/StereoKit/Controller/IsX2Pressed.html
Sourcepub fn is_x2_just_pressed(&self) -> bool
pub fn is_x2_just_pressed(&self) -> bool
Has the controller’s X2 button just been pressed this frame? Depending on the specific hardware, this is the second general purpose button on the controller. For example, on an Oculus Quest Touch controller this would represent ‘Y’ on the left controller, and ‘B’ on the right controller. https://stereokit.net/Pages/StereoKit/Controller/IsX2JustPressed.html
Sourcepub fn is_x2_just_unpressed(&self) -> bool
pub fn is_x2_just_unpressed(&self) -> bool
Has the controller’s X2 button just been released this frame? Depending on the specific hardware, this is the second general purpose button on the controller. For example, on an Oculus Quest Touch controller this would represent ‘Y’ on the left controller, and ‘B’ on the right controller. https://stereokit.net/Pages/StereoKit/Controller/IsX2JustUnPressed.html
Sourcepub fn is_stick_clicked(&self) -> bool
pub fn is_stick_clicked(&self) -> bool
Is the analog stick/directional controller button currently being actively pressed? https://stereokit.net/Pages/StereoKit/Controller/IsStickClicked.html
Sourcepub fn is_stick_just_clicked(&self) -> bool
pub fn is_stick_just_clicked(&self) -> bool
Is the analog stick/directional controller button currently being actively pressed? https://stereokit.net/Pages/StereoKit/Controller/IsStickJustClicked.html
Sourcepub fn is_stick_just_unclicked(&self) -> bool
pub fn is_stick_just_unclicked(&self) -> bool
Has the analog stick/directional controller button just been released this frame? https://stereokit.net/Pages/StereoKit/Controller/IsStickJustUnclicked.html
Sourcepub fn is_tracked(&self) -> bool
pub fn is_tracked(&self) -> bool
Is the controller being tracked by the sensors right now? https://stereokit.net/Pages/StereoKit/Controller/IsTracked.html
Sourcepub fn is_just_tracked(&self) -> bool
pub fn is_just_tracked(&self) -> bool
Has the controller just started being tracked this frame? https://stereokit.net/Pages/StereoKit/Controller/IsJustTracked.html
Sourcepub fn is_just_untracked(&self) -> bool
pub fn is_just_untracked(&self) -> bool
Has the analog stick/directional controller button just been released this frame? https://stereokit.net/Pages/StereoKit/Controller/IsJustUntracked.html
Trait Implementations§
Source§impl Clone for Controller
impl Clone for Controller
Source§fn clone(&self) -> Controller
fn clone(&self) -> Controller
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Controller
impl Debug for Controller
impl Copy for Controller
Auto Trait Implementations§
impl Freeze for Controller
impl RefUnwindSafe for Controller
impl Send for Controller
impl Sync for Controller
impl Unpin for Controller
impl UnwindSafe for Controller
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.