1

我正在使用最新的 googleVr SDK(1.10),但我测试了一些统一的示例场景,如城堡防御,我注意到当我将手机放在桌子上时视图开始漂移。有没有办法以编程方式防止这种漂移?

我看了一些视频来纠正三星上的陀螺仪,但我想要一些代码来防止这种情况

4

1 回答 1

1

正如这篇文章中所解释的,这仍然是一个未解决的问题:

GvrViewerMain 自己旋转相机。Unity3D+谷歌VR

但是根据您的需要,您可能会发现以下解决方法很有用。

这个想法是找到增量旋转,如果太小则忽略它。

using UnityEngine;

public class GyroCorrector  {

    public enum Correction
    {
        NONE,
        BEST
    }

    private Correction m_correction;

    public GyroCorrector(Correction a_correction)
    {
        m_correction = a_correction;
    }

    private void CorrectValueByThreshold(ref Vector3 a_vDeltaRotation, float a_fXThreshold = 1e-1f, float a_fYThreshold = 1e-2f, float a_fZThreshold = 0.0f)
    {

      //  Debug.Log(a_quatDelta.x + " " + a_quatDelta.y + " " + a_quatDelta.z );

        a_vDeltaRotation.x = Mathf.Abs(a_vDeltaRotation.x) < a_fXThreshold ? 0.0f : a_vDeltaRotation.x + a_fXThreshold;
        a_vDeltaRotation.y = Mathf.Abs(a_vDeltaRotation.y) < a_fYThreshold ? 0.0f : a_vDeltaRotation.y + a_fYThreshold;
        a_vDeltaRotation.z = Mathf.Abs(a_vDeltaRotation.z) < a_fZThreshold ? 0.0f : 0.0f;//We just ignore the z rotation
    }

    public Vector3 Reset()
    {
        return m_v3Init;
    }

    public Vector3 Get(Vector3 a_v3Init)
    {
        if (!m_bInit)
        {
            m_bInit = true;
            m_v3Init = a_v3Init;
        }

        Vector3 v = Input.gyro.rotationRateUnbiased;
        if (m_correction == Correction.NONE)
            return a_v3Init + v;


        CorrectValueByThreshold(ref v);

        return a_v3Init - v;
    }

}

...然后在“GvrHead”的“UpdateHead”方法中使用类似的东西:

GvrViewer.Instance.UpdateState();

if (trackRotation)
{
    var rot = Input.gyro.attitude;//GvrViewer.Instance.HeadPose.Orientation;

    if(Input.GetMouseButtonDown(0))
    {
        transform.eulerAngles = m_gyroCorrector.Reset();
    }
    else
    {
        transform.eulerAngles = m_gyroCorrector.Get(transform.eulerAngles);//where m_gyroCorrector is an instance of the previous class
    }

}

你可能会发现一些问题。主要但不排他:

  • 移动头部时会有延迟问题,因为有偏移量来检测移动

  • 您正在处理不精确的相对位置。所以你在做相反的动作时并不是100%肯定会找到相同的位置。

  • 您使用的是欧拉表示而不是四元数,它似乎不太准确。

您可能还对这些有关该领域的链接感兴趣:

http://scholarworks.uvm.edu/cgi/viewcontent.cgi?article=1449&context=graddis

手机上的陀螺仪漂移

和这段代码: https ://github.com/asus4/UnityIMU

希望能有所帮助,

于 2017-02-22T16:01:45.447 回答