/// <summary>
    /// Rotates a point based on orientation correction received from VPS service.
    /// </summary>
    /// <returns>The point.</returns>
    /// <param name="pos">Position.</param>
    private static Vector3 RotatePoint(Vector3 pos)
    {
        Vector3 rotatedPos = new Vector3();

        //Create a parent object to rotate pos around this object
        GameObject parent = new GameObject();

        GameObject posToRotate = new GameObject();

        posToRotate.transform.parent = parent.transform;

        //Before rotation
        posToRotate.transform.position = pos;

        //GetOrientationCorrection() is identity before Localization
        Quaternion rotInWorld = XRSessionManager.GetSession().GetOrientationCorrection() * OrientationUtils.UnityToWorld(parent.transform.rotation);

        //Rotate parent object which will rotate its child(posToRotate) around it
        parent.transform.rotation = OrientationUtils.WorldToUnity(rotInWorld);

        rotatedPos = posToRotate.transform.position;    // Unity WorldPos of pos

        Destroy(posToRotate);
        Destroy(parent);

        return(rotatedPos);
    }
    /// <summary>
    /// Rotates a point based on orientation correction received from VPS service.
    /// </summary>
    /// <returns>The point.</returns>
    /// <param name="point">Position.</param>
    private static Vector3 RotatePoint(Vector3 point, bool useCompass = true)
    {
        // Ar orgin where all values recieved rom Arcore/Arkit will be under this origin
        GameObject arOrigin = new GameObject("ArOrigin");

        // Create a child Gameobject and set its localPosition to the point we get from ArCore/ArKit
        GameObject pointGO = new GameObject("Point");

        pointGO.transform.parent        = arOrigin.transform;
        pointGO.transform.localPosition = point;
        pointGO.transform.localRotation = Quaternion.identity;

        if (useCompass)
        {
            // First rotate this origin to align with trueHeading received from sensor
            arOrigin.transform.rotation = Quaternion.Euler(0, ArWorldTracking.TrueHeading, 0);
        }

        // Then rotate this again based on offset received from VPS Service
        Quaternion rotInWorld = XRSessionManager.GetSession().GetYawOrientationCorrection() * OrientationUtils.UnityToWorld(arOrigin.transform.rotation) * XRSessionManager.GetSession().GetPitchOrientationCorrection();

        arOrigin.transform.rotation = OrientationUtils.WorldToUnity(rotInWorld);

        var rotatedPos = pointGO.transform.position;    // Unity WorldPos of pos

        Destroy(arOrigin);
        Destroy(pointGO);

        return(rotatedPos);
    }
    public override Quaternion GetOrientation()
    {
        if (_providerStatus != ProviderStatus.Ready)
        {
            return(Quaternion.identity);
        }

        return(OrientationUtils.WorldToUnity(_sampleManager.GetDataAtCurrentIndex().quaternion));
    }
Beispiel #4
0
 public override Quaternion GetOrientation()
 {
     return(OrientationUtils.WorldToUnity(_sampleManager.GetOrientationAtCurrentIndex()));
 }