Struct Controller

Source
#[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);
);
screenshot
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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn is_tracked(&self) -> bool

Is the controller being tracked by the sensors right now? https://stereokit.net/Pages/StereoKit/Controller/IsTracked.html

Source

pub fn is_just_tracked(&self) -> bool

Has the controller just started being tracked this frame? https://stereokit.net/Pages/StereoKit/Controller/IsJustTracked.html

Source

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

Source§

fn clone(&self) -> Controller

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Controller

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Controller

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more