Exemplo n.º 1
0
 /// <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();
     }
 }
Exemplo n.º 2
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";
            }
        }
        /// <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
        /// <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);
            });
        }
Exemplo n.º 6
0
    public void onConfirmLookDirection()
    {
        // playDing();

        SensorQuaternion currentQ = _wearableControl.LastSensorFrame.rotation;
        float            diff     = currentQ.value.eulerAngles.y - userCenter.value.eulerAngles.y;

        // float DotResult = Vector3.Dot(Vector3.forward, currentQ.value.eulerAngles);
        // Debug.Log(diff);
        // transform.InverseTransformPoint(otherTransform.position)
        // if(diff < 30f && diff > 300f) {
        //     Debug.Log("Center"+ Time.time + " " + diff);
        //     play
        // }
        // else
        if (diff > 0 && diff < 180f)
        {
            Debug.Log("Right" + Time.time + " " + diff);
            playLeftAudio();
        }
        else
        {
            Debug.Log("Left" + Time.time + " " + diff);
            playRightAudio();
        }
    }
        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;
        }
        private void ReadOrientationRotation2(ref Quaternion quaternion)
        {
#if WINDOWS_STORE_APP
            _sQuaternion = _sensor.GetCurrentReading().Quaternion;
            _quaternion.Set(_sQuaternion.X, _sQuaternion.Y, _sQuaternion.Z, _sQuaternion.W);
            _rotation = _quaternion.eulerAngles;

            var alpha = _rotation.z;
            var beta  = _rotation.y - 180.0f;
            var gamma = (_rotation.x / 2.0f) - 90.0f;
            // a: Z (0/360)
            // b: Y: (-180/180)
            // g: X: (-90/90)

            var degtorad = Mathf.PI / 180.0f;
            var z        = alpha * degtorad / 2.0f;
            var x        = beta * degtorad / 2.0f;
            var y        = gamma * degtorad / 2.0f;
            var cX       = Mathf.Cos(x);
            var cY       = Mathf.Cos(y);
            var cZ       = Mathf.Cos(z);
            var sX       = Mathf.Sin(x);
            var sY       = Mathf.Sin(y);
            var sZ       = Mathf.Sin(z);

            // ZXY quaternion construction.
            var w = cX * cY * cZ - sX * sY * sZ;
            x = sX * cY * cZ - cX * sY * sZ;
            y = cX * sY * cZ + sX * cY * sZ;
            z = cX * cY * sZ + sX * sY * cZ;

            quaternion.Set(x, y, z, w);

            //var deviceQuaternion = new Quaternion(x, y, z, w);

            // Correct for the screen orientation.

            /*var screenOrientation = (GetOrientation() * degtorad) / 2.0f;
             * var screenTransform = new Quaternion(0.0f, 0.0f, -Mathf.Sin(screenOrientation), Mathf.Cos(screenOrientation));
             *
             * var deviceRotation = deviceQuaternion * screenTransform;
             * var r22 = Mathf.Sqrt(0.5f);
             * deviceRotation = new Quaternion(-r22, 0.0f, 0.0f, r22) * deviceRotation;
             *
             * var rot = deviceQuaternion.eulerAngles;
             * var temp = rot.x;
             * rot.z = 0;
             * rot.x = 0;
             * rot.y = rot.x;
             * deviceQuaternion = Quaternion.Euler(rot);
             *
             * quaternion = deviceRotation;*/
#endif
        }
Exemplo n.º 9
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);
                    }
                });
            }
        }
        /// <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;
                }
            });
        }
Exemplo n.º 11
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;
                }
            }
        }
Exemplo n.º 12
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);
                        }
                    }
                });
            }
        }
Exemplo n.º 13
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;
        }
Exemplo n.º 14
0
        void Update()
        {
            // sample current orientation of frame
            SensorQuaternion q = _wearableControl.LastSensorFrame.rotation;

            samples.AddFirst(new Sample(Time.time, q));

            // max of 60 samples
            if (samples.Count >= 60)
            {
                samples.RemoveLast();
            }
            if (waitTime > 0)
            {
                waitTime -= Time.deltaTime;
            }
            else
            {
                DetectNod();
                DetectHeadshake();
            }
        }
Exemplo n.º 15
0
 public static Quaternion ToQuaternion(this SensorQuaternion q) =>
 new Quaternion(q.X, q.Y, q.Z, q.W);
 public static string Output(this SensorQuaternion q) =>
 $"x {q.X} y {q.Y} z {q.Z} w {q.W}";
Exemplo n.º 17
0
        private void OnReadingChange(OrientationSensor sender, OrientationSensorReadingChangedEventArgs args)
        {
            SensorQuaternion quaternion = args.Reading.Quaternion;

            Ball.SetAccelaration(quaternion.X, quaternion.Y);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Sets center view axis for orienting across spotlights
 /// </summary>
 protected void setRelativeDirection()
 {
     userCenter = _wearableControl.LastSensorFrame.rotation;
 }