Exemple #1
0
    private void Log(bool isLocalizationRequest)
    {
        Data data = new Data();

        data.XrCamPos              = XRSessionManager.GetSession().GetXRCameraPosition();
        data.XrCamOrient           = XRSessionManager.GetSession().GetXRCameraOrientation();
        data.GpsPos                = XRSessionManager.GetSession().GetXRCameraLocation();
        data.GpsOrient             = OrientationUtils.UnityToWorld(XRSessionManager.GetSession().GetXRCameraOrientation());
        data.ProjectionMatrix      = XRSessionManager.GetSession().VideoProvider.GetProjectionMatrix();
        data.TimeStamp             = DateTime.Now.ToString("O");
        data.IsLocalizationRequest = isLocalizationRequest;

        _datas.Add(data);

        string jsonData = JsonHelper.ToJson <Data>(_datas.ToArray());

        File.WriteAllText(_path, jsonData);

        //Debug.Log("XR Cam Position: " + XRSessionManager.GetSession().GetXRCameraPosition());
        //Debug.Log("XR Cam Orientation: " + XRSessionManager.GetSession().GetXRCameraOrientation());
        //Debug.Log("GPS Position: " + XRSessionManager.GetSession().GetXRCameraLocation());
        //Debug.Log("GPS Orientation" + OrientationUtils.UnityToWorld(XRSessionManager.GetSession().GetXRCameraOrientation()));
        //Debug.Log("XR Cam Projection Matrix: " + XRSessionManager.GetSession().GetXRCameraPosition());
        //Debug.Log("Localization Request: " + isLocalizationRequest);
        //Debug.Log("Time Stamp: " + DateTime.Now.ToString("O"));
    }
    /// <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);
    }