public IEnumerator Calibrate(IEyeTracker eyeTracker)
    {
        // Create a calibration object.
        HMDBasedCalibration calibration = new HMDBasedCalibration(eyeTracker);

        // Enter calibration mode.
        calibration.EnterCalibrationMode();
        // Define the points in the HMD space we should calibrate at.
        Point3D[] pointsToCalibrate = new Point3D[] {
            new Point3D(9f, 9f, 20f),
            new Point3D(-9f, 9f, 20f),
            new Point3D(-9f, -9f, 20f),
            new Point3D(9f, -9f, 20f),
            new Point3D(0f, 0f, 20f),
        };
        // Collect data.
        foreach (Point3D point in pointsToCalibrate)
        {
            // Show an image on screen where you want to calibrate.
            Debug.Log("Show point in HMD space at ( " + point.X + " , " + point.Y + " , " + point.Z + " )");
            VRHeadsetDebugDisplay.Instance.SetText("Show point in HMD space at ( " + point.X + " , " + point.Y + " , " + point.Z + " )");
            DisplayImgAtPoint(new Vector3(point.X, point.Y, point.Z));
            // Wait a little for user to focus.
            yield return(new WaitForSeconds(5));

            // Collect data.
            CalibrationStatus status = calibration.CollectData(point);
            if (status != CalibrationStatus.Success)
            {
                // Try again if it didn't go well the first time.
                // Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
                calibration.CollectData(point);
                Debug.Log("Calibration point status : " + status);
            }
            VRHeadsetDebugDisplay.Instance.SetText("Ok, next!");
        }
        // Compute and apply the calibration.
        HMDCalibrationResult calibrationResult = calibration.ComputeAndApply();

        Debug.Log("Compute and apply returned : " + calibrationResult.Status);
        // See that you're happy with the result.
        // The calibration is done. Leave calibration mode.


        calibration.LeaveCalibrationMode();
        VRHeadsetDebugDisplay.Instance.SetText("All finished!");
    }
示例#2
0
        /// <summary>
        /// The thread function that calls the blocking calibration methods.
        /// </summary>
        private void ThreadFunction()
        {
            // Get the eye tracker
            var eyeTracker = VREyeTracker.Instance.EyeTrackerInterface;

            if (eyeTracker == null)
            {
                return;
            }

            Running = true;

            // Create the calibration object.
            var hmd = new HMDBasedCalibration(eyeTracker);

            // Find out how long the calls took using a stopwatch.
            var stopWatch = new System.Diagnostics.Stopwatch();

            // Handle the calibration commands.
            while (Running)
            {
                var currentResult = MethodResult.CurrentResult;
                stopWatch.Reset();
                stopWatch.Start();

                if (currentResult == null)
                {
                    Thread.Sleep(25);
                }
                else
                {
                    switch (currentResult.Command)
                    {
                    case MethodResult.CommandType.Invalid:
                        Thread.Sleep(25);
                        break;

                    case MethodResult.CommandType.Enter:
                        hmd.EnterCalibrationMode();
                        stopWatch.Stop();
                        currentResult.Finished(CalibrationStatus.Success, (int)stopWatch.ElapsedMilliseconds);
                        break;

                    case MethodResult.CommandType.Collect:
                        var collectResult = hmd.CollectData(MethodResult.CurrentPoint);
                        stopWatch.Stop();
                        currentResult.Finished(collectResult, (int)stopWatch.ElapsedMilliseconds);
                        break;

                    case MethodResult.CommandType.Compute:
                        var applyResult = hmd.ComputeAndApply();
                        stopWatch.Stop();
                        currentResult.Finished(applyResult.Status, (int)stopWatch.ElapsedMilliseconds);
                        break;

                    case MethodResult.CommandType.Leave:
                        hmd.LeaveCalibrationMode();
                        stopWatch.Stop();
                        currentResult.Finished(CalibrationStatus.Success, (int)stopWatch.ElapsedMilliseconds);
                        break;

                    default:
                        Thread.Sleep(25);
                        break;
                    }
                }
            }
        }
示例#3
0
        // <BeginExample>
        private IEnumerator Calibrate(Point3D[] calibrationPoints, GameObject target)
        {
            if (_eyeTracker == null)
            {
                yield break;
            }

            _eyeTracker.CalibrationModeEntered += EyeTracker_CalibrationModeEntered;
            _eyeTracker.CalibrationModeLeft    += EyeTracker_CalibrationModeLeft;

            // Create a calibration object.
            var calibration = new HMDBasedCalibration(_eyeTracker);

            // Enter calibration mode.
            calibration.EnterCalibrationMode();

            // Get and set the lens cup separation
            float hmdIpdInMeter;

            if (TobiiPro_Util.TryGetHmdLensCupSeparationInMeter(out hmdIpdInMeter) == false)
            {
                Debug.LogWarning("TobiiPro: Failed to get lens cup separation from HMD. Setting default lens cup separation.");
                hmdIpdInMeter = 0.0635f;
            }

            TobiiPro_Util.SetLensCupSeparation(hmdIpdInMeter);
            // Collect data.
            var index           = 0;
            var remainingPoints = true;

            while (remainingPoints)
            {
                // Play intro animation for the point
                _hasAnimated = false;
                WaitingOnIntroAnimation.Invoke(this, new IntroAnimationArgs(index));

                yield return(StartCoroutine(WaitingForAnimation()));

                var point = calibrationPoints[index];

                point = new Point3D(-point.X, point.Y, point.Z);

                // Show an image on screen where you want to calibrate.
                // target.transform.localPosition = new Vector3(-point.X, point.Y, point.Z) / 1000f;

                // Wait a little for user to focus.
                yield return(new WaitForSeconds(1.5f));


                // Collect data.
                CalibrationStatus status = calibration.CollectData(point);
                if (status != CalibrationStatus.Success)
                {
                    // Try again if it didn't go well the first time.
                    // Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
                    Debug.Log("TobiiPro: Calibration for this point wasn't success, try again.");
                    calibration.CollectData(point);
                }

                index++;

                // Outro animation for the point
                _hasAnimated = false;
                WaitingOnOutroAnimation.Invoke(this, null);
                yield return(StartCoroutine(WaitingForAnimation()));

                // Check if there are more points remaining
                if (index > calibrationPoints.Length - 1)
                {
                    remainingPoints = false;
                }
            }
            // Compute and apply the calibration.
            HMDCalibrationResult calibrationResult = calibration.ComputeAndApply();

            Debug.Log(string.Format("Compute and apply returned {0}.", calibrationResult.Status));
            // See that you're happy with the result.
            // The calibration is done. Leave calibration mode.

            OnCalibrationCompleted.Invoke(this, new CalibrationCompletedArgs(calibrationResult.Status));

            if (target != null)
            {
                Destroy(target);
            }

            _eyeTracker.CalibrationModeEntered -= EyeTracker_CalibrationModeEntered;
            calibration.LeaveCalibrationMode();

            _eyeTracker.CalibrationModeLeft -= EyeTracker_CalibrationModeLeft;
        }