private void ReadOrientationRotation(ref Quaternion quaternion) { #if WINDOWS_STORE_APP _sQuaternion = _sensor.GetCurrentReading().Quaternion; _quaternion.Set(_sQuaternion.X, _sQuaternion.Y, _sQuaternion.Z, _sQuaternion.W); _rotation = _quaternion.eulerAngles; #endif quaternion = _quaternion; }
public async void NewQuan(OrientationSensor sender, OrientationSensorReadingChangedEventArgs args) { var reading = args == null?sender?.GetCurrentReading() : args.Reading; await this.dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { this[QUANTIZATION] = reading == null ? this[QUANTIZATION].New(0, 0, 0, 0) : this[QUANTIZATION].New( reading.Quaternion.X, reading.Quaternion.Y, reading.Quaternion.Z, reading.Quaternion.W); if (this[QUANTIZATION].IsChanged) { this.OnPropertyChanged(new PropertyChangedEventArgs("ItemsList")); this.OnSensorUpdated?.Invoke(this[QUANTIZATION]); } }); if (this.SensorSwitches.Q.HasValue && (this.SensorSwitches.Q.Value == 1 || this.SensorSwitches.Q.Value == 3)) { this.SensorSwitches.Q = 0; } }
/// <summary> /// Invoked when a user clicks on the GetDataButton /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void GetData(object sender, object args) { OrientationSensorReading reading = Sensor.GetCurrentReading(); if (reading != null) { // Quaternion values SensorQuaternion quaternion = reading.Quaternion; // get a reference to the object to avoid re-creating it for each access ScenarioOutput_X.Text = String.Format("{0,8:0.00000}", quaternion.X); ScenarioOutput_Y.Text = String.Format("{0,8:0.00000}", quaternion.Y); ScenarioOutput_Z.Text = String.Format("{0,8:0.00000}", quaternion.Z); ScenarioOutput_W.Text = String.Format("{0,8:0.00000}", quaternion.W); // Rotation Matrix values SensorRotationMatrix rotationMatrix = reading.RotationMatrix; ScenarioOutput_M11.Text = String.Format("{0,8:0.00000}", rotationMatrix.M11); ScenarioOutput_M12.Text = String.Format("{0,8:0.00000}", rotationMatrix.M12); ScenarioOutput_M13.Text = String.Format("{0,8:0.00000}", rotationMatrix.M13); ScenarioOutput_M21.Text = String.Format("{0,8:0.00000}", rotationMatrix.M21); ScenarioOutput_M22.Text = String.Format("{0,8:0.00000}", rotationMatrix.M22); ScenarioOutput_M23.Text = String.Format("{0,8:0.00000}", rotationMatrix.M23); ScenarioOutput_M31.Text = String.Format("{0,8:0.00000}", rotationMatrix.M31); ScenarioOutput_M32.Text = String.Format("{0,8:0.00000}", rotationMatrix.M32); ScenarioOutput_M33.Text = String.Format("{0,8:0.00000}", rotationMatrix.M33); } }
/// <summary> /// Update orientation readings event and update UI /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">The <see cref="object"/> instance containing the event data.</param> private void UpdateOrientation(object sender, EventArgs e) { try { OrientationSensor orientation = OrientationSensor.GetDefault(); if (orientation != null) { SensorQuaternion quaternion = orientation.GetCurrentReading().Quaternion; XLabel.Text = LocRM.GetString("XAxis") + ": " + String.Format("{0,8:0.00000}", quaternion.X); YLabel.Text = LocRM.GetString("YAxis") + ": " + String.Format("{0,8:0.00000}", quaternion.Y); ZLabel.Text = LocRM.GetString("ZAxis") + ": " + String.Format("{0,8:0.00000}", quaternion.Z); WLabel.Text = LocRM.GetString("WAxis") + ": " + String.Format("{0,8:0.00000}", quaternion.W); } else { XLabel.Text = LocRM.GetString("NotFound"); _timer.Stop(); } } catch (Exception ex) { Log.LogError(ex.ToString()); _timer.Stop(); } }
private void OnGetOrientation(object sender, RoutedEventArgs e) { OrientationSensor orientation = OrientationSensor.GetDefault(); OrientationSensorReading reading = orientation.GetCurrentReading(); this.DefaultViewModel["OrientationSensorResult"] = GetOrientationSensorResult(reading); }
private void PreviewControl_Tapped(object sender, TappedRoutedEventArgs e) { Pointer po = new Pointer(); if (pos != null) { i++; po.lat = pos.Coordinate.Latitude; po.lon = pos.Coordinate.Longitude; po.Yaw = c.GetCurrentReading().HeadingMagneticNorth; OrientationSensorReading reading2 = or.GetCurrentReading(); SensorQuaternion q = reading2.Quaternion; // get a reference to the object to avoid re-creating it for each access double y = reading2.Quaternion.Y; if (y < 0) { y = y + 2; } po.Pitch = y; li.Add(po); Tags.Text = i.ToString() + " Point(s) Tagged"; } }
/// <summary> /// This is the dispatcher callback. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void DisplayCurrentReading(object sender, object args) { OrientationSensorReading reading = _sensor.GetCurrentReading(); if (reading != null) { MainPage.SetReadingText(ScenarioOutput, reading); } }
public Vector3 GetOrientation() { if (OrientationSensor != null) { OrientationSensorReading orientation = OrientationSensor.GetCurrentReading(); Matrix m = new Matrix(); m.M11 = orientation.RotationMatrix.M11; m.M12 = orientation.RotationMatrix.M12; m.M13 = orientation.RotationMatrix.M13; m.M21 = orientation.RotationMatrix.M21; m.M22 = orientation.RotationMatrix.M22; m.M23 = orientation.RotationMatrix.M23; m.M31 = orientation.RotationMatrix.M31; m.M32 = orientation.RotationMatrix.M32; m.M33 = orientation.RotationMatrix.M33; return(Vector3.Transform(Vector3.UnitY, m)); } else if (SimpleOrientationSensor != null) { SimpleOrientation orientation = SimpleOrientationSensor.GetCurrentOrientation(); switch (orientation) { case SimpleOrientation.Facedown: case SimpleOrientation.Faceup: return(LastSimpleOrientation); case SimpleOrientation.NotRotated: LastSimpleOrientation = Vector3.UnitY; return(LastSimpleOrientation); case SimpleOrientation.Rotated180DegreesCounterclockwise: LastSimpleOrientation = -Vector3.UnitY; return(LastSimpleOrientation); case SimpleOrientation.Rotated270DegreesCounterclockwise: LastSimpleOrientation = -Vector3.UnitX; return(LastSimpleOrientation); case SimpleOrientation.Rotated90DegreesCounterclockwise: LastSimpleOrientation = Vector3.UnitX; return(LastSimpleOrientation); default: throw new Exception("Unrecognised Orientation"); } } else { throw new Exception("Couldn't determine orientation"); } }
/// <summary> /// This is the dispatcher callback. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void DisplayCurrentReading(object sender, object args) { OrientationSensorReading reading = _sensor.GetCurrentReading(); if (reading != null) { // Quaternion values SensorQuaternion quaternion = reading.Quaternion; // get a reference to the object to avoid re-creating it for each access ScenarioOutput_X.Text = String.Format("{0,8:0.00000}", quaternion.X); ScenarioOutput_Y.Text = String.Format("{0,8:0.00000}", quaternion.Y); ScenarioOutput_Z.Text = String.Format("{0,8:0.00000}", quaternion.Z); ScenarioOutput_W.Text = String.Format("{0,8:0.00000}", quaternion.W); // Rotation Matrix values SensorRotationMatrix rotationMatrix = reading.RotationMatrix; ScenarioOutput_M11.Text = String.Format("{0,8:0.00000}", rotationMatrix.M11); ScenarioOutput_M12.Text = String.Format("{0,8:0.00000}", rotationMatrix.M12); ScenarioOutput_M13.Text = String.Format("{0,8:0.00000}", rotationMatrix.M13); ScenarioOutput_M21.Text = String.Format("{0,8:0.00000}", rotationMatrix.M21); ScenarioOutput_M22.Text = String.Format("{0,8:0.00000}", rotationMatrix.M22); ScenarioOutput_M23.Text = String.Format("{0,8:0.00000}", rotationMatrix.M23); ScenarioOutput_M31.Text = String.Format("{0,8:0.00000}", rotationMatrix.M31); ScenarioOutput_M32.Text = String.Format("{0,8:0.00000}", rotationMatrix.M32); ScenarioOutput_M33.Text = String.Format("{0,8:0.00000}", rotationMatrix.M33); // Yaw accuracy switch (reading.YawAccuracy) { case MagnetometerAccuracy.Unknown: ScenarioOutput_YawAccuracy.Text = "Unknown"; break; case MagnetometerAccuracy.Unreliable: ScenarioOutput_YawAccuracy.Text = "Unreliable"; break; case MagnetometerAccuracy.Approximate: ScenarioOutput_YawAccuracy.Text = "Approximate"; break; case MagnetometerAccuracy.High: ScenarioOutput_YawAccuracy.Text = "High"; break; default: ScenarioOutput_YawAccuracy.Text = "No data"; break; } } }
public void OnGetOrientation() { OrientationSensor sensor = OrientationSensor.GetDefault(); if (sensor != null) { OrientationSensorReading reading = sensor.GetCurrentReading(); OrientationInfo = $"Quaternion: {reading.Quaternion.Output()} Rotation: {reading.RotationMatrix.Ouput()} Yaw accuracy: {reading.YawAccuracy}"; } else { OrientationInfo = "Compass not found"; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); sIncline = Inclinometer.GetDefault(SensorReadingType.Absolute); sDisplay = DisplayInformation.GetForCurrentView(); sOrient = OrientationSensor.GetDefault(SensorReadingType.Absolute); sOrient.ReadingChanged += SOrient_ReadingChanged; sDisplay.OrientationChanged += SDisplay_OrientationChanged; sIncline.ReadingChanged += SIncline_ReadingChanged; LastDisplayOrient = sDisplay.CurrentOrientation; LastIncline = sIncline.GetCurrentReading(); LastOrient = sOrient.GetCurrentReading(); timer.Start(); }
public OrientationSensorReading GetOrientationSensorReading() { if (_orientationSensor == null) { throw new InvalidOperationException("The orientation sensor is either not present or has not been initialized"); } var reading = _orientationSensor.GetCurrentReading(); return(reading); // Available reading values include: // reading.Quaternion // reading.RotationMatrix // reading.YawAccuracy // reading.Timestamp }
void ReadOrientationData() { if (orientationSensor != null) { OrientationSensorReading reading = orientationSensor.GetCurrentReading(); if (reading != null) { SensorRotationMatrix srm = reading.RotationMatrix; Matrix3D rotationMatrix = new Matrix3D( srm.M11, srm.M12, srm.M13, 0, srm.M21, srm.M22, srm.M23, 0, srm.M31, srm.M32, srm.M33, 0, 0, 0, 0, 0); Matrix3D bodySpaceMatrix = pointMatrix * rotationMatrix; point.Text = string.Format("Transform of (0.0, 10.0, 0.0) = ({0:F1}, {1:F1}, {2:F1})", bodySpaceMatrix.OffsetX, bodySpaceMatrix.OffsetY, bodySpaceMatrix.OffsetZ); } } }
void OnBitmapImageOpened(object sender, RoutedEventArgs args) { progressBar.Visibility = Visibility.Collapsed; statusText.Visibility = Visibility.Collapsed; // Save image dimensions imageWidth = bitmapImage.PixelWidth; imageHeight = bitmapImage.PixelHeight; titleText.Text = String.Format("{0} ({1}\x00D7{2})", title, imageWidth, imageHeight); // Initialize image transforms zoomInScale = Math.Min(pageWidth / imageWidth, pageHeight / imageHeight); // Start OrientationSensor going if (orientationSensor != null) { ProcessNewOrientationReading(orientationSensor.GetCurrentReading()); orientationSensor.ReportInterval = orientationSensor.MinimumReportInterval; orientationSensor.ReadingChanged += OnOrientationSensorReadingChanged; } }
async void OnMainPageLoaded(object sender, RoutedEventArgs args) { if (inclinometer == null) { await new MessageDialog("Inclinometer is not available").ShowAsync(); } else { // Start the Inclinometer events ShowYawPitchRoll(inclinometer.GetCurrentReading()); inclinometer.ReadingChanged += OnInclinometerReadingChanged; } if (orientationSensor == null) { await new MessageDialog("OrientationSensor is not available").ShowAsync(); } else { // Start the OrientationSensor events ShowOrientation(orientationSensor.GetCurrentReading()); orientationSensor.ReadingChanged += OrientationSensorChanged; } }