// * * * * * * * * * * * * * // SetInitialCalibrationState // We call this before we start the Update loop to see if // Mag has been set by Calibration tool public void SetInitialCalibarationState() { if (OVRDevice.IsMagCalibrated(0) && OVRDevice.IsYawCorrectionEnabled(0)) { MagCalState = MagCalibrationState.MagReady; } }
// UpdateMagYawDriftCorrection public void UpdateMagYawDriftCorrection() { if (Input.GetKeyDown(KeyCode.Z) == true) { if (MagCalState == MagCalibrationState.MagDisabled) { // Start calibration process if (MagAutoCalibrate == true) { OVRDevice.BeginMagAutoCalibration(0); MagCalState = MagCalibrationState.MagCalibrating; } else { // Go to pre-manual calibration state (to allow for // setting refrence point) MagCalState = MagCalibrationState.MagManualGetReady; return; } } else if (MagCalState == MagCalibrationState.MagManualGetReady) { OVRDevice.SetMagReference(0); OVRDevice.EnableMagYawCorrection(0, true); Quaternion q = Quaternion.identity; if ((CameraController != null) && (CameraController.PredictionOn == true)) { OVRDevice.GetPredictedOrientation(0, ref q); } else { OVRDevice.GetOrientation(0, ref q); } CurEulerRef = q.eulerAngles; // Begin manual calibration OVRDevice.BeginMagManualCalibration(0); MagCalState = MagCalibrationState.MagCalibrating; } else { // Reset calibration process if (MagAutoCalibrate == true) { OVRDevice.StopMagAutoCalibration(0); } else { OVRDevice.StopMagManualCalibration(0); } OVRDevice.EnableMagYawCorrection(0, false); MagCalState = MagCalibrationState.MagDisabled; // Do not show geometry MagShowGeometry = false; ShowGeometry(MagShowGeometry); return; } } // Check to see if calibration is completed if (MagCalState == MagCalibrationState.MagCalibrating) { if (MagAutoCalibrate == true) { OVRDevice.UpdateMagAutoCalibration(0); } else { OVRDevice.UpdateMagManualCalibration(0); } if (OVRDevice.IsMagCalibrated(0) == true) { if (MagAutoCalibrate == true) { MagCalState = MagCalibrationState.MagCalibrated; } else { // Manual Calibration take account of having set the // reference orientation. MagCalState = MagCalibrationState.MagReady; } } } // If we are calibrated, we will set mag reference and // enable yaw correction on a buton press if ((MagCalState == MagCalibrationState.MagCalibrated) || (MagCalState == MagCalibrationState.MagReady)) { if (Input.GetKeyDown(KeyCode.X) == true) { OVRDevice.SetMagReference(0); OVRDevice.EnableMagYawCorrection(0, true); MagCalState = MagCalibrationState.MagReady; Quaternion q = Quaternion.identity; if ((CameraController != null) && (CameraController.PredictionOn == true)) { OVRDevice.GetPredictedOrientation(0, ref q); } else { OVRDevice.GetOrientation(0, ref q); } CurEulerRef = q.eulerAngles; } if ((MagCalState == MagCalibrationState.MagReady) && (Input.GetKeyDown(KeyCode.F6))) { // Toggle showing geometry either on or off if (MagShowGeometry == false) { MagShowGeometry = true; ShowGeometry(MagShowGeometry); } else { MagShowGeometry = false; ShowGeometry(MagShowGeometry); } } UpdateGeometry(); } }
// UpdateMagYawDriftCorrection public void UpdateMagYawDriftCorrection() { bool calibrateInput = false; // Auto if (Input.GetKeyDown(KeyCode.X) == true) { MagAutoCalibrate = true; calibrateInput = true; } // Manual if (Input.GetKeyDown(KeyCode.Z) == true) { MagAutoCalibrate = false; calibrateInput = true; } if (calibrateInput == true) { if (MagCalState == MagCalibrationState.MagDisabled) { // Start calibration process if (MagAutoCalibrate == true) { OVRDevice.BeginMagAutoCalibration(0); MagCalState = MagCalibrationState.MagCalibrating; } else { // Go to pre-manual calibration state (to allow for // setting refrence point) MagCalState = MagCalibrationState.MagManualGetReady; return; } } else if (MagCalState == MagCalibrationState.MagManualGetReady) { // We will set yaw correction before calibration for // Manual mode EnableYawCorrection(0); // Begin manual calibration OVRDevice.BeginMagManualCalibration(0); MagCalState = MagCalibrationState.MagCalibrating; } else { // Reset calibration process if (MagAutoCalibrate == true) { OVRDevice.StopMagAutoCalibration(0); } else { OVRDevice.StopMagManualCalibration(0); } OVRDevice.EnableMagYawCorrection(0, false); MagCalState = MagCalibrationState.MagDisabled; // Do not show geometry MagShowGeometry = false; ShowGeometry(MagShowGeometry); return; } } // Check to see if calibration is completed if (MagCalState == MagCalibrationState.MagCalibrating) { if (MagAutoCalibrate == true) { OVRDevice.UpdateMagAutoCalibration(0); } else { // Check to see if we have aborted manual calibration OVRDevice.UpdateMagManualCalibration(0); } if (OVRDevice.IsMagCalibrated(0) == true) { if (MagAutoCalibrate == true) { // Manual Calibration took account of having set the // reference orientation at the start; with Auto, we // set it now EnableYawCorrection(0); } MagCalState = MagCalibrationState.MagReady; } } if (MagCalState == MagCalibrationState.MagReady) { // Toggle showing geometry either on or off if (Input.GetKeyDown(KeyCode.F6)) { if (MagShowGeometry == false) { MagShowGeometry = true; ShowGeometry(MagShowGeometry); } else { MagShowGeometry = false; ShowGeometry(MagShowGeometry); } } UpdateGeometry(); } }