示例#1
0
        private G2OM(G2OM_Description description)
        {
            var expectedNumberOfCandidates = description.ExpectedNumberOfObjects;

            _context = description.Context;
            _context.Setup(expectedNumberOfCandidates); // TODO: What if this fails???

            _howLongToKeepCandidatesInMemory = description.HowLongToKeepCandidatesInSeconds;

            _objectFinder = description.ObjectFinder;
            _objectFinder.SetLayerMask(description.LayerMask);

            _colliderDataProvider = description.ColliderDataProvider;
            _objectDistinguisher  = description.Distinguisher;
            _postTicker           = description.PostTicker;

            _newCandidates      = new Dictionary <int, GameObject>(expectedNumberOfCandidates);
            _internalCandidates = new Dictionary <int, InternalCandidate>(expectedNumberOfCandidates);

            _gazeFocusedObjects = new List <FocusedCandidate>(expectedNumberOfCandidates);
            _keysToRemove       = new List <int>(expectedNumberOfCandidates);

            _nativeCandidates       = new G2OM_Candidate[expectedNumberOfCandidates];
            _nativeCandidatesResult = new G2OM_CandidateResult[expectedNumberOfCandidates];
        }
示例#2
0
        private static void FindObjects(G2OM_GazeRay[] rays,
                                        Dictionary <int, GameObject> foundObjects,
                                        IG2OM_ObjectDistinguisher distinguisher,
                                        LayerMask layerMask,
                                        int numberOfRaysThisFrame)
        {
            foundObjects.Clear();

            for (int i = 0; i < numberOfRaysThisFrame; i++)
            {
                if (rays[i].is_valid.ToBool() == false)
                {
                    break;
                }

                GameObject go;
                if (FindGameObject(ref rays[i].ray, layerMask, out go) == false)
                {
                    continue;
                }

                var id = go.GetInstanceID();
                if (foundObjects.ContainsKey(id))
                {
                    continue;
                }

                if (distinguisher.IsGameObjectGazeFocusable(id, go) == false)
                {
                    continue;
                }

                foundObjects.Add(id, go);
            }
        }
示例#3
0
        // TODO: Is it possible to remove the redudant raycasts?
        public G2OM_RaycastResult GetRaycastResult(ref G2OM_DeviceData deviceData,
                                                   IG2OM_ObjectDistinguisher distinguisher)
        {
            var raycastResult = new G2OM_RaycastResult();

            GameObject go;
            var        result = FindGameObject(ref deviceData.combined, _layerMask, out go);

            if (result)
            {
                var id            = go.GetInstanceID();
                var hitACandidate = distinguisher.IsGameObjectGazeFocusable(id, go);
                raycastResult.combined = new G2OM_Raycast(hitACandidate, id);
            }

            result = FindGameObject(ref deviceData.leftEye, _layerMask, out go);
            if (result)
            {
                var id            = go.GetInstanceID();
                var hitACandidate = distinguisher.IsGameObjectGazeFocusable(id, go);
                raycastResult.left = new G2OM_Raycast(hitACandidate, id);
            }

            result = FindGameObject(ref deviceData.rightEye, _layerMask, out go);
            if (result)
            {
                var id            = go.GetInstanceID();
                var hitACandidate = distinguisher.IsGameObjectGazeFocusable(id, go);
                raycastResult.right = new G2OM_Raycast(hitACandidate, id);
            }

            return(raycastResult);
        }
示例#4
0
        private static void FindObjects(List <RawRay> rays, Dictionary <int, GameObject> foundObjects,
                                        IG2OM_ObjectDistinguisher distinguisher, LayerMask layerMask)
        {
            foundObjects.Clear();

            foreach (var ray in rays)
            {
                GameObject go;
                if (FindGameObject(ray, layerMask, out go) == false)
                {
                    continue;
                }

                var id = go.GetInstanceID();
                if (foundObjects.ContainsKey(id))
                {
                    continue;
                }

                if (distinguisher.IsGameObjectGazeFocusable(id, go) == false)
                {
                    continue;
                }

                foundObjects.Add(id, go);
            }
        }
示例#5
0
        public void GetRelevantGazeObjects(ref G2OM_DeviceData deviceData, Dictionary <int, GameObject> foundObjects,
                                           IG2OM_ObjectDistinguisher distinguisher)
        {
            var numberOfRaysThisFrame = GetNumberOfRays(deviceData.timestamp - _previousTimestamp);

            _previousTimestamp = deviceData.timestamp;

            CreateMutatedRays(ref deviceData, numberOfRaysThisFrame, _rays);

            FindObjects(_rays, foundObjects, distinguisher, _layerMask);
        }
示例#6
0
        // TODO: Is it possible to remove the redudant raycasts?
        public G2OM_RaycastResult GetRaycastResult(
            ref G2OM_DeviceData deviceData,
            IG2OM_ObjectDistinguisher distinguisher)
        {
            var raycastResult = new G2OM_RaycastResult();

            GameObject go;
            var        result = FindGameObject(ref deviceData.gaze_ray_world_space.ray, _layerMask, out go);

            if (result)
            {
                var id            = go.GetInstanceID();
                var hitACandidate = distinguisher.IsGameObjectGazeFocusable(id, go);
                raycastResult.gaze_ray = new G2OM_Raycast
                {
                    candidate_id        = (ulong)id,
                    is_raycast_id_valid = hitACandidate.ToByte()
                };
            }

            return(raycastResult);
        }
示例#7
0
        private G2OM(G2OM_Description description)
        {
            _internalCapacity = (int)description.Options.capacity;
            _howLongToKeepCandidatesInMemory = description.HowLongToKeepCandidatesInSeconds;

            _context = description.Context;
            _context.Setup(description.Options);

            _objectFinder = description.ObjectFinder;
            _objectFinder.Setup(_context, description.LayerMask);

            _colliderDataProvider = description.ColliderDataProvider;
            _distinguisher        = description.Distinguisher;
            _postTicker           = description.PostTicker;

            _newCandidates      = new Dictionary <int, GameObject>(_internalCapacity);
            _internalCandidates = new Dictionary <int, InternalCandidate>(_internalCapacity);

            _gazeFocusedObjects = new List <FocusedCandidate>(_internalCapacity);
            _keysToRemove       = new List <int>(_internalCapacity);

            _nativeCandidates       = new G2OM_Candidate[_internalCapacity];
            _nativeCandidatesResult = new G2OM_CandidateResult[_internalCapacity];
        }
示例#8
0
        public void GetRelevantGazeObjects(ref G2OM_DeviceData deviceData, Dictionary <int, GameObject> foundObjects, IG2OM_ObjectDistinguisher distinguisher)
        {
            var result = _context.GetCandidateSearchPattern(ref deviceData, _rays);

            if (result != G2OM_Error.Ok)
            {
                Debug.LogError("GetCandidateSearchPattern failed with error: " + result);
                return;
            }

            var numberOfRaysThisFrame = GetNumberOfRays(deviceData.timestamp - _previousTimestamp);

            _previousTimestamp = deviceData.timestamp;

#if UNITY_EDITOR
            if (ShouldDrawDebugRays)
            {
                DrawDebugRays(ref deviceData, _rays, numberOfRaysThisFrame);
            }
#endif

            FindObjects(_rays, foundObjects, distinguisher, _layerMask, numberOfRaysThisFrame);
        }
示例#9
0
        public void GetRelevantGazeObjects(ref G2OM_DeviceData deviceData, Dictionary <int, GameObject> foundObjects, IG2OM_ObjectDistinguisher distinguisher)
        {
            foundObjects.Clear();

            foreach (var registeredObject in G2OM_ObjectRegistry.Registry)
            {
                foundObjects.Add(registeredObject.Key, registeredObject.Value);
            }
        }