I'm trying to calculate the point of convergence by using the gaze rays from the left and right eyes. This is what my script currently looks like:
Vector3 LeftGazeOrigin = LeftGazeOriginLocal + Camera.main.transform.position;
Vector3 RightGazeOrigin = RightGazeOriginLocal + Camera.main.transform.position;
Vector3 LeftGazeDir = Camera.main.transform.TransformDirection(LeftGazeDirLocal);
Vector3 RightGazeDir = Camera.main.transform.TransformDirection(RightGazeDirLocal);
// Create a gaze plane using three points:
// - The left gaze origin
// - The right gaze origin
// - The midpoint of the gaze origins + the combined (average) gaze
Vector3 CombinedGazeDir = (LeftGazeDir + RightGazeDir) / 2;
Vector3 MidpointGazeOrigin = (LeftGazeOrigin + RightGazeOrigin) / 2;
Vector3 ThirdPoint = MidpointGazeOrigin + CombinedGazeDir;
Plane GazePlane = new Plane(RightGazeOrigin, LeftGazeOrigin, ThirdPoint);
// Project gaze directions onto the gaze plane. We do this to ensure
// that the projected rays will intersect.
Vector3 ProjLeftGazeDir = Vector3.ProjectOnPlane(LeftGazeDir, GazePlane.normal);
Vector3 ProjRightGazeDir = Vector3.ProjectOnPlane(RightGazeDir, GazePlane.normal);
// Calculate the intersection of the projected left and right gaze
// rays. To do this, we create a plane orthogonal to the gaze plane which
// contains the left gaze ray. We then use Unity's `Raycast` function to find
// the intersection of this plane and the right gaze ray.
Vector3 LeftGazePlaneNormal = Vector3.Cross(GazePlane.normal, ProjLeftGazeDir);
Plane LeftGazePlane = new Plane(LeftGazePlaneNormal, LeftGazeOrigin);
Ray RightGazeRay = new Ray(RightGazeOrigin, ProjRightGazeDir);
float Enter = 0.0f;
if (LeftGazePlane.Raycast(RightGazeRay, out Enter))
Vector3 Intersection = RightGazeRay.GetPoint(Enter);
After this testing out this script on Unity, it seemed to be working. However, the calculated point of convergence seemed to vary considerably even during fixation. Because of this, I was wondering if anyone had suggestions to improve this script or if anyone had alternative approaches to calculate point of convergence.
A common alternative approach I've seen is to create a single combined gaze ray by averaging the left and right gaze origins and directions. The combined gaze ray would then be raycasted to find collisions with other game objects. However, I would prefer a solution which only uses data from the left and right eyes to find the point of convergence.