/// <summary> /// Warning, a lot of guesstimating happening right here!!! /// </summary> void Update() { if (HMDPlacementCanvas.gameObject.activeSelf == false) { return; } float lensCupSeparationInM; if (TobiiPro_Util.TryGetHmdLensCupSeparationInMeter(out lensCupSeparationInM) == false) { Debug.LogError("TobiiPro: Failed to get hmd lens cup separation."); } else { _lcs = lensCupSeparationInM; if (TobiiPro_Host.Instance.IsCalibrating == false && Time.frameCount % 45 == 0) { TobiiPro_Util.SetLensCupSeparation(_lcs); } } if (HMDPlacementCanvas != null && HMDPlacementCanvas.gameObject.activeSelf) { var hmdLcsInMM = _lcs * 1000f; var lHPos = new Vector3(-hmdLcsInMM, 0); var rHPos = new Vector3(hmdLcsInMM, 0); HMDPlacementCanvas.TargetLeft.localPosition = lHPos; HMDPlacementCanvas.TargetRight.localPosition = rHPos; var pupilL = SubscribingToHMDGazeData.SubscribingInstance.GetHMDEyeData().LeftEye.PupilPosition.PositionInTrackingArea; var pupilR = SubscribingToHMDGazeData.SubscribingInstance.GetHMDEyeData().RightEye.PupilPosition.PositionInTrackingArea; _leftPupilXY = new Vector2(pupilL.X, pupilL.Y); _rightPupilXY = new Vector2(pupilR.X, pupilR.Y); var pupilLeft = new Vector2( _leftPupilXY.x * _sizeOfparent.x, _leftPupilXY.y * _sizeOfparent.y * -1 ); var pupilRight = new Vector2( _rightPupilXY.x * _sizeOfparent.x, _rightPupilXY.y * _sizeOfparent.y * -1 ); if (Mathf.Abs(pupilLeft.y - pupilRight.y) < (0.15f * _sizeOfparent.y)) { pupilLeft.y = (pupilLeft.y + pupilRight.y) * 0.5f; pupilRight.y = pupilLeft.y; } HMDPlacementCanvas.LeftPupil.anchoredPosition = pupilLeft; HMDPlacementCanvas.RightPupil.anchoredPosition = pupilRight; // Coloring var c = new Vector2(0.5f, 0.5f); var distLeft = Vector2.Distance(c, _leftPupilXY); var distRight = Vector2.Distance(c, _rightPupilXY); HMDPlacementCanvas.LeftPupil.GetComponent <Image>().color = Color.Lerp(Color.green, Color.red, distLeft / 0.35f); HMDPlacementCanvas.RightPupil.GetComponent <Image>().color = Color.Lerp(Color.green, Color.red, distRight / 0.35f); // Info to the user HMDPlacementCanvas.Status.text = distLeft + distRight < 0.25f ? "Awesome!" : "OK"; } }
// <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; }