UWP development direction sensor and UWP development direction Sensor

Source: Internet
Author: User

UWP development direction sensor and UWP development direction Sensor

In UWP development, we can use three methods in the following directions: four elements in OrientationSensor, HeadingMagneticNorth of Compass, and SimpleOrientationSensor.

SimpleOrientationSensor is used in simple cases. It can only read six directions: 0, 90, 180,270, FaceUP, and FaceDown.

        var simpleOrien = SimpleOrientationSensor.GetDefault().GetCurrentOrientation();            switch (simpleOrien)            {                case SimpleOrientation.Facedown:                    // To do ...                    break;                case SimpleOrientation.Faceup:                    // To do ...                    break;                case SimpleOrientation.NotRotated:                    // To do ...                    break;                case SimpleOrientation.Rotated180DegreesCounterclockwise:                    // To do ...                    break;                case SimpleOrientation.Rotated270DegreesCounterclockwise:                    // To do ...                    break;                case SimpleOrientation.Rotated90DegreesCounterclockwise:                    // To do ...                    break;            }

Compass:

        var compass = Compass.GetDefault().GetCurrentReading();            var angle= compass.HeadingMagneticNorth;

It is easy to use, but it seems that you are moving in the direction, that is, if you do not move, the reading is meaningless.

Direction sensor:

        var _sensor = OrientationSensor.GetDefault();            var quaternion = _sensor.GetCurrentReading().Quaternion;            var heading = 180 * Math.Atan2(2 * (quaternion.W * quaternion.Z + quaternion.X * quaternion.Y), 1 - 2 * (quaternion.Y * quaternion.Y + quaternion.Z * quaternion.Z)) / Math.PI;

This may be a little troublesome, because it involves the four-dimensional element. For information about the four-dimensional element, google or flip the book.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.