Skip to main content

DeviceMotionSample

Struct DeviceMotionSample 

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

Screen-aligned 6-DOF gravity, linear acceleration, and gyroscope sample delivered by real device motion sensors.

Linear vectors use the screen frame +x right, +y down, +z out of the screen in SI m/s². Angular rates use the native sensor right-hand convention (gyro_x about screen-right, gyro_y about screen-up, gyro_z about the out-of-screen axis, positive counter-clockwise as seen by the user) in rad/s.

Implementations§

Source§

impl DeviceMotionSample

Physical coordinate, orientation, and sanitization helpers for DeviceMotionSample.

Source

pub fn upright() -> Self

Returns an upright stationary DeviceMotionSample with standard Earth gravity along +y.

§Returns
  • Self - Upright gravity sample (0.0, 9.80665, 0.0).
Source

pub fn from_vectors( gravity: [f32; 3], linear_accel: [f32; 3], gyro: [f32; 3], attitude: [f32; 3], timestamp_ns: u64, sensor_active: bool, ) -> Self

Constructs a sanitized screen-aligned DeviceMotionSample from grouped 3-axis gravity, linear acceleration, gyroscope, and attitude vectors.

§Arguments
  • [f32; 3] - Screen-aligned gravity [gx, gy, gz] in m/s².
  • [f32; 3] - Screen-aligned linear shake acceleration [lx, ly, lz] in m/s².
  • [f32; 3] - Screen-aligned angular velocity [wx, wy, wz] in rad/s.
  • [f32; 3] - Device attitude [pitch_rad, roll_rad, yaw_rad] in radians.
  • u64 - Monotonic sensor timestamp in nanoseconds.
  • bool - Whether the sample comes from a live hardware sensor.
§Returns
  • Self - Sanitized 6-DOF device motion sample.
Source

pub fn from_gravity(gx: f32, gy: f32, gz: f32) -> Self

Constructs a DeviceMotionSample from a screen-aligned gravity vector and derives roll_rad and pitch_rad.

§Arguments
  • f32 - Screen-right gravity component in m/s².
  • f32 - Screen-down gravity component in m/s².
  • f32 - Out-of-screen gravity component in m/s².
§Returns
  • Self - Sanitized sample with derived orientation angles.
Source

pub fn from_device_axes( gravity_dev: [f32; 3], linear_dev: [f32; 3], gyro_dev: [f32; 3], screen_angle_deg: i32, timestamp_ns: u64, ) -> Self

Transforms natural-portrait device vectors (+X right, +Y up, +Z out-of-screen) by clockwise/CCW display rotation degrees (0, 90, 180, 270) into screen-aligned DeviceMotionSample coordinates (+x right, +y down, +z out-of-screen).

gravity_dev must point downward in device coordinates (e.g. (0, -9.80665, 0) when upright portrait).

§Arguments
  • [f32; 3] - Gravity vector in natural device (+X_right, +Y_up, +Z_out) m/s².
  • [f32; 3] - Linear acceleration in natural device (+X_right, +Y_up, +Z_out) m/s².
  • [f32; 3] - Angular velocity in natural device (+X_right, +Y_up, +Z_out) rad/s.
  • i32 - Display rotation angle in degrees (0, 90, 180, 270, or -90).
  • u64 - Monotonic timestamp in nanoseconds.
§Returns
  • Self - Sanitized screen-aligned DeviceMotionSample marked sensor_active = true.
Source

pub fn sanitized(&self) -> Self

Returns a sanitized copy with non-finite values replaced and extreme sensor spikes clamped safely.

§Arguments
  • &Self - Raw device motion sample.
§Returns
  • Self - Sanitized finite sample.
Source

pub fn gravity_magnitude(&self) -> f32

Returns the in-screen gravity magnitude in m/s².

§Arguments
  • &Self - Device motion sample reference.
§Returns
  • f32 - Magnitude sqrt(gx² + gy² + gz²).
Source§

impl DeviceMotionSample

Source

pub fn get_gravity_x(&self) -> f32

Source

pub fn get_mut_gravity_x(&mut self) -> &mut f32

Source

pub fn set_gravity_x(&mut self, val: f32) -> &mut Self

Source

pub fn get_gravity_y(&self) -> f32

Source

pub fn get_mut_gravity_y(&mut self) -> &mut f32

Source

pub fn set_gravity_y(&mut self, val: f32) -> &mut Self

Source

pub fn get_gravity_z(&self) -> f32

Source

pub fn get_mut_gravity_z(&mut self) -> &mut f32

Source

pub fn set_gravity_z(&mut self, val: f32) -> &mut Self

Source

pub fn get_linear_accel_x(&self) -> f32

Source

pub fn get_mut_linear_accel_x(&mut self) -> &mut f32

Source

pub fn set_linear_accel_x(&mut self, val: f32) -> &mut Self

Source

pub fn get_linear_accel_y(&self) -> f32

Source

pub fn get_mut_linear_accel_y(&mut self) -> &mut f32

Source

pub fn set_linear_accel_y(&mut self, val: f32) -> &mut Self

Source

pub fn get_linear_accel_z(&self) -> f32

Source

pub fn get_mut_linear_accel_z(&mut self) -> &mut f32

Source

pub fn set_linear_accel_z(&mut self, val: f32) -> &mut Self

Source

pub fn get_gyro_x(&self) -> f32

Source

pub fn get_mut_gyro_x(&mut self) -> &mut f32

Source

pub fn set_gyro_x(&mut self, val: f32) -> &mut Self

Source

pub fn get_gyro_y(&self) -> f32

Source

pub fn get_mut_gyro_y(&mut self) -> &mut f32

Source

pub fn set_gyro_y(&mut self, val: f32) -> &mut Self

Source

pub fn get_gyro_z(&self) -> f32

Source

pub fn get_mut_gyro_z(&mut self) -> &mut f32

Source

pub fn set_gyro_z(&mut self, val: f32) -> &mut Self

Source

pub fn get_pitch_rad(&self) -> f32

Source

pub fn get_mut_pitch_rad(&mut self) -> &mut f32

Source

pub fn set_pitch_rad(&mut self, val: f32) -> &mut Self

Source

pub fn get_roll_rad(&self) -> f32

Source

pub fn get_mut_roll_rad(&mut self) -> &mut f32

Source

pub fn set_roll_rad(&mut self, val: f32) -> &mut Self

Source

pub fn get_yaw_rad(&self) -> f32

Source

pub fn get_mut_yaw_rad(&mut self) -> &mut f32

Source

pub fn set_yaw_rad(&mut self, val: f32) -> &mut Self

Source

pub fn get_timestamp_ns(&self) -> u64

Source

pub fn get_mut_timestamp_ns(&mut self) -> &mut u64

Source

pub fn set_timestamp_ns(&mut self, val: u64) -> &mut Self

Source

pub fn get_sensor_active(&self) -> bool

Source

pub fn get_mut_sensor_active(&mut self) -> &mut bool

Source

pub fn set_sensor_active(&mut self, val: bool) -> &mut Self

Trait Implementations§

Source§

impl Clone for DeviceMotionSample

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for DeviceMotionSample

Source§

impl Debug for DeviceMotionSample

Source§

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

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

impl Default for DeviceMotionSample

Default upright portrait gravity sample for DeviceMotionSample.

Source§

fn default() -> Self

Creates an upright stationary DeviceMotionSample with (0.0, 9.80665, 0.0) screen gravity.

§Returns
  • Self - Default upright device motion sample with sensor_active == false.
Source§

impl PartialEq for DeviceMotionSample

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DeviceMotionSample

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.