コード例 #1
0
        public void onOrientationChanged(Device device)
        {
            PairableDevice pairableDevice = (PairableDevice)device;
            // Draw two lines to serve as field of view indicators
            double topAngle = Util.NormalizeAngle(pairableDevice.Orientation.Value + pairableDevice.FieldOfView.Value);
            double topX     = Math.Cos(topAngle * Math.PI / 180);
            double topY     = Math.Sin(topAngle * Math.PI / 180);


            double bottomAngle = Util.NormalizeAngle(pairableDevice.Orientation.Value - pairableDevice.FieldOfView.Value);
            double bottomX     = Math.Cos(bottomAngle * Math.PI / 180);
            double bottomY     = Math.Sin(bottomAngle * Math.PI / 180);

            Point newLeft  = DrawingResources.ConvertPointToProperLength(new Point(topX, topY), DrawingResources.DEVICE_FOV_LENGTH);
            Point newRight = DrawingResources.ConvertPointToProperLength(new Point(bottomX, bottomY), DrawingResources.DEVICE_FOV_LENGTH);

            //Dispatch UI Changes to Main Thread
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                LeftLine.X2 = newLeft.X;
                LeftLine.Y2 = -newLeft.Y;

                RightLine.X2 = newRight.X;
                RightLine.Y2 = -newRight.Y;

                if (pairableDevice.PairingState == PairingState.Paired)
                {
                    LeftLine.Visibility  = System.Windows.Visibility.Visible;
                    RightLine.Visibility = System.Windows.Visibility.Visible;
                }
            }));
        }