void Update() { if (!Application.isPlaying) { return; } if (!VRMode.IsRunningInVRMode && !_IsOff) { if (!GazeManager.Instance.IsCalibrating) { // If running in 'remote' mode and not calibrating, we position eyes // and set size based on distance _EyesDistance = GazeFrameCache.Instance.GetLastUserPosition().Z; _DepthMod = (1 - _EyesDistance) * .25f; Vector3 scaleVec = new Vector3((float)(_DepthMod), (float)(_DepthMod), (float)_EyeBaseScale.z); Eye left = GazeFrameCache.Instance.GetLastLeftEye(); Eye right = GazeFrameCache.Instance.GetLastRightEye(); double angle = GazeFrameCache.Instance.GetLastEyesAngle(); if (null != left) { if (!left.Equals(_LastLeftEye)) { _LastLeftEye = left; if (!_LeftEye.IsRendererEnabled()) { _LeftEye.SetRendererEnabled(true); } //position GO based on screen coordinates Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(left.PupilCenterCoordinates); _LeftEye.SetWorldPositionFromGaze(_Camera, gp, _LeftEye.transform.localPosition.z); _LeftEye.transform.localScale = scaleVec * _EyeScaleInitSize; _LeftEye.transform.localEulerAngles = new Vector3(_LeftEye.transform.localEulerAngles.x, _LeftEye.transform.localEulerAngles.y, (float)-angle); } } else { if (_LeftEye.IsRendererEnabled()) { _LeftEye.SetRendererEnabled(false); } } if (null != right) { if (!right.Equals(_LastRightEye)) { _LastRightEye = right; if (!_RightEye.IsRendererEnabled()) { _RightEye.SetRendererEnabled(true); } //position GO based on screen coordinates Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(right.PupilCenterCoordinates); _RightEye.SetWorldPositionFromGaze(_Camera, gp, _RightEye.transform.localPosition.z); _RightEye.transform.localScale = scaleVec * _EyeScaleInitSize; _RightEye.transform.localEulerAngles = new Vector3(_RightEye.transform.localEulerAngles.x, _RightEye.transform.localEulerAngles.y, (float)-angle); } } else { if (_RightEye.IsRendererEnabled()) { _RightEye.SetRendererEnabled(false); } } } } else { if (_LeftEye.IsRendererEnabled()) { _LeftEye.SetRendererEnabled(false); } if (_RightEye.IsRendererEnabled()) { _RightEye.SetRendererEnabled(false); } } }
void Update() { if (!GazeManager.Instance.IsCalibrating) { //Set eyes size based on distance _EyesDistance = GazeDataValidator.Instance.GetLastValidUserPosition().Z; _DepthMod = (1 - _EyesDistance) * .25f; Vector3 scaleVec = new Vector3((float)(_DepthMod), (float)(_DepthMod), (float)_EyeBaseScale.z); Eye left = GazeDataValidator.Instance.GetLastValidLeftEye(); Eye right = GazeDataValidator.Instance.GetLastValidRightEye(); double angle = -GazeDataValidator.Instance.GetLastValidEyesAngle(); if (null != left) { if (!_LeftEye.GetComponent <Renderer>().enabled) { _LeftEye.GetComponent <Renderer>().enabled = true; } //position GO based on screen coordinates Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(left.PupilCenterCoordinates); PositionGOFromScreenCoords(_LeftEye, gp); _LeftEye.transform.localScale = scaleVec; _LeftEye.transform.eulerAngles = new Vector3(_LeftEye.transform.eulerAngles.x, _LeftEye.transform.eulerAngles.y, (float)angle); } else { if (_LeftEye.GetComponent <Renderer>().enabled) { _LeftEye.GetComponent <Renderer>().enabled = false; } } if (null != right) { if (!_RightEye.GetComponent <Renderer>().enabled) { _RightEye.GetComponent <Renderer>().enabled = true; } //position GO based on screen coordinates Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(right.PupilCenterCoordinates); PositionGOFromScreenCoords(_RightEye, gp); _RightEye.transform.localScale = scaleVec; _RightEye.transform.eulerAngles = new Vector3(_RightEye.transform.eulerAngles.x, _RightEye.transform.eulerAngles.y, (float)angle); } else { if (_RightEye.GetComponent <Renderer>().enabled) { _RightEye.GetComponent <Renderer>().enabled = false; } } } else { _LeftEye.GetComponent <Renderer>().enabled = false; _RightEye.GetComponent <Renderer>().enabled = false; } if (GazeManager.Instance.IsCalibrated) { if (!_GazeIndicator.GetComponent <Renderer>().enabled) { _GazeIndicator.GetComponent <Renderer>().enabled = true; } Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); if (null != gazeCoords) { // Map gaze indicator Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, _Camera.nearClipPlane + .1f); Vector3 planeCoord = _Camera.ScreenToWorldPoint(screenPoint); _GazeIndicator.transform.position = planeCoord; } } else { if (_GazeIndicator.GetComponent <Renderer>().enabled) { _GazeIndicator.GetComponent <Renderer>().enabled = false; } } lock (_CallbackQueue) { //we handle queued callback in the update loop while (_CallbackQueue.Count > 0) { _CallbackQueue.Dequeue()(); } } //handle keypress if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } }
void Update() { if (!Application.isPlaying) { return; } if (!VRMode.IsRunningInVRMode && !_IsOff) { if (!GazeManager.Instance.IsCalibrating) { // If running in 'remote' mode and not calibrating, we position eyes // and set size based on distance _EyesDistance = GazeFrameCache.Instance.GetLastUserPosition().Z; _DepthMod = (1 - _EyesDistance) * .25f; Vector3 scaleVec = new Vector3((float)(_DepthMod), (float)(_DepthMod), (float)_EyeBaseScale.z); Eye left = GazeFrameCache.Instance.GetLastLeftEye(); Eye right = GazeFrameCache.Instance.GetLastRightEye(); double angle = GazeFrameCache.Instance.GetLastEyesAngle(); if (null != left) { if (!left.Equals(_LastLeftEye)) { _LastLeftEye = left; if (!_LeftEye.IsRendererEnabled()) { _LeftEye.SetRendererEnabled(true); } //position GO based on screen coordinates Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(left.PupilCenterCoordinates); //////////////// // normalize coordinates to top right corner //float xMin = 0, xMax = Screen.width, yMin = 0, yMax = Screen.height; float xMin = 0, xMax = xScreen, yMin = 0, yMax = yScreen; float xOffset = xMax * (1 - _ResizeMultiplier), yOffset = yMax * (1 - _ResizeMultiplier); gp.X = (((gp.X - xMin) / (xMax - xMin)) * _ResizeMultiplier * xMax + xOffset); gp.Y = (((gp.Y - yMin) / (yMax - yMin)) * _ResizeMultiplier * yMax + yOffset) - yMax * (1 - _ResizeMultiplier); //////////////// _LeftEye.SetWorldPositionFromGaze(_Camera, gp, _LeftEye.transform.localPosition.z); _LeftEye.transform.localScale = scaleVec * _EyeScaleInitSize; _LeftEye.transform.localEulerAngles = new Vector3(_LeftEye.transform.localEulerAngles.x, _LeftEye.transform.localEulerAngles.y, (float)-angle); } } else { if (_LeftEye.IsRendererEnabled()) { _LeftEye.SetRendererEnabled(false); } } if (null != right) { if (!right.Equals(_LastRightEye)) { _LastRightEye = right; if (!_RightEye.IsRendererEnabled()) { _RightEye.SetRendererEnabled(true); } //position GO based on screen coordinates Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(right.PupilCenterCoordinates); //////////////// // normalize coordinates to top right corner //float xMin = 0, xMax = Screen.width, yMin = 0, yMax = Screen.height; float xMin = 0, xMax = xScreen, yMin = 0, yMax = yScreen; float xOffset = xMax * (1 - _ResizeMultiplier), yOffset = yMax * (1 - _ResizeMultiplier); gp.X = (((gp.X - xMin) / (xMax - xMin)) * _ResizeMultiplier * xMax + xOffset); gp.Y = (((gp.Y - yMin) / (yMax - yMin)) * _ResizeMultiplier * yMax + yOffset) - yMax * (1 - _ResizeMultiplier); //////////////// _RightEye.SetWorldPositionFromGaze(_Camera, gp, _RightEye.transform.localPosition.z); _RightEye.transform.localScale = scaleVec * _EyeScaleInitSize; _RightEye.transform.localEulerAngles = new Vector3(_RightEye.transform.localEulerAngles.x, _RightEye.transform.localEulerAngles.y, (float)-angle); } } else { if (_RightEye.IsRendererEnabled()) { _RightEye.SetRendererEnabled(false); } } } } else { if (_LeftEye.IsRendererEnabled()) { _LeftEye.SetRendererEnabled(false); } if (_RightEye.IsRendererEnabled()) { _RightEye.SetRendererEnabled(false); } } }