/// <summary> /// Update the spatial grip input from the device. /// </summary> /// <param name="interactionSourceState">The InteractionSourceState retrieved from the platform.</param> /// <param name="interactionMapping"></param> private void UpdateGripData(InteractionSourceState interactionSourceState, MixedRealityInteractionMapping interactionMapping) { switch (interactionMapping.AxisType) { case AxisType.SixDof: { interactionSourceState.sourcePose.TryGetPosition(out currentGripPosition, InteractionSourceNode.Grip); interactionSourceState.sourcePose.TryGetRotation(out currentGripRotation, InteractionSourceNode.Grip); currentGripPose.Position = MixedRealityPlayspace.TransformPoint(currentGripPosition); currentGripPose.Rotation = Quaternion.Euler(MixedRealityPlayspace.TransformDirection(currentGripRotation.eulerAngles)); // Update the interaction data source interactionMapping.PoseData = currentGripPose; // If our value changed raise it. if (interactionMapping.Changed) { // Raise input system Event if it enabled InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, currentGripPose); } } break; } }
/// <inheritdoc /> public override void Update() { using (UpdatePerfMarker.Auto()) { if (WindowsMixedRealityUtilities.SpatialCoordinateSystem == null || !eyesApiAvailable) { return; } SpatialPointerPose pointerPose = SpatialPointerPose.TryGetAtTimestamp(WindowsMixedRealityUtilities.SpatialCoordinateSystem, PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now)); if (pointerPose != null) { var eyes = pointerPose.Eyes; if (eyes != null) { Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, eyes.IsCalibrationValid); if (eyes.Gaze.HasValue) { Vector3 origin = MixedRealityPlayspace.TransformPoint(eyes.Gaze.Value.Origin.ToUnityVector3()); Vector3 direction = MixedRealityPlayspace.TransformDirection(eyes.Gaze.Value.Direction.ToUnityVector3()); Ray newGaze = new Ray(origin, direction); if (SmoothEyeTracking) { newGaze = SmoothGaze(newGaze); } Service?.EyeGazeProvider?.UpdateEyeGaze(this, newGaze, eyes.UpdateTimestamp.TargetTime.UtcDateTime); } } } } }
/// <inheritdoc /> public override void Update() { using (UpdatePerfMarker.Auto()) { if (!eyeTrackingDevice.isValid) { InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.EyeTracking, InputDeviceList); if (InputDeviceList.Count > 0) { eyeTrackingDevice = InputDeviceList[0]; } if (!eyeTrackingDevice.isValid) { Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, false); return; } } #if UNITY_OPENXR if (eyeTrackingDevice.TryGetFeatureValue(CommonUsages.isTracked, out bool gazeAvailable)) { Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, gazeAvailable); if (gazeAvailable && eyeTrackingDevice.TryGetFeatureValue(EyeTrackingUsages.gazePosition, out Vector3 eyeGazePosition) && eyeTrackingDevice.TryGetFeatureValue(EyeTrackingUsages.gazeRotation, out Quaternion eyeGazeRotation)) { Vector3 worldPosition = MixedRealityPlayspace.TransformPoint(eyeGazePosition); Vector3 worldRotation = MixedRealityPlayspace.TransformDirection(eyeGazeRotation * Vector3.forward); Ray newGaze = new Ray(worldPosition, worldRotation); if (SmoothEyeTracking) { newGaze = SmoothGaze(newGaze); } Service?.EyeGazeProvider?.UpdateEyeGaze(this, newGaze, DateTime.UtcNow); } } else { Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, false); } #endif // UNITY_OPENXR } }
/// <inheritdoc /> public override void Update() { #if PLATFORM_LUMIN using (UpdatePerfMarker.Auto()) { if (!eyeTrackingDevice.isValid) { InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.EyeTracking, InputDeviceList); if (InputDeviceList.Count > 0) { eyeTrackingDevice = InputDeviceList[0]; } if (!eyeTrackingDevice.isValid) { Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, false); return; } Debug.Log("Eye Calibration status: " + MLEyes.CalibrationStatus + ". This value may be incorrect when using Zero Iteration."); } if (MLEyes.IsStarted && (int)MLEyes.CalibrationStatus > 1) { Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, true); Vector3 worldPosition = CameraCache.Main.transform.position; Vector3 worldRotation = MixedRealityPlayspace.TransformDirection((MLEyes.FixationPoint - worldPosition).normalized); Ray newGaze = new Ray(worldPosition, worldRotation); if (SmoothEyeTracking) { newGaze = SmoothGaze(newGaze); } Service?.EyeGazeProvider?.UpdateEyeGaze(this, newGaze, DateTime.UtcNow); } else { Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, false); } } #endif }
/// <summary> /// Compute the world direction corresponding to the input local direction in playspace. /// </summary> /// <param name="localDirection">The local direction.</param> /// <returns>The world direction.</returns> public static Vector3 DirectionRelativeToPlayspace(Vector3 localDirection) { return(MixedRealityPlayspace.TransformDirection(localDirection)); }