Struct Pose

Source
#[repr(C)]
pub struct Pose { pub position: Vec3, pub orientation: Quat, }
Expand description

Pose represents a location and orientation in space, excluding scale! The default value of a Pose use Pose.Identity . https://stereokit.net/Pages/StereoKit/Pose.html

§Examples

use stereokit_rust::{ui::Ui, maths::{Vec3, Pose, Matrix}, model::Model };

let plane = Model::from_file("plane.glb", None).unwrap_or_default();
let bounds = plane.get_bounds();
let mut handle_pose = Pose::look_at(
    [0.0, -5.5, -10.0], (Vec3::Z + Vec3::X) * 100.0);

let mut window_pose = Pose::new(
    [0.0, 0.05, 0.90], Some([0.0, 200.0, 0.0].into()));

filename_scr = "screenshots/pose.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
    Ui::handle_begin( "Model Handle", &mut handle_pose,
                      bounds, false, None, None);
    plane.draw(token, Matrix::IDENTITY, None, None);
    Ui::handle_end();

    Ui::window_begin("My Window", &mut window_pose, None, None, None);
    Ui::text("My Text", None, None, None, Some(0.14), None, None);
    Ui::window_end();
);
screenshot

Fields§

§position: Vec3§orientation: Quat

Implementations§

Source§

impl Pose

Source

pub const IDENTITY: Pose

The default Pose: Origin with Quat::IDENTITY orientation. https://stereokit.net/Pages/StereoKit/Pose/Identity.html

Source

pub const ZERO: Pose

Zero may be encountered when testing some crate::system::Input crate::system::Pointer and crate::system::Controller

Source

pub fn new(position: impl Into<Vec3>, orientation: Option<Quat>) -> Self

Basic initialization constructor! Just copies in the provided values directly, and uses Identity for the orientation. https://stereokit.net/Pages/StereoKit/Pose/Pose.html

§Examples
use stereokit_rust::maths::{Vec3, Pose};
let mut handle_pose = Pose::new( [0.0, 0.05, 0.90], None);

let mut window_pose = Pose::new(
    [0.0, 0.05, 0.90], Some([0.0, 180.0 * 4.0, 0.0].into()));

assert_eq!(handle_pose, window_pose);
Source

pub fn lerp(a: impl Into<Pose>, b: impl Into<Pose>, percent: f32) -> Self

Interpolates between two poses! It is unclamped, so values outside of (0,1) will extrapolate their position. https://stereokit.net/Pages/StereoKit/Pose/Lerp.html

§Examples
use stereokit_rust::maths::{Vec3, Pose};

let mut pose1 = Pose::new( Vec3::Y, None);
let mut pose2 = Pose::new( Vec3::Y, Some([0.0, 45.0, 0.0].into()));
let mut pose3 = Pose::new( Vec3::Y, Some([0.0, 90.0, 0.0].into()));

assert_eq!(Pose::lerp(pose1, pose3, 0.5), pose2);
Source

pub fn look_at(from: impl Into<Vec3>, at: impl Into<Vec3>) -> Self

Creates a Pose that looks from one location in the direction of another location. This leaves “Up” as the +Y axis. https://stereokit.net/Pages/StereoKit/Pose/LookAt.html

§Examples
use stereokit_rust::maths::{Vec3, Pose};

let mut pose1 = Pose::look_at(Vec3::ZERO, Vec3::NEG_Z );
assert_eq!(pose1, Pose::default());
Source

pub fn to_matrix(&self, scale: Option<Vec3>) -> Matrix

Converts this pose into a transform matrix. https://stereokit.net/Pages/StereoKit/Pose/ToMatrix.html

  • scale - Let you add a scale factor if needed.
§Examples
use stereokit_rust::maths::{Vec3, Matrix, Pose};

let pose1 = Pose::IDENTITY;

assert_eq!(pose1.to_matrix(None), Matrix::IDENTITY);    
Source

pub fn to_matrix_inv(&self, scale: Option<Vec3>) -> Matrix

Converts this pose into the inverse of the Pose’s transform matrix. This can be used to transform points from the space represented by the Pose into world space. https://stereokit.net/Pages/StereoKit/Pose/ToMatrixInv.html

  • scale - A scale vector! Vec3.One would be an identity scale.
§Examples
use stereokit_rust::maths::{Vec3, Matrix, Pose};

let pose1 = Pose::IDENTITY;

assert_eq!(pose1.to_matrix_inv(None), Matrix::IDENTITY);    

assert_eq!(pose1.to_matrix_inv(Some(Vec3::new(0.5, 0.25, 0.125))),
            [2.0, 0.0, 0.0, 0.0,
             0.0, 4.0, 0.0, 0.0,
             0.0, 0.0, 8.0, 0.0,
             0.0, 0.0, 0.0, 1.0].into());
Source

pub fn get_forward(&self) -> Vec3

Calculates the forward direction from this pose. This is done by multiplying the orientation with Vec3::new(0, 0, -1). Remember that Forward points down the -Z axis! https://stereokit.net/Pages/StereoKit/Pose/Forward.html

§Examples
use stereokit_rust::maths::{Vec3,  Pose};

let pose1 = Pose::default();
assert_eq!(pose1.get_forward(), Vec3::NEG_Z);    

let pose2 = Pose::look_at(Vec3::new(1.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0));
assert_eq!(pose2.get_forward(), Vec3::NEG_X);    
Source

pub fn get_ray(&self) -> Ray

This creates a ray starting at the Pose’s position, and pointing in the ‘Forward’ direction. The Ray direction is a unit vector/normalized. https://stereokit.net/Pages/StereoKit/Pose/Ray.html

see also Ray

§Examples
use stereokit_rust::maths::{Vec3, Pose, Ray};

let pose1 = Pose::default();
let ray_forward = Ray::new( Vec3::ZERO, Vec3::NEG_Z);
assert_eq!(pose1.get_ray(), ray_forward);    

let pose2 = Pose::look_at(Vec3::new(1.0, 0.0, 0.0), Vec3::new(1.0, 2.0, 0.0));
let ray_to_the_left = Ray::new(Vec3::X, Vec3::Y);
assert_eq!(pose2.get_ray(), ray_to_the_left);   
Source

pub fn get_right(&self) -> Vec3

Calculates the right (+X) direction from this pose. This is done by multiplying the orientation with Vec3.Right. https://stereokit.net/Pages/StereoKit/Pose/Right.html

§Examples
use stereokit_rust::maths::{Vec3, Pose, Ray};

let pose1 = Pose::default();
assert_eq!(pose1.get_right(), Vec3::X);    

let pose2 = Pose::look_at(Vec3::new(1.0, 0.0, 0.0), Vec3::new(1.0, 2.0, 3.0));
assert_eq!(pose2.get_right(), Vec3::NEG_X);  
Source

pub fn get_up(&self) -> Vec3

Calculates the up (+Y) direction from this pose. This is done by multiplying the orientation with Vec3.Up. https://stereokit.net/Pages/StereoKit/Pose/Up.html

§Examples
use stereokit_rust::maths::{Vec3, Pose, Ray};

let pose1 = Pose::default();
assert_eq!(pose1.get_up(), Vec3::Y);    

let pose2 = Pose::look_at(Vec3::new(1.0, 0.0, 0.0), Vec3::new(2.0, 0.0, 3.0));
assert_eq!(pose2.get_up(), Vec3::Y);  

Trait Implementations§

Source§

impl Clone for Pose

Source§

fn clone(&self) -> Pose

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 Pose

Source§

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

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

impl Default for Pose

Source§

fn default() -> Self

Position is Vec3::ZERO, and orientation is Quat::IDENTITY (no rotation) https://stereokit.net/Pages/StereoKit/Pose/Identity.html

Source§

impl Display for Pose

Source§

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

A string representation of the Pose, in the format of “position, Forward”. Mostly for debug visualization. https://stereokit.net/Pages/StereoKit/Pose/ToString.html

§Examples
use stereokit_rust::maths::{Vec3, Pose};

let pose = Pose::new([1.1, 2.0, 3.0], Some([0.0, 90.0, 0.0].into()));
assert_eq!(format!("{}", pose),
           "[position:[x:1.1, y:2, z:3] forward:[x:0, y:0.70710677, z:0, w:0.7071067]]");
Source§

impl From<Matrix> for Pose

Source§

fn from(matrix: Matrix) -> Self

Converts to this type from the input type.
Source§

impl From<Pose> for Matrix

Source§

fn from(pose: Pose) -> Self

Converts to this type from the input type.
Source§

impl Mul<Matrix> for Pose

Transforms a Pose by the Matrix! The position and orientation are both transformed by the matrix, accounting properly for the Pose’s quaternion. https://stereokit.net/Pages/StereoKit/Matrix/op_Multiply.html

Source§

fn mul(self, rhs: Matrix) -> Self::Output

§Examples
use stereokit_rust::maths::{Pose, Vec3, Matrix};

let transform = Matrix::t([1.0, 2.0, 3.0]);
let pose = Pose::new([0.0, 0.0, 0.0], None);

let transformed_pose = pose * transform;
assert_eq!(transformed_pose, Pose::new([1.0, 2.0, 3.0], None));
Source§

type Output = Pose

The resulting type after applying the * operator.
Source§

impl Mul<Pose> for Matrix

Transforms a Pose by the Matrix! The position and orientation are both transformed by the matrix, accounting properly for the Pose’s quaternion. https://stereokit.net/Pages/StereoKit/Matrix/op_Multiply.html

Source§

fn mul(self, rhs: Pose) -> Self::Output

§Examples
use stereokit_rust::maths::{Pose, Vec3, Matrix};

let transform = Matrix::t([1.0, 2.0, 3.0]);
let pose = Pose::new([0.0, 0.0, 0.0], None);

let transformed_pose = transform * pose;
assert_eq!(transformed_pose, Pose::new([1.0, 2.0, 3.0], None));
Source§

type Output = Pose

The resulting type after applying the * operator.
Source§

impl MulAssign<Matrix> for Pose

Transforms a Pose by the Matrix! The position and orientation are both transformed by the matrix, accounting properly for the Pose’s quaternion. https://stereokit.net/Pages/StereoKit/Matrix/op_Multiply.html

Source§

fn mul_assign(&mut self, rhs: Matrix)

§Examples
use stereokit_rust::maths::{Pose, Vec3, Matrix};

let mut pose = Pose::new([0.0, 0.0, 0.0], None);
let transform = Matrix::t([1.0, 2.0, 3.0]);

pose *= transform;
assert_eq!(pose, Pose::new([1.0, 2.0, 3.0], None));
Source§

impl PartialEq for Pose

Source§

fn eq(&self, other: &Pose) -> 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 Pose

Source§

impl StructuralPartialEq for Pose

Auto Trait Implementations§

§

impl Freeze for Pose

§

impl RefUnwindSafe for Pose

§

impl Send for Pose

§

impl Sync for Pose

§

impl Unpin for Pose

§

impl UnwindSafe for Pose

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> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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