Example #1
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();
        }