コード例 #1
0
        public new void Enqueue(GazeData gd)
        {
            GazeData last;

            while (base.Count > 0 && null != (last = base.Peek()) && UnityGazeUtils.GetTimeDeltaNow(last) > TimeLimit)
            {
                base.Dequeue();
            }

            base.Enqueue(gd);
        }
コード例 #2
0
 private Vector3 GetGazeScreenPosition(Point2D gp)
 {
     if (null != gp)
     {
         Point2D sp = UnityGazeUtils.getGazeCoordsToUnityWindowCoords(gp);
         return(new Vector3((float)sp.X, (float)sp.Y, 0f));
     }
     else
     {
         return(Vector3.zero);
     }
 }
コード例 #3
0
        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.renderer.enabled)
                    {
                        _LeftEye.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.renderer.enabled)
                    {
                        _LeftEye.renderer.enabled = false;
                    }
                }

                if (null != right)
                {
                    if (!_RightEye.renderer.enabled)
                    {
                        _RightEye.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.renderer.enabled)
                    {
                        _RightEye.renderer.enabled = false;
                    }
                }
            }
            else
            {
                _LeftEye.renderer.enabled  = false;
                _RightEye.renderer.enabled = false;
            }

            if (GazeManager.Instance.IsCalibrated)
            {
                if (!_GazeIndicator.renderer.enabled)
                {
                    _GazeIndicator.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.renderer.enabled)
                {
                    _GazeIndicator.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();
            }
        }
コード例 #4
0
        public virtual void Update(GazeData frame)
        {
            _GazeFrameCache.Enqueue(frame);

            // update valid gazedata based on store
            Eye      right = null, left = null;
            Point2D  gazeCoords       = null;
            Point2D  gazeCoordsSmooth = null;
            Point2D  userPos          = null;
            double   userDist         = 0d;
            Point2D  eyeDistVecHalf   = null;
            GazeData gd;

            lock (_GazeFrameCache)
            {
                for (int i = _GazeFrameCache.Count; --i >= 0;)
                {
                    gd = _GazeFrameCache.ElementAt(i);

                    // if no tracking problems, then cache eye data
                    if ((gd.State & NO_TRACKING_MASK) == 0)
                    {
                        if (null == userPos &&
                            !gd.LeftEye.PupilCenterCoordinates.Equals(Point2D.zero) &&
                            !gd.RightEye.PupilCenterCoordinates.Equals(Point2D.zero))
                        {
                            userPos        = (gd.LeftEye.PupilCenterCoordinates + gd.RightEye.PupilCenterCoordinates) / 2;
                            eyeDistVecHalf = (gd.RightEye.PupilCenterCoordinates - gd.LeftEye.PupilCenterCoordinates) / 2;
                            userDist       = UnityGazeUtils.getDistancePoint2D(gd.LeftEye.PupilCenterCoordinates, gd.RightEye.PupilCenterCoordinates);

                            left  = gd.LeftEye;
                            right = gd.RightEye;
                        }
                        else if (null == userPos && left == null && !gd.LeftEye.PupilCenterCoordinates.Equals(Point2D.zero))
                        {
                            left = gd.LeftEye;
                        }
                        else if (null == userPos && right == null && !gd.RightEye.PupilCenterCoordinates.Equals(Point2D.zero))
                        {
                            right = gd.RightEye;
                        }

                        // if gaze coordinates available, cache both raw and smoothed
                        if (/*(gd.State & GazeData.STATE_TRACKING_GAZE) != 0 && */ null == gazeCoords && !gd.RawCoordinates.Equals(Point2D.zero))
                        {
                            gazeCoords       = gd.RawCoordinates;
                            gazeCoordsSmooth = gd.SmoothedCoordinates;
                        }
                    }

                    // break loop if valid values found
                    if (null != userPos && null != gazeCoords)
                    {
                        break;
                    }
                }

                if (null != gazeCoords)
                {
                    _LastValidRawGazeCoords      = gazeCoords;
                    _LastValidSmoothedGazeCoords = gazeCoordsSmooth;
                }

                if (null != eyeDistVecHalf)
                {
                    _LastValidEyesDistHalfVec = eyeDistVecHalf;
                }

                //Update user position values if needed data is valid
                if (null != userPos)
                {
                    _LastValidLeftEye  = left;
                    _LastValidRightEye = right;

                    //update 'depth' measure
                    if (userDist < _MinimumEyesDistance)
                    {
                        _MinimumEyesDistance = userDist;
                    }

                    if (userDist > _MaximumEyesDistance)
                    {
                        _MaximumEyesDistance = userDist;
                    }

                    //_LastValidEyeDistance = _LastValidEyeDistance / (_MaximumEyesDistance - _MinimumEyesDistance);
                    _LastValidEyeDistance = 1 - (userDist / _MaximumEyesDistance);

                    //update user position
                    _LastValidUserPosition = new Point3D(userPos.X, userPos.Y, _LastValidEyeDistance);

                    //map to normalized 3D space
                    _LastValidUserPosition.X = (_LastValidUserPosition.X * 2) - 1;
                    _LastValidUserPosition.Y = (_LastValidUserPosition.Y * 2) - 1;

                    //update angle
                    _LastValidEyeAngle = ((180 / Math.PI * Math.Atan2(_LastValidRightEye.PupilCenterCoordinates.Y - _LastValidLeftEye.PupilCenterCoordinates.Y,
                                                                      _LastValidRightEye.PupilCenterCoordinates.X - _LastValidLeftEye.PupilCenterCoordinates.X)));
                }
                else if (null != left)
                {
                    _LastValidLeftEye  = left;
                    _LastValidRightEye = null;
                    Point2D newPos = _LastValidLeftEye.PupilCenterCoordinates + _LastValidEyesDistHalfVec;
                    _LastValidUserPosition = new Point3D(newPos.X, newPos.Y, _LastValidEyeDistance);

                    //map to normalized 3D space
                    _LastValidUserPosition.X = (_LastValidUserPosition.X * 2) - 1;
                    _LastValidUserPosition.Y = (_LastValidUserPosition.Y * 2) - 1;
                }
                else if (null != right)
                {
                    _LastValidRightEye = right;
                    _LastValidLeftEye  = null;
                    Point2D newPos = _LastValidRightEye.PupilCenterCoordinates - _LastValidEyesDistHalfVec;
                    _LastValidUserPosition = new Point3D(newPos.X, newPos.Y, _LastValidEyeDistance);

                    //map to normalized 3D space
                    _LastValidUserPosition.X = (_LastValidUserPosition.X * 2) - 1;
                    _LastValidUserPosition.Y = (_LastValidUserPosition.Y * 2) - 1;
                }
                else
                {
                    _LastValidRightEye = null;
                    _LastValidLeftEye  = null;
                }
            }
        }