Here’s what I did and as far as I can see it works.
I’ve use the Sample Scene of the Tobii SDK (TobiiXR for Unity package) and cut most of the code from the GazeVisualizer there. So take a look there is you want too!
This is the abbreviated bit of code:
public class EyeTrackOnScreen : MonoBehaviour
float _defaultDistance = 5f;
IEyeTrackingProvider provider = TobiiXR.Internal.Provider;
TobiiXR_EyeTrackingData eyeTrackingData = EyeTrackingDataHelper.Clone(provider.EyeTrackingDataLocal);
Matrix4x4 localToWorldMatrix = provider.LocalToWorldMatrix;
Vector3 worldForward = localToWorldMatrix.MultiplyVector(Vector3.forward);
TobiiXR_GazeRay gazeRay = eyeTrackingData.GazeRay;
Vector3 screenPosition = gazeRay.Origin + gazeRay.Direction.normalized * _defaultDistance;
float screenX = transform.localPosition.x + (Screen.width * 0.5);
float screenY = transform.localPosition.y + (Screen.height * 0.5);
Note: it is the Game screen that is calculated and so you have to take into account what size the game screen is at run time. If it’s full screen the gaze coordinates will conform to the resolution of your monitor. Is it running in a window, then the inner dimensions of that window will determine the max X and Y.
The screenPosition vector has its origin at the center of the screen.
The screenX and screenY are adjusted for the current Screen size.