Mapbox Ar does not work in all directions

故事扮演 提交于 2019-12-24 21:23:57

问题


I have built an augmented reality application in Unity through Mapbox. Also, I geolocated some points through Mapbox. Points seems in AR in the application. But, I realized that when application is initialized the direction of the phone is important. It just shows the truth when phone follows the north.

I have some searched on internet, but I couldn't find any exact information.

I prefer to work application independently from phone direction. Can somebody explain that or are there any solution for this ?


回答1:


What you are probably looking for would be Input.compass → Compass and in specific

Input.compass.magneticHeading

The heading in degrees relative to the magnetic North Pole. (Read Only)

The value in this property is always measured relative to the top of the screen in its current orientation. The heading of magnetic north is not exactly the same as true geographical north - to get the exact heading, use the trueHeading property.

public class Example : MonoBehaviour
{
    void Start()
    {
        Input.location.Start();
    }

    void Update()
    {
        // Orient an object to point to magnetic north.
        transform.rotation = Quaternion.Euler(0, -Input.compass.magneticHeading, 0);
    }
}

or Input.compass.trueHeading

The heading in degrees relative to the geographic North Pole. (Read Only)

The value in this property is always measured relative to the top of the screen in its current orientation. Note, that if you want this property to contain a valid value, you must also enable location updates by calling Input.location.Start(). (Read Only)

Usage examples from the API

public class Example : MonoBehaviour
{
    void Start()
    {
        Input.location.Start();
    }

    void Update()
    {
        // Orient an object to point northward.
        transform.rotation = Quaternion.Euler(0, -Input.compass.trueHeading, 0);
    }
}


来源:https://stackoverflow.com/questions/57645448/mapbox-ar-does-not-work-in-all-directions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!