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.
impl DeviceMotionSample
Physical coordinate, orientation, and sanitization helpers for DeviceMotionSample.
Sourcepub fn upright() -> Self
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).
Sourcepub fn from_vectors(
gravity: [f32; 3],
linear_accel: [f32; 3],
gyro: [f32; 3],
attitude: [f32; 3],
timestamp_ns: u64,
sensor_active: bool,
) -> Self
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]inm/s².[f32; 3]- Screen-aligned linear shake acceleration[lx, ly, lz]inm/s².[f32; 3]- Screen-aligned angular velocity[wx, wy, wz]inrad/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.
Sourcepub fn from_gravity(gx: f32, gy: f32, gz: f32) -> Self
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 inm/s².f32- Screen-down gravity component inm/s².f32- Out-of-screen gravity component inm/s².
§Returns
Self- Sanitized sample with derived orientation angles.
Sourcepub fn from_device_axes(
gravity_dev: [f32; 3],
linear_dev: [f32; 3],
gyro_dev: [f32; 3],
screen_angle_deg: i32,
timestamp_ns: u64,
) -> Self
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-alignedDeviceMotionSamplemarkedsensor_active = true.
Sourcepub fn gravity_magnitude(&self) -> f32
pub fn gravity_magnitude(&self) -> f32
Source§impl DeviceMotionSample
impl DeviceMotionSample
pub fn get_gravity_x(&self) -> f32
pub fn get_mut_gravity_x(&mut self) -> &mut f32
pub fn set_gravity_x(&mut self, val: f32) -> &mut Self
pub fn get_gravity_y(&self) -> f32
pub fn get_mut_gravity_y(&mut self) -> &mut f32
pub fn set_gravity_y(&mut self, val: f32) -> &mut Self
pub fn get_gravity_z(&self) -> f32
pub fn get_mut_gravity_z(&mut self) -> &mut f32
pub fn set_gravity_z(&mut self, val: f32) -> &mut Self
pub fn get_linear_accel_x(&self) -> f32
pub fn get_mut_linear_accel_x(&mut self) -> &mut f32
pub fn set_linear_accel_x(&mut self, val: f32) -> &mut Self
pub fn get_linear_accel_y(&self) -> f32
pub fn get_mut_linear_accel_y(&mut self) -> &mut f32
pub fn set_linear_accel_y(&mut self, val: f32) -> &mut Self
pub fn get_linear_accel_z(&self) -> f32
pub fn get_mut_linear_accel_z(&mut self) -> &mut f32
pub fn set_linear_accel_z(&mut self, val: f32) -> &mut Self
pub fn get_gyro_x(&self) -> f32
pub fn get_mut_gyro_x(&mut self) -> &mut f32
pub fn set_gyro_x(&mut self, val: f32) -> &mut Self
pub fn get_gyro_y(&self) -> f32
pub fn get_mut_gyro_y(&mut self) -> &mut f32
pub fn set_gyro_y(&mut self, val: f32) -> &mut Self
pub fn get_gyro_z(&self) -> f32
pub fn get_mut_gyro_z(&mut self) -> &mut f32
pub fn set_gyro_z(&mut self, val: f32) -> &mut Self
pub fn get_pitch_rad(&self) -> f32
pub fn get_mut_pitch_rad(&mut self) -> &mut f32
pub fn set_pitch_rad(&mut self, val: f32) -> &mut Self
pub fn get_roll_rad(&self) -> f32
pub fn get_mut_roll_rad(&mut self) -> &mut f32
pub fn set_roll_rad(&mut self, val: f32) -> &mut Self
pub fn get_yaw_rad(&self) -> f32
pub fn get_mut_yaw_rad(&mut self) -> &mut f32
pub fn set_yaw_rad(&mut self, val: f32) -> &mut Self
pub fn get_timestamp_ns(&self) -> u64
pub fn get_mut_timestamp_ns(&mut self) -> &mut u64
pub fn set_timestamp_ns(&mut self, val: u64) -> &mut Self
pub fn get_sensor_active(&self) -> bool
pub fn get_mut_sensor_active(&mut self) -> &mut bool
pub fn set_sensor_active(&mut self, val: bool) -> &mut Self
Trait Implementations§
Source§impl Clone for DeviceMotionSample
impl Clone for DeviceMotionSample
impl Copy for DeviceMotionSample
Source§impl Debug for DeviceMotionSample
impl Debug for DeviceMotionSample
Source§impl Default for DeviceMotionSample
Default upright portrait gravity sample for DeviceMotionSample.
impl Default for DeviceMotionSample
Default upright portrait gravity sample for DeviceMotionSample.