Home Forums Software Development [Unity5 EyeX] Raycast from gazepoint on perspective camera to vector3 worldspace Reply To: [Unity5 EyeX] Raycast from gazepoint on perspective camera to vector3 worldspace

#3532
Jenny [Tobii]
Participant

Hi Peter,

Yes, using the GazeAware component does not scale well. They’re kind of neat as a proof-of-concept and might work well in some specific game setting. But to do something proper with 3D interactors in Unity, we (as in Tobii) would need to a kind of source integration into the Unity 3D engine that is currently not possible (for more than one reason).

Using ray casts is a way to go around this. Since eye-tracking is not pixel perfect, you are going to have to do some work to get the gaze interaction experience right. You’ll have to re-create enough of the heuristics, filtering and snapping that is built-in to the GazeAware behavior. What is a good-enough approximation of the GazeAware behavior is context-dependent from game to game. (This is one of the reasons why we do not have sample code for ray casting.).

If you are using the Spotlight sample as a basis for your experiment, I think what you might want to change to make it work in the perspective view is this:
– Change from Camera.main.ScreenToWorldPoint to Camera.main.ScreenPointToRay
– From the Ray you get from the previous method, use the ray.origin and ray.direction as the first two parameters to Physics.RayCast. The resulting hit point will be in the RaycastHit out parameter.

Here some links to sample code and further explanation of the ScreenToWorldPoint in perspective view problem:
http://docs.unity3d.com/ScriptReference/Camera.ScreenPointToRay.html
http://docs.unity3d.com/ScriptReference/Physics.Raycast.html
http://answers.unity3d.com/questions/566519/camerascreentoworldpoint-in-perspective.html (The first part of the reply is applicable here).