This section describes the typical workflow when using the C Binding API of the Interaction Library SDK.
Let's assume the eye tracker is on the main screen and that the resolution is 2560x1440 pixels.
We want to tell the Interaction Library about 4 regions on screen (A, B, C and D in the picture below) for which we want to know when the user looks at them (or not). As our gaze enters and leaves them, the Interaction Library will emit "got focus" and "lost focus" events that we can react to in our client application.
Such a screen region is called an interactor in the Interaction Library API.
In the following, error checking is omitted for readability (most API functions return an IL_Result value, where IL_Result_Ok is the generic "success" value).
Make sure that the compiler and linker can find the Interaction Library C Binding API headers and dynamic libraries, then include the main library header file:
To get a way of breaking out of the "update loop" (described further down), we track how many times the same interactor gets focus consecutively using a simple struct.
When we tell the Interaction Library (further down) that we want to get interactor focus events, we supply this callback function.
Create an instance of the Interaction Library implementation with IL_CreateInteractionLib(). Please note that the IL_Context created must be deleted using IL_DestroyInteractionLib().
Tell the Interaction Library our screen size with IL_CoordinateTransformAddOrUpdateDisplayArea() and which origo our interactor coordinates are relative to with IL_CoordinateTransformSetOriginOffset(). The latter is most useful if you want to use interactors with window local coordinates; simply update the offset as the window moves rather than all interactors.
Tell the Interaction Library where our interactors are located with IL_AddOrUpdateInteractor(). This must be done between matching calls to IL_BeginInteractorUpdates() and IL_CommitInteractorUpdates(), as changes will be handled in safe and optimized batches. An interactor is identified by a unique client supplied ID. Also, interactors can overlap each other and be stacked in z-order but we leave them all at 0 in this sample.
Tell the Interaction Library we want to get interactor focus events with IL_SubscribeGazeFocusEvents(). When our gaze enters and leaves the interactors, the callback function provided will be called by the Interaction Library and the event information is printed to standard output.
Tell the Interaction Library to continuously evaluate eye tracker gaze data and call any client event subscribers with IL_WaitAndUpdate(). In the event that no device is connected, IL_WaitAndUpdate() will attempt to find and connect to a tracker once per second. Since IL_WaitAndUpdate() will often block the calling thread, you would normally put this loop on its own thread. IL_WaitAndUpdate() is a convenience method that handles device connections, waiting for data and updating the Interaction Library to perform all calculation and trigger relevant callbacks all in one method. If you need granular control over updates and/or non-blocking calls use a suitable combination of the various other control methods available in the API.
Remember to clean up after us:
Finally: