private IEnumerable <GameObject> FindObjectsInGaze(IEnumerable <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)) { /*Note: Do not use LINQ here - too inefficient to be called every update.*/ foreach (var raycastHit in hitInfos) { objectsInGaze.Add(raycastHit.collider.gameObject); } } return(objectsInGaze); }
public FocusedObject GetFocusedObject(IEnumerable <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)); }
private IEnumerable <GameObject> FindObjectsInGaze(Vector2 gazePoint, Camera camera) { var objectsInGaze = new List <GameObject>(); float fovealAngle = 2.0f; float distanceGazeOriginToScreen_inches = 24f; // ~ 60 cm var dpi = Screen.dpi > 0 ? Screen.dpi : 100; float fovealRadius_inches = Mathf.Tan(fovealAngle * Mathf.Deg2Rad) * distanceGazeOriginToScreen_inches; int 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); }