Exemplo n.º 1
0
        private void OnGetOrientation(object sender, RoutedEventArgs e)
        {
            OrientationSensor        orientation = OrientationSensor.GetDefault();
            OrientationSensorReading reading     = orientation.GetCurrentReading();

            this.DefaultViewModel["OrientationSensorResult"] = GetOrientationSensorResult(reading);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This is the event handler for ReadingChanged events.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        //<SnippetReadingChangedCS>
        async private void ReadingChanged(object sender, OrientationSensorReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                OrientationSensorReading reading = e.Reading;

                // 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>
        /// 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);
            }
        }
Exemplo n.º 4
0
        // For more information on using orientation sensors, see the OrientationSensor sample.
        void GetOrientationReport()
        {
            OrientationSensor sensor;

            // If there is a version of GetDefault that lets us specify the optimization goal,
            // then use it. Otherwise, use the regular version.
            if (hasOrientationWithOptimizationGoal)
            {
                sensor = OrientationSensor.GetDefault(SensorReadingType.Absolute, SensorOptimizationGoal.PowerEfficiency);
            }
            else
            {
                sensor = OrientationSensor.GetDefault();
            }

            if (sensor != null)
            {
                OrientationSensorReading reading    = sensor.GetCurrentReading();
                SensorQuaternion         quaternion = reading.Quaternion;
                rootPage.NotifyUser($"X: {quaternion.X}, Y: {quaternion.Y}, Z: {quaternion.Z}, W: {quaternion.W}", NotifyType.StatusMessage);

                // Restore the default report interval to release resources while the sensor is not in use.
                sensor.ReportInterval = 0;
            }
            else
            {
                rootPage.NotifyUser("Sorry, no sensor found", NotifyType.ErrorMessage);
            }
        }
Exemplo n.º 5
0
        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";
            }
        }
 private void orentation_ReadingChanged(object sender, Windows.Devices.Sensors.OrientationSensorReadingChangedEventArgs e)
 {
     System.Windows.Application.Current.Dispatcher.BeginInvoke((Action) delegate
     {
         OrientationSensorReading = e.Reading;
     });
 }
 /// <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);
     }
 }
Exemplo n.º 8
0
        private string GetOrientationSensorResult(OrientationSensorReading reading)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("quaternion w: {0}, x: {1}, y: {2}, z: {3}\n", reading.Quaternion.W, reading.Quaternion.X, reading.Quaternion.Y, reading.Quaternion.Z);
            sb.AppendFormat("{0,10:0.000}{1,10:0.000}{2,10:0.000}\n{3,10:0.000}{4,10:0.000}{5,10:0.000}\n{6,10:0.000}{7,10:0.000}{8,10:0.000}\n", reading.RotationMatrix.M11, reading.RotationMatrix.M12, reading.RotationMatrix.M13, reading.RotationMatrix.M21, reading.RotationMatrix.M22, reading.RotationMatrix.M23, reading.RotationMatrix.M31, reading.RotationMatrix.M32, reading.RotationMatrix.M33);
            sb.AppendFormat("yaw accuracy: {0}\n", reading.YawAccuracy);
            return(sb.ToString());
        }
Exemplo n.º 9
0
        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");
            }
        }
Exemplo n.º 10
0
        public String GetOrientationSensorDisplayText(OrientationSensorReading reading)
        {
            if (reading == null)
            {
                return("No Reading Available.");
            }

            return(String.Format("Q(x)= {0} Q(y)={1} Q(z)={2} Q(w)={3}",
                                 reading.Quaternion.X,
                                 reading.Quaternion.Y,
                                 reading.Quaternion.Z,
                                 reading.Quaternion.W));
        }
Exemplo n.º 11
0
        private async void Or_ReadingChanged(OrientationSensor sender, OrientationSensorReadingChangedEventArgs args)
        {
            if (myBool)
            {
                OrientationSensorReading reading = args.Reading;

                // Quaternion values
                SensorQuaternion q = reading.Quaternion;
                double           y = args.Reading.Quaternion.Y;
                if (y < 0)
                {
                    y = y + 2;
                }

                double pitch = y;
                //    pitch = pitch * 180 / Math.PI;
                if (yaw < 0)
                {
                    yaw += 360;
                }


                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    for (; lol.Children.Count > 1;)
                    {
                        lol.Children.RemoveAt(1);
                    }

                    foreach (PointerViewAR n in li2)
                    {
                        Image img            = new Image();
                        img.Name             = n.Id;
                        img.Width            = 250;
                        img.Height           = 250;
                        img.Source           = n.Media;
                        TranslateTransform t = new TranslateTransform();


                        t.X = angleDiff(n.Yaw, yaw) * stepW * 2;
                        t.Y = (n.Pitch - pitch) * stepH * 2;
                        Debug.WriteLine((n.Yaw - yaw).ToString() + ",");

                        img.RenderTransform = t;
                        img.IsTapEnabled    = true;
                        img.Tapped         += Img_Tapped;
                        lol.Children.Add(img);
                    }
                });
            }
        }
Exemplo n.º 12
0
        /// <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";
            }
        }
        /// <summary>
        /// This is the event handler for ReadingChanged events.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async private void ReadingChanged(object sender, OrientationSensorReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                OrientationSensorReading reading = e.Reading;

                // 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 ResetHome()
        {
            var incl = OrientationSensor.GetDefault();


            OrientationSensorReading inc = incl.GetCurrentReading();

            if (inc != null)
            {
                zeroSet = true;

                zeroMatrix = inc.RotationMatrix;
            }
        }
Exemplo n.º 16
0
 static Matrix ConvertToMatrix(OrientationSensorReading reading)
 {
     return(new Matrix
     {
         Xx = reading.RotationMatrix.M11,
         Xy = reading.RotationMatrix.M12,
         Xz = reading.RotationMatrix.M13,
         Yx = reading.RotationMatrix.M21,
         Yy = reading.RotationMatrix.M22,
         Yz = reading.RotationMatrix.M23,
         Zx = reading.RotationMatrix.M31,
         Zy = reading.RotationMatrix.M32,
         Zz = reading.RotationMatrix.M33
     });
 }
Exemplo n.º 17
0
        private async void Or_ReadingChanged(OrientationSensor sender, OrientationSensorReadingChangedEventArgs args)
        {
            if (myBool)
            {
                OrientationSensorReading reading = args.Reading;

                // Quaternion values
                SensorQuaternion q = reading.Quaternion;
                double           y = args.Reading.Quaternion.Y;
                if (y < 0)
                {
                    y = y + 2;
                }
                pitch = y;
                //    pitch = pitch * 180 / Math.PI;
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    for (; lol.Children.Count > 6;)
                    {
                        lol.Children.RemoveAt(6);
                    }

                    foreach (PointerViewAR n in li2)
                    {
                        Image img            = new Image();
                        img.Name             = n.Id;
                        img.Width            = 250;
                        img.Height           = 250;
                        img.Source           = n.Media;// img.Stretch = Stretch.UniformToFill;
                        TranslateTransform t = new TranslateTransform();
                        double dis           = getDistance(n.lat, n.lon, pos.Coordinate.Latitude, pos.Coordinate.Longitude);
                        if (dis < 50)
                        //TODO: in prod write distance<20
                        {
                            // double ang = getangle(n.lat, n.lon, pos.Coordinate.Latitude, pos.Coordinate.Longitude);
                            t.X = angleDiff(n.Yaw, yaw) * stepW * 2;
                            t.Y = (n.Pitch - pitch) * stepH * 2;
                            img.RenderTransform = t;
                            img.IsTapEnabled    = true;
                            img.Tapped         += Img_Tapped;
                            lol.Children.Add(img);
                            Grid.SetRow(img, 1);
                        }
                    }
                });
            }
        }
        public void OnGetOrientationReport()
        {
            OrientationSensor sensor = OrientationSensor.GetDefault();

            if (sensor != null)
            {
                sensor.ReportInterval = Math.Max(sensor.MinimumReportInterval, 1000);

                sensor.ReadingChanged += async(s, e) =>
                {
                    OrientationSensorReading reading = e.Reading;
                    await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                    {
                        OrientationInfoReport = $"Quaternion: {reading.Quaternion.Output()} Rotation: {reading.RotationMatrix.Ouput()} Yaw accuracy: {reading.YawAccuracy} { reading.Timestamp:T}";
                    });
                };
            }
        }
Exemplo n.º 19
0
        public static void SetReadingText(TextBlock textBlock, OrientationSensorReading reading)
        {
            SensorQuaternion quaternion       = reading.Quaternion; // get a reference to the object to avoid re-creating it for each access
            string           quaternionReport = string.Format("W: {0,5:0.00}, X: {1,5:0.00}, Y: {2,5:0.00}, Z: {3,5:0.00}",
                                                              quaternion.W, quaternion.X, quaternion.Y, quaternion.Z);

            SensorRotationMatrix rotationMatrix = reading.RotationMatrix;
            string rotationMatrixReport         = string.Format(
                "M11: {0,5:0.00}, M12: {1,5:0.00}, M13: {2,5:0.00}\n" +
                "M21: {3,5:0.00}, M22: {4,5:0.00}, M23: {5,5:0.00}\n" +
                "M31: {6,5:0.00}, M32: {7,5:0.00}, M33: {8,5:0.00}",
                rotationMatrix.M11, rotationMatrix.M12, rotationMatrix.M13,
                rotationMatrix.M21, rotationMatrix.M22, rotationMatrix.M23,
                rotationMatrix.M31, rotationMatrix.M32, rotationMatrix.M33);

            string yawAccuracyReport;

            switch (reading.YawAccuracy)
            {
            case MagnetometerAccuracy.Unknown:
                yawAccuracyReport = "unknown";
                break;

            case MagnetometerAccuracy.Unreliable:
                yawAccuracyReport = "unreliable";
                break;

            case MagnetometerAccuracy.Approximate:
                yawAccuracyReport = "approximate";
                break;

            case MagnetometerAccuracy.High:
                yawAccuracyReport = "high";
                break;

            default:
                yawAccuracyReport = "other";
                break;
            }

            textBlock.Text = "Quaternion:\n" + quaternionReport + "\n\n" +
                             "Rotation Matrix:\n" + rotationMatrixReport + "\n\n" +
                             "Yaw Accuracy:\n" + yawAccuracyReport;
        }
        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);
                }
            }
        }
Exemplo n.º 21
0
        void ProcessNewOrientationReading(OrientationSensorReading orientationReading)
        {
            if (orientationReading == null)
            {
                return;
            }

            // Get the rotation matrix & convert to horizontal coordinates
            SensorRotationMatrix m = orientationReading.RotationMatrix;

            if (m == null)
            {
                return;
            }

            Matrix3D matrix3d = new Matrix3D(m.M11, m.M12, m.M13, 0,
                                             m.M21, m.M22, m.M23, 0,
                                             m.M31, m.M32, m.M33, 0,
                                             0, 0, 0, 1);

            if (!matrix3d.HasInverse)
            {
                return;
            }

            HorizontalCoordinate horzCoord = HorizontalCoordinate.FromMotionMatrix(matrix3d);

            // Set the transform center on the Image element
            imageTransform.CenterX = (imageWidth + maxDimension) *
                                     (180 + horzCoord.Azimuth) / 360 - maxDimension / 2;
            imageTransform.CenterY = (imageHeight + maxDimension) *
                                     (90 - horzCoord.Altitude) / 180 - maxDimension / 2;

            // Set the translation on the Border element
            borderTransform.TranslateX = imageTransform.CenterX - pageWidth / 2;
            borderTransform.TranslateY = imageTransform.CenterY - pageHeight / 2;

            // Get rotation from Tilt
            rotation = -horzCoord.Tilt;
            UpdateImageTransforms();
        }
Exemplo n.º 22
0
        void ShowOrientation(OrientationSensorReading orientationReading)
        {
            if (orientationReading == null)
            {
                return;
            }

            SensorRotationMatrix matrix = orientationReading.RotationMatrix;

            if (matrix == null)
            {
                return;
            }

            m11Text.Text = matrix.M11.ToString("F3");
            m12Text.Text = matrix.M12.ToString("F3");
            m13Text.Text = matrix.M13.ToString("F3");

            m21Text.Text = matrix.M21.ToString("F3");
            m22Text.Text = matrix.M22.ToString("F3");
            m23Text.Text = matrix.M23.ToString("F3");

            m31Text.Text = matrix.M31.ToString("F3");
            m32Text.Text = matrix.M32.ToString("F3");
            m33Text.Text = matrix.M33.ToString("F3");

            // Convert rotation matrix to axis and angle
            double angle = Math.Acos((matrix.M11 + matrix.M22 + matrix.M33 - 1) / 2);

            angleText.Text = (180 * angle / Math.PI).ToString("F0");

            if (angle != 0)
            {
                double twoSine = 2 * Math.Sin(angle);
                double x       = (matrix.M23 - matrix.M32) / twoSine;
                double y       = (matrix.M31 - matrix.M13) / twoSine;
                double z       = (matrix.M12 - matrix.M21) / twoSine;

                axisText.Text = String.Format("({0:F2} {1:F2} {2:F2})", x, y, z);
            }
        }
Exemplo n.º 23
0
        private async void ReadingChanged(object sender, OrientationSensorReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                OrientationSensorReading reading = e.Reading;

                // Quaternion values
                txtQuaternionX.Text = String.Format("{0,8:0.00000}", reading.Quaternion.X);
                txtQuaternionY.Text = String.Format("{0,8:0.00000}", reading.Quaternion.Y);
                txtQuaternionZ.Text = String.Format("{0,8:0.00000}", reading.Quaternion.Z);
                txtQuaternionW.Text = String.Format("{0,8:0.00000}", reading.Quaternion.W);

                // Rotation Matrix values
                txtM11.Text = String.Format("{0,8:0.00000}", reading.RotationMatrix.M11);
                txtM12.Text = String.Format("{0,8:0.00000}", reading.RotationMatrix.M12);
                txtM13.Text = String.Format("{0,8:0.00000}", reading.RotationMatrix.M13);
                txtM21.Text = String.Format("{0,8:0.00000}", reading.RotationMatrix.M21);
                txtM22.Text = String.Format("{0,8:0.00000}", reading.RotationMatrix.M22);
                txtM23.Text = String.Format("{0,8:0.00000}", reading.RotationMatrix.M23);
                txtM31.Text = String.Format("{0,8:0.00000}", reading.RotationMatrix.M31);
                txtM32.Text = String.Format("{0,8:0.00000}", reading.RotationMatrix.M32);
                txtM33.Text = String.Format("{0,8:0.00000}", reading.RotationMatrix.M33);
            });
        }