【问题标题】:How to point a model in ARkit to north pole in real world?如何将 ARkit 中的模型指向现实世界中的北极?
【发布时间】:2018-06-26 12:21:23
【问题描述】:

嗨,我正在尝试一个始终在北方向的模型。如何在现实世界中获得北极方向。

public class PointNoeth : MonoBehaviour {

// Use this for initialization
//void Start () 
IEnumerator Start()
{
    // First, check if user has location service enabled
    if (!Input.location.isEnabledByUser)
        yield break;

    // Start service before querying location
    Input.location.Start();

    // Wait until service initializes
    int maxWait = 20;
    while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
    {
        yield return new WaitForSeconds(1);
        maxWait--;
    }

    // Service didn't initialize in 20 seconds
    if (maxWait < 1)
    {
        print("Timed out");
        yield break;
    }

    // Connection has failed
    if (Input.location.status == LocationServiceStatus.Failed)
    {
        print("Unable to determine device location");
        yield break;
    }
    else
    {
        // Access granted and location value could be retrieved
        print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
    }

    // Stop service if there is no need to query location updates continuously
    Input.location.Stop();

    Input.compass.enabled = true;
}

// Update is called once per frame
void Update () 
{

    transform.rotation = Quaternion.Euler(0, -Input.compass.trueHeading, 0);

    /
}
}

在更新功能中,我设置了旋转。我将箭头标记作为我的模型。最初我让它指向 z 方向,但是当我点击播放时,它变为 -x 轴。当我签入我的时也会发生同样的情况设备。当我使用手机中的工具检查现实世界的北极时,它的方向是相反的。那么如何将我的模型指向北极

【问题讨论】:

  • 好吧,在编辑器中,你的对象被旋转到(90, 0, -90),你的代码告诉它旋转到(0, $heading, 0)...

标签: c# unity3d orientation


【解决方案1】:

您可以将世界对齐方式更改为基于指南针方向,然后在放置对象时可以根据AR Kit World Alignment 旋转它

为此,您需要使用带有参数 UnityARAlignment.UnityARAlignmentGravityAndHeading 的 ARKitSessionConfiguration 对其进行配置 有关枚举的更多信息可以找到here

【讨论】:

    【解决方案2】:

    我会用Input.compass.magneticHeading 来解决这个问题。 更多详情可以查看官方文档here

    检测到平面并放置 ar 对象后,我像这样旋转它

    arObject.transform.rotation = Quaternion.Euler(0f, -Input.compass.magneticHeading, 0f);
    

    这会将对象旋转到朝北。
    现在如果我想朝南,我会做类似的事情

    private float directionOffset = 180f;// 0f - north, 45f - northeast, 90f - east, 135f - southeast etc.
    arObject.transform.rotation = Quaternion.Euler(0f, -Input.compass.magneticHeading + directionOffset, 0f);
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2017-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-29
      • 2017-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多