Hi everyone,
We have just received our eye tracker and I am wondering where I can get C++ examples. Any help will be appreciated.
Thank you,
Uril.
MyGaze _mygaze
/** Add an IGazeListener to the GazeApi.
*
* \param[in] listener The IGazeListener listener to be added.
* \sa remove_listener(IGazeListener & listener).
*/
void add_listener(IGazeListener & listener);
/** A notification call back indicating that a new GazeData frame is available.
* Implementing classes should update themselves accordingly if needed.
* Register for updates through GazeApi::add_listener(IGazeListener & listener)
\param[in] gazeData Latest GazeData frame processed by Tracker Server
*/
virtual void on_gaze_data(gtl::GazeData const & gaze_data) = 0;
using namespace std;
// --- MyGaze definition
class MyGaze : public gtl::IGazeListener
{
public:
MyGaze();
~MyGaze();
private:
// IGazeListener
void on_gaze_data( gtl::GazeData const & gaze_data );
private:
gtl::GazeApi m_api;
};
// --- MyGaze implementation
MyGaze::MyGaze()
{
// Connect to the server in push mode on the default TCP port (6555)
if( m_api.connect( true ) )
{
// Enable GazeData notifications
m_api.add_listener( *this );
}
}
MyGaze::~MyGaze()
{
m_api.remove_listener( *this );
m_api.disconnect();
}
void MyGaze::on_gaze_data( gtl::GazeData const & gaze_data )
{
if( gaze_data.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
{
gtl::Point2D const & smoothedCoordinates = gaze_data.avg;
// Move GUI point, do hit-testing, log coordinates, etc.
cout << "x = " << smoothedCoordinates.x << " y = " << smoothedCoordinates.y << endl;
}
}
int main()
{
MyGaze test;
where (1)
{
here you also can write the output function e.g. cout << or printf, of course, under the precondition of predefined coordinates variable in your class
}
return 0;
}
void MyGaze::on_gaze_data( gtl::GazeData const & gaze_data )
{
if( gaze_data.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
{
gtl::Point2D const & smoothedCoordinatesLeftEye = gaze_data.lefteye.avg; // smoothed data from left eye
gtl::Point2D const & smoothedCoordinatesRightEye=gaze_data.righteye.avg; // smoothed data from right eye
LeftEyeX=smoothedCoordinatesLeftEye.x;
LeftEyeY=smoothedCoordinatesLeftEye.y;
RightEyeX=smoothedCoordinatesRightEye.x;
RightEyeY=smoothedCoordinatesRightEye.y;
// Move GUI point, do hit-testing, log coordinates, etc.
cout << "x = " << (LeftEyeX+ RightEyeX)/2<< " y = " << (LeftEyeY+RightEyeY)/2 << endl; //center values for left and right eyes, respectively.
}
}