Interactor

Struct Interactor 

Source
pub struct Interactor { /* private fields */ }
Expand description

Interactors are essentially capsules that allow interaction with StereoKit’s interaction primitives used by the UI system. While StereoKit does provide a number of interactors by default, you can replace StereoKit’s defaults, add additional interactors, or generally just customize your interactions! https://stereokit.net/Pages/StereoKit/Interactor.html

see also InteractorType InteractorEvent InteractorActivation DefaultInteractors

§Examples

use stereokit_rust::{system::{Interactor, InteractorType, InteractorEvent, InteractorActivation, BtnState},
                     maths::{Vec3, Pose}};

let interactor = Interactor::create(
    InteractorType::Point,
    InteractorEvent::Poke,
    InteractorActivation::State,
    0,
    0.01,
    0
);

interactor.update(
    Vec3::new(0.0, 0.0, 0.0),
    Vec3::new(0.0, 0.0, 0.1),
    Pose::IDENTITY,
    Vec3::ZERO,
    Vec3::ZERO,
    BtnState::Active,
    BtnState::Active
);

let radius = interactor.get_radius();
let start = interactor.get_start();
let end = interactor.get_end();
let tracked = interactor.get_tracked();
let focused = interactor.get_focused();
let active = interactor.get_active();
let motion = interactor.get_motion();

interactor.destroy();

Implementations§

Source§

impl Interactor

Source

pub fn create( shape_type: InteractorType, events: InteractorEvent, activation_type: InteractorActivation, input_source_id: i32, capsule_radius: f32, secondary_motion_dimensions: i32, ) -> Self

Create a new custom Interactor. https://stereokit.net/Pages/StereoKit/Interactor/Create.html

  • shape_type - A line, or a point? These interactors behave slightly differently with respect to distance checks and directionality. See InteractorType for more details.
  • events - What type of interaction events should this interactor fire? Interaction elements use this bitflag as a filter to avoid interacting with certain interactors.
  • activation_type - How does this interactor activate elements?
  • input_source_id - An identifier that uniquely indicates a shared source for inputs. This will deactivate other interactors with a shared source if one is already active. For example, 3 interactors for poke, pinch, and aim on a hand would all come from a single hand, and if one is actively interacting, then the whole hand source is considered busy.
  • capsule_radius - The radius of the interactor’s capsule, in meters.
  • secondary_motion_dimensions - How many axes of secondary motion can this interactor provide? This should be 0-3.

Returns the Interactor that was just created. see also interactor_create

Source

pub fn update( &self, capsule_start: impl Into<Vec3>, capsule_end: impl Into<Vec3>, motion: impl Into<Pose>, motion_anchor: impl Into<Vec3>, secondary_motion: impl Into<Vec3>, active: BtnState, tracked: BtnState, )

Update the interactor with data for the current frame! This should be called as soon as possible at the start of the frame before any UI is done, otherwise the UI will not properly react. https://stereokit.net/Pages/StereoKit/Interactor/Update.html

  • capsule_start - World space location of the collision capsule’s start. For Line interactors, this should be the ‘origin’ of the capsule’s orientation.
  • capsule_end - World space location of the collision capsule’s end. For Line interactors, this should be in the direction the Start/origin is facing.
  • motion - This pose is the source of translation and rotation motion caused by the interactor. In most cases it will be the same as your capsuleStart with the orientation of your interactor, but in some instance may be something else!
  • motion_anchor - Some motion, like that of amplified motion, needs some anchor point with which to determine the amplification from. This might be a shoulder, or a head, or some other point that the interactor will push from / pull towards.
  • secondary_motion - This is motion that comes from somewhere other than the interactor itself! This can be something like an analog stick on a controller, or the scroll wheel of a mouse.
  • active - The activation state of the Interactor.
  • tracked - The tracking state of the Interactor.

see also interactor_update

Source

pub fn destroy(&self)

Destroy this interactor and free its resources. https://stereokit.net/Pages/StereoKit/Interactor/Destroy.html

see also interactor_destroy

Source

pub fn get_min_distance(&self) -> f32

The distance at which a ray starts being interactive. For pointing rays, you may not want them to interact right at their start, or you may want the start to move depending on how outstretched the hand is! This allows you to change that start location without affecting the movement caused by the ray, and still capturing occlusion from blocking elements too close to the start. By default, this is a large negative value. https://stereokit.net/Pages/StereoKit/Interactor/MinDistance.html

see also interactor_get_min_distance Interactor::min_distance

Source

pub fn min_distance(&self, min_distance: f32)

Source

pub fn get_radius(&self) -> f32

The world space radius of the interactor capsule, in meters. https://stereokit.net/Pages/StereoKit/Interactor/Radius.html

see also interactor_get_radius Interactor::radius

Source

pub fn radius(&self, radius: f32)

Set the world space radius of the interactor capsule, in meters. https://stereokit.net/Pages/StereoKit/Interactor/Radius.html

see also interactor_set_radius Interactor::get_radius

Source

pub fn get_start(&self) -> Vec3

The world space start of the interactor capsule. Some interactions can be directional, especially for Line type interactors, so if you think of the interactor as an “oriented” capsule, this would be the origin which points towards the capsule End. https://stereokit.net/Pages/StereoKit/Interactor/Start.html

see also interactor_get_capsule_start Interactor::get_end

Source

pub fn get_end(&self) -> Vec3

The world space end of the interactor capsule. Some interactions can be directional, especially for Line type interactors, so if you think of the interactor as an “oriented” capsule, this would be the end which the Start/origin points towards. https://stereokit.net/Pages/StereoKit/Interactor/End.html

see also interactor_get_capsule_end Interactor::get_start

Source

pub fn get_tracked(&self) -> BtnState

Source

pub fn get_focused(&self) -> IdHashT

The id of the interaction element that is currently focused, this will be IdHashT::NONE if this interactor has nothing focused. https://stereokit.net/Pages/StereoKit/Interactor/Focused.html

see also interactor_get_focused Interactor::get_active

Source

pub fn get_active(&self) -> IdHashT

The id of the interaction element that is currently active, this will be IdHashT::NONE if this interactor has nothing active. This will always be the same id as Focused when not None. https://stereokit.net/Pages/StereoKit/Interactor/Active.html

see also interactor_get_active Interactor::get_focused

Source

pub fn get_motion(&self) -> Pose

This pose is the source of translation and rotation motion caused by the interactor. In most cases it will be the same as your Start with the orientation of your interactor, but in some instance may be something else! https://stereokit.net/Pages/StereoKit/Interactor/Motion.html

see also interactor_get_motion Interactor::update

Source

pub fn try_get_focus_bounds(&self) -> Option<(Pose, Bounds, Vec3)>

If this interactor has an element focused, this will output information about the location of that element, as well as the interactor’s intersection point with that element. https://stereokit.net/Pages/StereoKit/Interactor/TryGetFocusBounds.html

  • pose_world - The world space Pose of the element’s hierarchy space. This is typically the Pose of the Window/Handle/Surface the element belongs to.
  • bounds_local - The bounds of the UI element relative to the Pose. Note that the center should always be accounted for here!
  • at_local - The intersection point relative to the Bounds, NOT relative to the Pose!

Returns Some((pose_world, bounds_local, at_local)) if bounds data is available, None otherwise.

see also interactor_get_focus_bounds Interactor::get_focused

Source

pub fn count() -> i32

The number of interactors currently in the system. Can be used with get. https://stereokit.net/Pages/StereoKit/Interactor/Count.html

see also interactor_count Interactor::get

Source

pub fn get(index: i32) -> Self

Returns the Interactor at the given index. Should be used with count. https://stereokit.net/Pages/StereoKit/Interactor/Get.html

  • index - The index.

Returns an Interactor. see also interactor_get Interactor::count

Trait Implementations§

Source§

impl Clone for Interactor

Source§

fn clone(&self) -> Interactor

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 Interactor

Source§

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

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

impl PartialEq for Interactor

Source§

fn eq(&self, other: &Interactor) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Interactor

Source§

impl Eq for Interactor

Source§

impl StructuralPartialEq for Interactor

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 + Sync + Send>

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