public void SaveCalibration() { if (LeapMotionCamera != null) { Vector3 localPosLeapMotion = LeapMotionCamera.transform.localPosition; Quaternion localRotLeapMotion = LeapMotionCamera.transform.localRotation; calibration.localPositionLeapMotion = new float[3] { localPosLeapMotion.x, localPosLeapMotion.y, localPosLeapMotion.z }; calibration.localRotationLeapMotion = new float[4] { localRotLeapMotion.x, localRotLeapMotion.y, localRotLeapMotion.z, localRotLeapMotion.w }; } DisplaySettings ds = displaySettings; ds.Initialized = false; string json = JsonUtility.ToJson(calibration, true); System.IO.File.WriteAllText(OpticalCalibrationsFolder + "DisplayCalibration.json", json); Debug.Log("Saved Calibration"); string json2 = JsonUtility.ToJson(ds, true); System.IO.File.WriteAllText("DisplaySettings.json", json2); }
void LoadCalibration() { calibration = new DisplayCalibration(); calibration.baseline = 0.0f; if (LoadDisplaySettings) { if (File.Exists("DisplaySettings.json")) { displaySettings = JsonUtility.FromJson <DisplaySettings>(File.ReadAllText("DisplaySettings.json")); } } if (File.Exists(OpticalCalibrationsFolder + "DisplayCalibration.json")) { calibration = JsonUtility.FromJson <DisplayCalibration>(File.ReadAllText(OpticalCalibrationsFolder + "DisplayCalibration.json")); if (calibration.baseline == 0.0f) { Debug.LogError("There was a problem loading the calibration"); this.enabled = false; return; } if (loadLeapCalibration) { if (LeapMotionCamera == null) { LeapMotionCamera = GameObject.Find("LeapMotion"); } if (LeapMotionCamera != null) { LeapMotionCamera.transform.localPosition = new Vector3(calibration.localPositionLeapMotion[0], calibration.localPositionLeapMotion[1], calibration.localPositionLeapMotion[2]); LeapMotionCamera.transform.localRotation = new Quaternion(calibration.localRotationLeapMotion[0], calibration.localRotationLeapMotion[1], calibration.localRotationLeapMotion[2], calibration.localRotationLeapMotion[3]); } else { Debug.LogError("Couldn't find the leapmotion object, did you modify the rig???"); } } renderTextureSettings.LeftCamera.transform.localPosition = new Vector3(-(calibration.baseline / 2.0f), 0, 0); renderTextureSettings.RightCamera.transform.localPosition = new Vector3((calibration.baseline / 2.0f), 0, 0); if (renderTextureSettings.RequiresRotation) { renderTextureSettings.LeftCamera.transform.Rotate(new Vector3(0, 0, 90), Space.Self); renderTextureSettings.RightCamera.transform.Rotate(new Vector3(0, 0, 90), Space.Self); } renderTextureSettings.LeftRenderTexture = new RenderTexture(displaySettings.EyeTextureWidth, displaySettings.EyeTextureHeight, 24, renderTextureFormat); renderTextureSettings.RightRenderTexture = new RenderTexture(displaySettings.EyeTextureWidth, displaySettings.EyeTextureHeight, 24, renderTextureFormat); renderTextureSettings.LeftCamera.targetTexture = renderTextureSettings.LeftRenderTexture; renderTextureSettings.RightCamera.targetTexture = renderTextureSettings.RightRenderTexture; myEyeBorders.UpdateBorders(); renderTextureSettings.UpdateProjectionMatrix(renderTextureSettings.LeftCamera.projectionMatrix, true); // = renderTextureSettings..renderTextureSettings.LeftCamera.projectionMatrix,renderTextureSettings.RightCamera.projectionMatrix; renderTextureSettings.UpdateProjectionMatrix(renderTextureSettings.RightCamera.projectionMatrix, false); // // if(renderTextureSettings.RequiresRotation){ // renderTextureSettings.LeftCamera.fieldOfView = 43.01793f;//52.75 for 1.5 weighting // renderTextureSettings.RightCamera.fieldOfView = 43.01793f;//Pre-CALCULATED // } } else { Debug.LogError("Waah! My display calibration file is missing :("); } }