Jump to content

How to detect objects that are being focused


Recommended Posts

Hi,

I have been trying to track what object that a person is looking at by using focus function. But I still don't get it. I don't understand what enableDataCallback mean. Could anyone give me a hand ? how do I know whether it is activated or not ?. It is a bit difficult to follow the example for checking focus. What should I do to fix this code please ?

I tried to call this function from update function of UNITY. Yet, it only printed :

Debug.Log("Hit Collider Inside CheckFocus");

and

Debug.Log("Hit Collider inside foreach");

It seems that it never get into  if (eye_callback_registered)

I would like to get the information (name of game object that a person is looking at).

Thanks a lot for your help

===================

I declare the following variables as global

private static EyeData eyeData = new EyeData();

private bool eye_callback_registered = false;
private readonly GazeIndex[] GazePriority = new GazeIndex[] { GazeIndex.COMBINE, GazeIndex.LEFT, GazeIndex.RIGHT };
public void CheckFocus()
    {

        if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
        {
            SRanipal_Eye.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye.CallbackBasic)EyeCallback));
            eye_callback_registered = true;
        }
        else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
        {
            SRanipal_Eye.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye.CallbackBasic)EyeCallback));
            eye_callback_registered = false;
        }


        Debug.Log("Hit Collider Inside CheckFocus");

        foreach (GazeIndex index in GazePriority)
        {
            Debug.Log("Hit Collider inside foreach");

            Ray GazeRay;
            bool eye_focus;
            if (eye_callback_registered)
            {
                eye_focus = SRanipal_Eye.Focus(index, out GazeRay, out focusInfo);
                if (eye_focus)
                {
                    Debug.Log("Hit Collider inside EyeFocus");
                    Debug.Log(focusInfo);
                    Debug.Log(GazeRay);
                }
                else
                {
                    Debug.Log(eye_focus);
                }
            }



private static void EyeCallback(ref EyeData eye_data)
    {
        eyeData = eye_data;
    }


            

Link to comment
Share on other sites

@Ihshan Gumilar Please see my response here for help using the Focus api: 

Note that the callback runs on a separate thread than the Unity main thread to get eye tracking data faster than the framerate. Unity is not thread safe and you cannot call the Unity api from a separate thread (ex. you cannot call "UnityEngine.Debug.Log" within EyeCallback).

https://support.unity.com/hc/en-us/articles/208707516-Why-should-I-use-Threads-instead-of-Coroutines-#

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...