예제 #1
0
    // UpdateMagYawDriftCorrection
    public void UpdateMagYawDriftCorrection()
    {
        if (Input.GetKeyDown(KeyCode.Z) == true)
        {
            if (MagCalState == MagCalibrationState.MagDisabled)
            {
                // Start calibration process
                if (MagAutoCalibrate == true)
                {
                    OVRDeviceImposter.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)
            {
                OVRDeviceImposter.SetMagReference(0);
                OVRDeviceImposter.EnableMagYawCorrection(0, true);

                Quaternion q = Quaternion.identity;
                if ((CameraController != null) && (CameraController.PredictionOn == true))
                {
                    OVRDeviceImposter.GetPredictedOrientation(0, ref q);
                }
                else
                {
                    OVRDeviceImposter.GetOrientation(0, ref q);
                }

                CurEulerRef = q.eulerAngles;

                // Begin manual calibration
                OVRDeviceImposter.BeginMagManualCalibration(0);
                MagCalState = MagCalibrationState.MagCalibrating;
            }
            else
            {
                // Reset calibration process
                if (MagAutoCalibrate == true)
                {
                    OVRDeviceImposter.StopMagAutoCalibration(0);
                }
                else
                {
                    OVRDeviceImposter.StopMagManualCalibration(0);
                }

                OVRDeviceImposter.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)
            {
                OVRDeviceImposter.UpdateMagAutoCalibration(0);
            }
            else
            {
                OVRDeviceImposter.UpdateMagManualCalibration(0);
            }

            if (OVRDeviceImposter.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)
            {
                OVRDeviceImposter.SetMagReference(0);
                OVRDeviceImposter.EnableMagYawCorrection(0, true);
                MagCalState = MagCalibrationState.MagReady;

                Quaternion q = Quaternion.identity;
                if ((CameraController != null) && (CameraController.PredictionOn == true))
                {
                    OVRDeviceImposter.GetPredictedOrientation(0, ref q);
                }
                else
                {
                    OVRDeviceImposter.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();
        }
    }