Eye Tracking, a cutting-edge feature exclusive to PICO 4 PRO. This innovative input method opens the door for developers to explore new dimensions within the realm of VR experiences.
In MicroWar, we use Eye Tracking to interact with the vehicle status UI.
To unlock the potential of Eye Tracking, follow these simple steps:
- Ensure Eye Tracking is activated on PXR_Manager.
- Attach the
EyeTrackingManager
component within your scene.
- To enable UI interaction with Eye Tracking, attach the
EyeTrackingArea
to the tank holders within theTankSelector
prefab.
If you wish to craft custom Eye Tracking interactions, create a new class inheriting from EyeTrackingObject
.
At the heart of Eye Tracking lies the EyeTrackingManager.cs
script. Here's a glimpse of its core functionality:
- Initialization: In the
Start()
method, the script checks if Eye Tracking is supported on the current device. - Data Retrieval: Crucial Eye Tracking data such as head pose matrix, combined eye gaze vector, and combined eye gaze origin are extracted.
- World Space Transformation: The retrieved eye gaze point and vector are translated to world space for accurate interactions.
- Interaction Detection: The script employs SphereCast to determine if the player's gaze is fixed upon a game object.
PXR_EyeTracking.GetHeadPosMatrix(out headPoseMatrix); bool isSuccess = PXR_EyeTracking.GetCombineEyeGazeVector(out combineEyeGazeVector); if (!isSuccess) return; PXR_EyeTracking.GetCombineEyeGazePoint(out combineEyeGazeOrigin); //Translate Eye Gaze point and vector to world space combineEyeGazeOrigin += combineEyeGazeOriginOffset; combineEyeGazeOriginInWorldSpace = originPoseMatrix.MultiplyPoint(headPoseMatrix.MultiplyPoint(combineEyeGazeOrigin)); combineEyeGazeVectorInWorldSpace = originPoseMatrix.MultiplyVector(headPoseMatrix.MultiplyVector(combineEyeGazeVector)); if (SpotLight != null) { SpotLight.transform.position = combineEyeGazeOriginInWorldSpace; SpotLight.transform.rotation = Quaternion.LookRotation(combineEyeGazeVectorInWorldSpace, Vector3.up); } GazeTargetControl(combineEyeGazeOriginInWorldSpace, combineEyeGazeVectorInWorldSpace);