void ISensorEventListener.OnSensorChanged(SensorEvent e) { var count = e?.Values?.Count ?? 0; if (count < 3) { return; } OrientationSensorData?data; // Docs: https://developer.android.com/reference/android/hardware/SensorEvent#sensor.type_rotation_vector-: // values[3], originally optional, will always be present from SDK Level 18 onwards. values[4] is a new value that has been added in SDK Level 18. if (count < 4) { data = new OrientationSensorData(e.Values[0], e.Values[1], e.Values[2], -1); } else { data = new OrientationSensorData(e.Values[0], e.Values[1], e.Values[2], e.Values[3]); } OrientationSensor.OnChanged(data.Value); }
void ISensorEventListener.OnSensorChanged(SensorEvent?e) { var values = e?.Values ?? Array.Empty <float>(); if (values.Count < 3) { return; } OrientationSensorData?data; // Docs: https://developer.android.com/reference/android/hardware/SensorEvent#sensor.type_rotation_vector: // values[3], originally optional, will always be present from SDK Level 18 onwards. values[4] is a new value that has been added in SDK Level 18. if (values.Count < 4) { data = new OrientationSensorData(values[0], values[1], values[2], -1); } else { data = new OrientationSensorData(values[0], values[1], values[2], values[3]); } Callback?.Invoke(data.Value); }
static void DataUpdated(object sender, OrientationSensorReadingChangedEventArgs e) { var reading = e.Reading; var data = new OrientationSensorData(reading.Quaternion.X, reading.Quaternion.Y, reading.Quaternion.Z, reading.Quaternion.W); OnChanged(data); }
public void OrientationSensorData_Comparison( float x1, float y1, float z1, float w1, float x2, float y2, float z2, float w2, bool equals) { var data1 = new OrientationSensorData(x1, y1, z1, w1); var data2 = new OrientationSensorData(x2, y2, z2, w2); if (equals) { Assert.True(data1.Equals(data2)); Assert.True(data1 == data2); Assert.False(data1 != data2); Assert.Equal(data1, data2); Assert.Equal(data1.GetHashCode(), data2.GetHashCode()); } else { Assert.False(data1.Equals(data2)); Assert.False(data1 == data2); Assert.True(data1 != data2); Assert.NotEqual(data1, data2); Assert.NotEqual(data1.GetHashCode(), data2.GetHashCode()); } }
private void OrientationSensor_ReadingChanged(object sender, OrientationSensorChangedEventArgs e) { OrientationSensorData reading = e.Reading; QuaternionData data = Orientation; data.Value = reading.Orientation; data.TimeStamp = DateTime.UtcNow; data.SendNotification(); }
static void DataUpdated(CMDeviceMotion data, NSError error) { if (data == null) { return; } var field = data.Attitude.Quaternion; var rotationData = new OrientationSensorData(field.x, field.y, field.z, field.w); OnChanged(rotationData); }
internal void RaiseReadingChanged(OrientationSensorData reading) { var args = new OrientationSensorChangedEventArgs(reading); if (UseSyncContext) { MainThread.BeginInvokeOnMainThread(() => ReadingChanged?.Invoke(null, args)); } else { ReadingChanged?.Invoke(null, args); } }
static void DataUpdated(CMDeviceMotion data, NSError error) { if (data == null) { return; } var field = data.Attitude.Quaternion; // the quaternion returned by the MotionManager refers to a frame where the X axis points north var q = new Quaternion((float)field.x, (float)field.y, (float)field.z, (float)field.w); // we rotate it by 90 degrees around the Z axis, so that the Y axis points north and the X axis points east var qz90 = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)(Math.PI / 2.0)); q = Quaternion.Multiply(q, qz90); var rotationData = new OrientationSensorData(q.X, q.Y, q.Z, q.W); OnChanged(rotationData); }
static void DataUpdated(CMDeviceMotion data, NSError error) { if (data == null) { return; } var field = data.Attitude.Quaternion; // the quaternion returned by the MotionManager refers to a frame where the X axis points north ("iOS frame") var q = new Quaternion((float)field.x, (float)field.y, (float)field.z, (float)field.w); // in Xamarin, the reference frame is defined such that Y points north and Z is vertical, // so we first rotate by 90 degrees around the Z axis, in order to get from the Xamarin frame to the iOS frame var qz90 = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)(Math.PI / 2.0)); // on top of this rotation, we apply the actual quaternion obtained from the MotionManager, // so that the final quaternion will take us from the earth frame in Xamarin convention to the phone frame q = Quaternion.Multiply(qz90, q); var rotationData = new OrientationSensorData(q.X, q.Y, q.Z, q.W); OnChanged(rotationData); }
void DataUpdated(CMDeviceMotion data, NSError error) { if (data == null) { return; } #pragma warning disable CA1416 // https://github.com/xamarin/xamarin-macios/issues/14619 var field = data.Attitude.Quaternion; #pragma warning restore CA1416 // the quaternion returned by the MotionManager refers to a frame where the X axis points north ("iOS frame") var q = new Quaternion((float)field.x, (float)field.y, (float)field.z, (float)field.w); // In .NET MAUI, the reference frame is defined such that Y points north and Z is vertical, // so we first rotate by 90 degrees around the Z axis, in order to get from the .NET MAUI frame to the iOS frame var qz90 = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)(Math.PI / 2.0)); // on top of this rotation, we apply the actual quaternion obtained from the MotionManager, // so that the final quaternion will take us from the earth frame in .NET MAUI convention to the phone frame q = Quaternion.Multiply(qz90, q); var rotationData = new OrientationSensorData(q.X, q.Y, q.Z, q.W); RaiseReadingChanged(rotationData); }
internal OrientationSensorChangedEventArgs(OrientationSensorData reading) =>
internal static void OnChanged(OrientationSensorData reading) => OnChanged(new OrientationSensorChangedEventArgs(reading));
public OrientationSensorChangedEventArgs(OrientationSensorData reading) =>
void ISensorEventListener.OnSensorChanged(SensorEvent e) { var data = new OrientationSensorData(e.Values[0], e.Values[1], e.Values[2], e.Values[3]); OrientationSensor.OnChanged(data); }