Exemplo n.º 1
0
    // 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();
        }
    }