Пример #1
0
        private IEnumerable <GameObject> FindObjectsInGaze(Vector2 gazePoint,
                                                           Camera camera)
        {
            var objectsInGaze = new List <GameObject>();
            var fovealAngle   = 2.0f;
            var distanceGazeOriginToScreen_inches = 24f; // ~ 60 cm
            var dpi = Screen.dpi > 0 ? Screen.dpi : 100;
            var fovealRadius_inches = Mathf.Tan(fovealAngle * Mathf.Deg2Rad) *
                                      distanceGazeOriginToScreen_inches;
            var fovealRadius_pixels =
                Mathf.RoundToInt(fovealRadius_inches * dpi);

            var points =
                PatternGenerator.CreateCircularAreaUniformPattern(gazePoint,
                                                                  fovealRadius_pixels, 4);
            IEnumerable <RaycastHit> hitInfos;

            if (HitTestFromPoint.FindMultipleObjectsInWorldFromMultiplePoints(
                    out hitInfos, points, camera,
                    MaximumDistance, LayerMask))
            {
                foreach (var raycastHit in hitInfos)
                {
                    objectsInGaze.Add(raycastHit.collider.gameObject);
                }
            }

            return(objectsInGaze);
        }
        private IEnumerable <GameObject> FindObjectsInGaze(
            IEnumerable <global::Tobii.Framework.GazePoint> gazePoints, Camera camera)
        {
            var points = new List <Vector2>();

            /*Note: Do not use LINQ here - too inefficient to be called every update.*/
            foreach (var gazePoint in gazePoints)
            {
                if (gazePoint.IsValid)
                {
                    points.Add(gazePoint.Screen);
                }
            }
            var objectsInGaze = new List <GameObject>();

            IEnumerable <RaycastHit> hitInfos;

            if (HitTestFromPoint.FindMultipleObjectsInWorldFromMultiplePoints(
                    out hitInfos, points, camera,
                    MaximumDistance, LayerMask))
            {
                foreach (var raycastHit in hitInfos)
                {
                    objectsInGaze.Add(raycastHit.collider.gameObject);
                }
            }

            return(objectsInGaze);
        }
Пример #3
0
        public FocusedObject GetFocusedObject(
            IEnumerable <global::Tobii.Framework.GazePoint> lastGazePoints, Camera camera)
        {
            var gazePoint = lastGazePoints.Last();

            if (!gazePoint.IsValid)
            {
                return(FocusedObject.Invalid);
            }

            GameObject focusedObject = null;
            RaycastHit hitInfo;

            if (HitTestFromPoint.FindObjectInWorld(out hitInfo,
                                                   gazePoint.Screen, camera, MaximumDistance, LayerMask))
            {
                if (GazeFocus.IsFocusableObject(hitInfo.collider.gameObject))
                {
                    focusedObject = hitInfo.collider.gameObject;
                }
            }

            return(new FocusedObject(focusedObject));
        }