Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void Tick(G2OM_DeviceData deviceData)
        {
            _deviceData = deviceData;
            var now = _deviceData.timestamp;

            // Get, add and remove candidates
            _objectFinder.GetRelevantGazeObjects(ref _deviceData, _newCandidates, _distinguisher);

            AddNewCandidates(now, _internalCandidates, _newCandidates);

            RemoveOldCandidates(now, _internalCandidates, MaxHistoryInSeconds, _keysToRemove, _internalCapacity);

            // Ensure capacity is enough
            if (_internalCandidates.Count > _nativeCandidates.Length)
            {
                _nativeCandidates       = new G2OM_Candidate[_internalCandidates.Count];
                _nativeCandidatesResult = new G2OM_CandidateResult[_internalCandidates.Count];
            }

            // Prepare structs to be sent to G2OM
            _colliderDataProvider.GetColliderData(_internalCandidates, _nativeCandidates);

            var raycastResult = _objectFinder.GetRaycastResult(ref _deviceData, _distinguisher);

            _context.Process(ref _deviceData, ref raycastResult, _internalCandidates.Count, _nativeCandidates, _nativeCandidatesResult); // TODO: What to do if this call fails??

            // Process the result from G2OM
            UpdateListOfFocusedCandidates(_nativeCandidatesResult, _internalCandidates, _gazeFocusedObjects);

            _postTicker.TickComplete(_gazeFocusedObjects);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private static void CreateMutatedRays(ref G2OM_DeviceData deviceData, int numberOfRays, IList <RawRay> rays)
        {
            rays.Clear();

            if (deviceData.combined.IsValid)
            {
                rays.Add(new RawRay(ref deviceData.combined.ray));
            }

            if (deviceData.leftEye.IsValid)
            {
                rays.Add(new RawRay(ref deviceData.leftEye.ray));
            }

            if (deviceData.rightEye.IsValid)
            {
                rays.Add(new RawRay(ref deviceData.rightEye.ray));
            }

            if (rays.Count == 0)
            {
                return;                  // If we don't have any source rays to mutate, early return
            }
            var numberOfInitialRays = rays.Count;
            var rayIndex            = numberOfInitialRays;
            var indexOffset         = Random.Range(0, Rotations.Length);

            while (rayIndex < numberOfRays)
            {
                for (int i = 0; i < numberOfInitialRays && i + rayIndex < numberOfRays; i++)
                {
                    var sourceRay        = rays[i];
                    var randomRotation   = Rotations[(rayIndex + indexOffset) % Rotations.Length];
                    var mutatedDirection = randomRotation * sourceRay.direction;
                    rays.Add(new RawRay {
                        origin = sourceRay.origin, direction = mutatedDirection
                    });
                }

                rayIndex += numberOfInitialRays;
            }

#if UNITY_EDITOR
            for (int i = 0; i < numberOfInitialRays; i++)
            {
                Debug.DrawRay(rays[i].origin, rays[i].direction * 100, Color.red);
            }

            for (int i = numberOfInitialRays; i < numberOfRays; i++)
            {
                Debug.DrawRay(rays[i].origin, rays[i].direction * 100, Color.green);
            }
#endif
        }
        public bool Process(ref G2OM_DeviceData deviceData, ref G2OM_RaycastResult raycastResult, int candidateCount, G2OM_Candidate[] candidates, G2OM_CandidateResult[] candidateResults)
        {
            var result = Interop.G2OM_Process(_context, ref deviceData, ref raycastResult, (uint)candidateCount, candidates, candidateResults);

            if (result == G2OM_Error.Ok)
            {
                return(true);
            }

            Debug.LogError("Failed to process G2OM. Error code " + result);
            return(false);
        }
Exemplo n.º 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);
        }
Exemplo n.º 7
0
        private static void DrawDebugRays(ref G2OM_DeviceData deviceData, G2OM_GazeRay[] rays, int numberOfRaysThisFrame)
        {
            if (rays.Length <= 0)
            {
                return;
            }
            if (rays[0].is_valid.ToBool() == false)
            {
                return;
            }

            Debug.DrawRay(rays[0].ray.origin.Vector(), rays[0].ray.direction.Vector() * 100, Color.red);

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

                Debug.DrawRay(rays[i].ray.origin.Vector(), rays[i].ray.direction.Vector() * 100, Color.green);
            }
        }
Exemplo n.º 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);
        }
        private static void DrawDebugRays(ref G2OM_DeviceData deviceData, G2OM_Ray[] rays, int numberOfRaysThisFrame)
        {
            var numberOfInitialRays = 0;

            if (deviceData.combined.IsValid)
            {
                numberOfInitialRays++;
            }

            for (int i = 0; i < numberOfInitialRays; i++)
            {
                Debug.DrawRay(rays[i].origin.Vector, rays[i].direction.Vector * 100, Color.red);
            }

            for (int i = numberOfInitialRays; i < numberOfRaysThisFrame; i++)
            {
                if (rays[i].direction.Vector.sqrMagnitude == 0)
                {
                    break;
                }

                Debug.DrawRay(rays[i].origin.Vector, rays[i].direction.Vector * 100, Color.green);
            }
        }
 public static extern G2OM_Error G2OM_GetCandidateSearchPattern(IntPtr context, ref G2OM_DeviceData deviceData, uint numberOfRays, G2OM_GazeRay[] mutatedRays);
 public static extern G2OM_Error G2OM_Process(IntPtr context, ref G2OM_DeviceData deviceData, ref G2OM_RaycastResult raycastResult, uint candidatesCount, G2OM_Candidate[] candidates, G2OM_CandidateResult[] candidateResults);
 public G2OM_Error GetCandidateSearchPattern(ref G2OM_DeviceData deviceData, G2OM_Ray[] rays)
 {
     return(Interop.G2OM_GetCandidateSearchPattern(_context, ref _up, ref _right, ref deviceData, (uint)rays.Length, rays));
 }
 public static extern G2OM_Error G2OM_GetCandidateSearchPattern(IntPtr context, ref G2OM_Vector3 worldSpaceUpDirection, ref G2OM_Vector3 worldSpaceRightDirection, ref G2OM_DeviceData deviceData, uint numberOfRays, G2OM_Ray[] mutatedRays);