Home Forums Software Development Get Eye XYZ Position – cannot find the functions for TX_INTERACTIONBEHAVIORTYPE_ Reply To: Get Eye XYZ Position – cannot find the functions for TX_INTERACTIONBEHAVIORTYPE_

#1959
zhangmeng
Participant

the right code is like this:

BOOL InitializeGlobalInteractorSnapshot(TX_CONTEXTHANDLE hContext)
{
    TX_HANDLE hInteractor = TX_EMPTY_HANDLE;
    TX_GAZEPOINTDATAPARAMS params = { TX_GAZEPOINTDATAMODE_LIGHTLYFILTERED };
    TX_FIXATIONDATAPARAMS fixationDataParams = { TX_FIXATIONDATAMODE_SENSITIVE };
    TX_HANDLE hBehaviorWithoutParameters = TX_EMPTY_HANDLE;
    BOOL success;
 
    success = txCreateGlobalInteractorSnapshot(
        hContext,
        InteractorId,
        &g_hGlobalInteractorSnapshot,
        &hInteractor) == TX_RESULT_OK;
    success &= txCreateGazePointDataBehavior(hInteractor, &params) == TX_RESULT_OK;
 
    // add a second behavior to the same interactor: fixation data
    success &= txCreateFixationDataBehavior(hInteractor, &fixationDataParams) == TX_RESULT_OK;
 
    // add a third behavior to the same interactor: eye position data.
    // this one is a bit different because it doesn't take any parameters.
    // therefore we use the generic txCreateInteractorBehavior function (and remember to release the handle!)
    success &= txCreateInteractorBehavior(hInteractor, &hBehaviorWithoutParameters, TX_BEHAVIORTYPE_EYEPOSITIONDATA) == TX_RESULT_OK;
    txReleaseObject(&hBehaviorWithoutParameters);
 
    txReleaseObject(&hInteractor);
    return success;
}
and get data, the code is:
void OnGazeDataEvent(TX_HANDLE hGazeDataBehavior)
{
	//TX_GAZEPOINTDATAEVENTPARAMS eventParams;
	TX_EYEPOSITIONDATAEVENTPARAMS eventParams;
	//printf ("%d", txGetEyePositionDataEventParams(hGazeDataBehavior, &eventParams));
	//printf ("%d", TX_RESULT_OK);//TX_RESULT_INVALIDBEHAVIORTYPE
	//printf ("%d", TX_RESULT_INVALIDBEHAVIORTYPE);
	if (txGetEyePositionDataEventParams(hGazeDataBehavior, &eventParams) == TX_RESULT_OK) {
	//if (txGetGazePointDataEventParams(hGazeDataBehavior, &eventParams) == TX_RESULT_OK) {
		printf("Gaze Data: timestamp %d ms\n", eventParams.HasLeftEyePosition);
		//printf("Gaze Data: (%.1f, %.1f) timestamp %.0f ms\n", eventParams.X, eventParams.Y, eventParams.Timestamp);
	} else {
		printf("Failed to interpret gaze data event packet.\n");
		printf ("Error code: %d.\n", txGetEyePositionDataEventParams(hGazeDataBehavior, &eventParams));
	}
}
Next, there is a small detail you should not ignore:
if (txGetEventBehavior(hEvent, &hBehavior, TX_BEHAVIORTYPE_EYEPOSITIONDATA) == TX_RESULT_OK) {
		OnGazeDataEvent(hBehavior);
		txReleaseObject(&hBehavior);
	}

That is all, So the eye data can be got successfully.