Esempio n. 1
0
    /// <summary>
    /// Saves the ZED's offset from the tracked object as a file to be loaded within Unity or from any ZED application
    /// built to load such a calibration file.
    /// <para>Destination directory defined by the CALIB_FILE_PATH constant.</para>
    /// </summary>
    public void SaveCalibFile()
    {
        int    slashindex = filePath.LastIndexOf('\\');
        string directory  = filePath.Substring(0, slashindex);

        print(directory);
        if (!System.IO.Directory.Exists(directory))
        {
            System.IO.Directory.CreateDirectory(directory);
        }
        using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath))
        {
            Vector3 localpos = zedManager.transform.localPosition;             //Shorthand.
            Vector3 localrot = zedManager.transform.localRotation.eulerAngles; //Shorthand.

            file.WriteLine("x=" + localpos.x);
            file.WriteLine("y=" + localpos.y);
            file.WriteLine("z=" + localpos.z);
            file.WriteLine("rx=" + localrot.x);
            file.WriteLine("ry=" + localrot.y);
            file.WriteLine("rz=" + localrot.z);

#if ZED_STEAM_VR
            string indexstring = "indexController=";
            if (controllerTracker.index > 0)
            {
                var snerror  = Valve.VR.ETrackedPropertyError.TrackedProp_Success;
                var snresult = new System.Text.StringBuilder((int)64);
                indexstring += Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)controllerTracker.index,
                                                                                     Valve.VR.ETrackedDeviceProperty.Prop_SerialNumber_String, snresult, 64, ref snerror);
            }
            else
            {
                indexstring += "NONE";
            }

            file.WriteLine(indexstring);
#endif
            file.Close();
            print("Calibration saved to " + filePath);

            MessageDisplay.DisplayTemporaryMessageAll("Saved calibration file to:\r\n" + filePath);
        }
    }