public StreamEngineTracker(StreamEngineTracker_Description description = null, StreamEngineConnection connection = null)
        {
            if (description == null)
            {
                description = new StreamEngineTracker_Description();
            }

            if (connection == null)
            {
                connection = new StreamEngineConnection(new InteropWrapper());
            }

            LocalLatestData = new TobiiXR_EyeTrackingData();

            _connection = connection;

            if (TryConnectToTracker(_connection, _stopwatch, description) == false)
            {
                throw new Exception("Failed to connect to tracker");
            }

            _wearableDataCallback = OnWearableData;
            if (SubscribeToWearableData(_connection.Context.Device, _wearableDataCallback) == false)
            {
                throw new Exception("Failed to subscribe to tracker");
            }

            CheckForCapabilities(_connection.Context.Device);
        }
        public static TobiiXR_EyeTrackingData Clone(TobiiXR_EyeTrackingData data)
        {
            var result = new TobiiXR_EyeTrackingData();

            Copy(data, result);
            return(result);
        }
Ejemplo n.º 3
0
 public SnapdragonVRProvider()
 {
     #if TOBIIXR_SNAPDRAGONVRPROVIDER
     SvrManager.Instance.settings.trackEyes = true;
     EyeTrackingData = new TobiiXR_EyeTrackingData();
     #endif
 }
        public StreamEngineTracker(StreamEngineTracker_Description description = null, StreamEngineConnection connection = null)
        {
            if (description == null)
            {
                description = new StreamEngineTracker_Description();
            }

            if (connection == null)
            {
                connection = new StreamEngineConnection(new InteropWrapper());
            }

            LocalLatestData = new TobiiXR_EyeTrackingData();

            _connection = connection;

            if (TryConnectToTracker(_connection, _stopwatch, description) == false)
            {
                throw new Exception("Failed to connect to tracker");
            }

            _nativePointerToSelf = GCHandle.Alloc(this);
            if (SubscribeToWearableData(_connection.Context.Device, GCHandle.ToIntPtr(_nativePointerToSelf)) == false)
            {
                throw new Exception("Failed to subscribe to tracker");
            }

            CheckForCapabilities(_connection.Context.Device);
        }
        private void Update()
        {
            var provider        = TobiiXR.Internal.Provider;
            var eyeTrackingData = new TobiiXR_EyeTrackingData();

            provider.GetEyeTrackingDataLocal(eyeTrackingData);
            var localToWorldMatrix = provider.LocalToWorldMatrix;
            var worldForward       = localToWorldMatrix.MultiplyVector(Vector3.forward);

            EyeTrackingDataHelper.TransformGazeData(eyeTrackingData, localToWorldMatrix);
            var gazeModifierFilter = TobiiXR.Internal.Filter as GazeModifierFilter;

            if (gazeModifierFilter != null)
            {
                gazeModifierFilter.FilterAccuracyOnly(eyeTrackingData, worldForward);
            }

            var gazeRay = eyeTrackingData.GazeRay;

            _spriteRenderer.enabled = gazeRay.IsValid;
            if (_spriteRenderer.enabled == false)
            {
                return;
            }

            SetPositionAndScale(gazeRay);

            if (ScaleAffectedByPrecision && gazeModifierFilter != null)
            {
                UpdatePrecisionScale(gazeModifierFilter.GetMaxPrecisionAngleDegrees(eyeTrackingData.GazeRay.Direction, worldForward));
            }
        }
 public static void TransformGazeData(TobiiXR_EyeTrackingData eyeTrackingData, Matrix4x4 hmdOrigin)
 {
     if (eyeTrackingData.GazeRay.IsValid)
     {
         TransformToWorldSpace(ref eyeTrackingData.GazeRay, hmdOrigin);
     }
 }
        public void SetAllGazeRays(TobiiXR_EyeTrackingData data, Vector3 origin, Vector3 direction, bool isValid)
        {
            data.Timestamp = Time.unscaledTime;

            data.GazeRay.Origin    = origin;
            data.GazeRay.Direction = direction.normalized;
            data.GazeRay.IsValid   = isValid;
        }
Ejemplo n.º 8
0
 private static G2OM_DeviceData CreateDeviceData(TobiiXR_EyeTrackingData data)
 {
     return(new G2OM_DeviceData
     {
         timestamp = data.Timestamp,
         combined = new G2OM_GazeRay(new G2OM_Ray(data.GazeRay.Origin, data.GazeRay.Direction), data.GazeRay.IsValid),
     });
 }
 public static void TransformGazeData(TobiiXR_EyeTrackingData src, TobiiXR_EyeTrackingData dest, Matrix4x4 transformMatrix)
 {
     Copy(src, dest);
     if (src.GazeRay.IsValid)
     {
         dest.GazeRay.Origin    = transformMatrix.MultiplyPoint(src.GazeRay.Origin);
         dest.GazeRay.Direction = transformMatrix.MultiplyVector(src.GazeRay.Direction);
     }
 }
 public static void Copy(TobiiXR_EyeTrackingData src, TobiiXR_EyeTrackingData dest)
 {
     dest.Timestamp                  = src.Timestamp;
     dest.GazeRay                    = src.GazeRay;
     dest.ConvergenceDistance        = src.ConvergenceDistance;
     dest.ConvergenceDistanceIsValid = src.ConvergenceDistanceIsValid;
     dest.IsLeftEyeBlinking          = src.IsLeftEyeBlinking;
     dest.IsRightEyeBlinking         = src.IsRightEyeBlinking;
 }
Ejemplo n.º 11
0
        public bool Initialize(FieldOfUse fieldOfUse)
        {
            EyeTrackingDataLocal = new TobiiXR_EyeTrackingData();
            var result = Pvr_UnitySDKAPI.System.UPvr_setTrackingMode((int)Pvr_UnitySDKAPI.TrackingMode.PVR_TRACKING_MODE_POSITION | (int)Pvr_UnitySDKAPI.TrackingMode.PVR_TRACKING_MODE_EYE);

            if (!result)
            {
                Debug.LogWarning("Failed to enable eye tracking");
            }

            return(result);
        }
Ejemplo n.º 12
0
        private static G2OM_DeviceData CreateDeviceData(TobiiXR_EyeTrackingData data)
        {
            var leftEyeOpen  = data.Left.EyeOpennessIsValid ? data.Left.EyeOpenness > 0.5f : true;
            var rightEyeOpen = data.Right.EyeOpennessIsValid ? data.Right.EyeOpenness > 0.5f : true;

            return(new G2OM_DeviceData
            {
                timestamp = data.Timestamp,
                combined = new G2OM_GazeRay(new G2OM_Ray(data.CombinedRay.Origin, data.CombinedRay.Direction), data.CombinedRay.IsValid && leftEyeOpen && rightEyeOpen),
                leftEye = new G2OM_GazeRay(new G2OM_Ray(data.Left.Ray.Origin, data.Left.Ray.Direction), data.Left.Ray.IsValid && leftEyeOpen),
                rightEye = new G2OM_GazeRay(new G2OM_Ray(data.Right.Ray.Origin, data.Right.Ray.Direction), data.Right.Ray.IsValid && rightEyeOpen)
            });
        }
Ejemplo n.º 13
0
        private static void CopyEyeTrackingData(TobiiXR_EyeTrackingData latestDataLocalSpace, ref tobii_wearable_data_t data)
        {
            latestDataLocalSpace.CombinedRay.IsValid     = data.gaze_direction_combined_validity == tobii_validity_t.TOBII_VALIDITY_VALID && data.gaze_origin_combined_validity == tobii_validity_t.TOBII_VALIDITY_VALID;
            latestDataLocalSpace.CombinedRay.Origin.x    = data.gaze_origin_combined_mm_xyz.x * -1 / 1000f;
            latestDataLocalSpace.CombinedRay.Origin.y    = data.gaze_origin_combined_mm_xyz.y / 1000f;
            latestDataLocalSpace.CombinedRay.Origin.z    = data.gaze_origin_combined_mm_xyz.z / 1000f;
            latestDataLocalSpace.CombinedRay.Direction.x = data.gaze_direction_combined_normalized_xyz.x * -1;
            latestDataLocalSpace.CombinedRay.Direction.y = data.gaze_direction_combined_normalized_xyz.y;
            latestDataLocalSpace.CombinedRay.Direction.z = data.gaze_direction_combined_normalized_xyz.z;

            CopyIndividualEyeData(ref latestDataLocalSpace.Left, ref data.left);
            CopyIndividualEyeData(ref latestDataLocalSpace.Right, ref data.right);
        }
Ejemplo n.º 14
0
        private static G2OM_DeviceData CreateG2OMData(TobiiXR_EyeTrackingData data)
        {
            var t = Internal.Provider.LocalToWorldMatrix;

            return(new G2OM_DeviceData {
                timestamp = data.Timestamp,
                gaze_ray_world_space = new G2OM_GazeRay {
                    is_valid = data.GazeRay.IsValid.ToByte(),
                    ray = G2OM_UnityExtensionMethods.CreateRay(data.GazeRay.Origin, data.GazeRay.Direction),
                },
                camera_up_direction_world_space = t.MultiplyVector(Vector3.up).AsG2OMVector3(),
                camera_right_direction_world_space = t.MultiplyVector(Vector3.right).AsG2OMVector3()
            });
        }
 private static void TransformGazeData(TobiiXR_EyeTrackingData eyeTrackingData, Transform hmdOrigin)
 {
     if (eyeTrackingData.CombinedRay.IsValid)
     {
         TransformToWorldSpace(ref eyeTrackingData.CombinedRay, hmdOrigin);
     }
     if (eyeTrackingData.Left.Ray.IsValid)
     {
         TransformToWorldSpace(ref eyeTrackingData.Left.Ray, hmdOrigin);
     }
     if (eyeTrackingData.Right.Ray.IsValid)
     {
         TransformToWorldSpace(ref eyeTrackingData.Right.Ray, hmdOrigin);
     }
 }
Ejemplo n.º 16
0
        public StreamEngineTracker()
        {
            if (TryConnectToTracker(ref _streamEngineContext, _stopwatch) == false)
            {
                throw new Exception("Failed to connect to tracker");
            }

            _wearableDataCallback = OnWearableData;
            if (SubscribeToWearableData(_streamEngineContext.Device, _wearableDataCallback) == false)
            {
                throw new Exception("Failed to subscribe to tracker");
            }

            LocalLatestData = new TobiiXR_EyeTrackingData();
        }
Ejemplo n.º 17
0
        public static void FromAdvancedData(TobiiXR_EyeTrackingData to,
                                            ref tobii_wearable_advanced_data_t data, bool convergenceDistanceSupported, Vector3 headToCenterEyeTranslation)
        {
            FillGazeRayFrom(ref to.GazeRay, data.gaze_origin_combined_validity, data.gaze_origin_combined_mm_xyz, data.gaze_direction_combined_validity, data.gaze_direction_combined_normalized_xyz, headToCenterEyeTranslation);

            if (convergenceDistanceSupported)
            {
                to.ConvergenceDistance        = data.convergence_distance_mm / 1000f;
                to.ConvergenceDistanceIsValid = BoolFromValidity(data.convergence_distance_validity);
            }

            to.IsLeftEyeBlinking = data.left.blink == tobii_state_bool_t.TOBII_STATE_BOOL_TRUE ||
                                   !BoolFromValidity(data.left.blink_validity);
            to.IsRightEyeBlinking = data.right.blink == tobii_state_bool_t.TOBII_STATE_BOOL_TRUE ||
                                    !BoolFromValidity(data.right.blink_validity);
        }
        private static void CopyEyeTrackingData(TobiiXR_EyeTrackingData latestDataLocalSpace, ref tobii_wearable_consumer_data_t data)
        {
            latestDataLocalSpace.GazeRay.IsValid     = data.gaze_direction_combined_validity == tobii_validity_t.TOBII_VALIDITY_VALID && data.gaze_origin_combined_validity == tobii_validity_t.TOBII_VALIDITY_VALID;
            latestDataLocalSpace.GazeRay.Origin.x    = data.gaze_origin_combined_mm_xyz.x * -1 / 1000f;
            latestDataLocalSpace.GazeRay.Origin.y    = data.gaze_origin_combined_mm_xyz.y / 1000f;
            latestDataLocalSpace.GazeRay.Origin.z    = data.gaze_origin_combined_mm_xyz.z / 1000f;
            latestDataLocalSpace.GazeRay.Direction.x = data.gaze_direction_combined_normalized_xyz.x * -1;
            latestDataLocalSpace.GazeRay.Direction.y = data.gaze_direction_combined_normalized_xyz.y;
            latestDataLocalSpace.GazeRay.Direction.z = data.gaze_direction_combined_normalized_xyz.z;

            if (_convergenceDistanceSupported)
            {
                latestDataLocalSpace.ConvergenceDistance        = data.convergence_distance_mm / 1000f;
                latestDataLocalSpace.ConvergenceDistanceIsValid = data.convergence_distance_validity == tobii_validity_t.TOBII_VALIDITY_VALID;
            }

            latestDataLocalSpace.IsLeftEyeBlinking  = data.left.blink == tobii_state_bool_t.TOBII_STATE_BOOL_TRUE || data.left.blink_validity == tobii_validity_t.TOBII_VALIDITY_INVALID;
            latestDataLocalSpace.IsRightEyeBlinking = data.right.blink == tobii_state_bool_t.TOBII_STATE_BOOL_TRUE || data.right.blink_validity == tobii_validity_t.TOBII_VALIDITY_INVALID;
        }
        private static void CopyEyeTrackingData(TobiiXR_EyeTrackingData latestDataLocalSpace, ref tobii_wearable_data_t data)
        {
            latestDataLocalSpace.GazeRay.IsValid     = data.gaze_direction_combined_validity == tobii_validity_t.TOBII_VALIDITY_VALID && data.gaze_origin_combined_validity == tobii_validity_t.TOBII_VALIDITY_VALID;
            latestDataLocalSpace.GazeRay.Origin.x    = data.gaze_origin_combined_mm_xyz.x * -1 / 1000f;
            latestDataLocalSpace.GazeRay.Origin.y    = data.gaze_origin_combined_mm_xyz.y / 1000f;
            latestDataLocalSpace.GazeRay.Origin.z    = data.gaze_origin_combined_mm_xyz.z / 1000f;
            latestDataLocalSpace.GazeRay.Direction.x = data.gaze_direction_combined_normalized_xyz.x * -1;
            latestDataLocalSpace.GazeRay.Direction.y = data.gaze_direction_combined_normalized_xyz.y;
            latestDataLocalSpace.GazeRay.Direction.z = data.gaze_direction_combined_normalized_xyz.z;

            if (_convergenceDistanceSupported)
            {
                latestDataLocalSpace.ConvergenceDistance        = data.convergence_distance_mm / 1000f;
                latestDataLocalSpace.ConvergenceDistanceIsValid = data.convergence_distance_validity == tobii_validity_t.TOBII_VALIDITY_VALID;
            }
            else
            {
                if (data.left.gaze_direction_validity == tobii_validity_t.TOBII_VALIDITY_INVALID || data.right.gaze_direction_validity == tobii_validity_t.TOBII_VALIDITY_INVALID)
                {
                    latestDataLocalSpace.ConvergenceDistanceIsValid = false;
                }
                else
                {
                    var convergenceDistance_mm = Convergence.CalculateDistance(
                        data.left.gaze_origin_mm_xyz.ToVector3(),
                        data.left.gaze_direction_normalized_xyz.ToVector3(),
                        data.right.gaze_origin_mm_xyz.ToVector3(),
                        data.right.gaze_direction_normalized_xyz.ToVector3()
                        );
                    latestDataLocalSpace.ConvergenceDistance        = convergenceDistance_mm / 1000f;
                    latestDataLocalSpace.ConvergenceDistanceIsValid = true;
                }
            }

            latestDataLocalSpace.IsLeftEyeBlinking  = data.left.eye_openness_validity == tobii_validity_t.TOBII_VALIDITY_INVALID || Mathf.Approximately(data.left.eye_openness, 0f);
            latestDataLocalSpace.IsRightEyeBlinking = data.right.eye_openness_validity == tobii_validity_t.TOBII_VALIDITY_INVALID || Mathf.Approximately(data.right.eye_openness, 0f);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Applies filter to data parameter
 /// </summary>
 /// <param name="data">Eye tracking data that will be modified</param>
 /// <param name="forward">A unit direction vector pointing forward in the coordinate system used by the eye tracking data</param>
 public abstract void Filter(TobiiXR_EyeTrackingData data, Vector3 forward);
Ejemplo n.º 21
0
 public void GetEyeTrackingDataLocal(TobiiXR_EyeTrackingData data)
 {
     EyeTrackingDataHelper.Copy(_eyeTrackingDataLocal, data);
 }
 public static void TransformGazeData(TobiiXR_EyeTrackingData data, Matrix4x4 transformMatrix)
 {
     data.GazeRay.Origin    = transformMatrix.MultiplyPoint(data.GazeRay.Origin);
     data.GazeRay.Direction = transformMatrix.MultiplyVector(data.GazeRay.Direction);
 }