Hi Mingxin,
Thank you very much for your help.
I have tested your new method of using average of the right and the left eye and it works perfectly for me.
I work for the research.
Uril.
/****** MyGaze.h ******/
#ifndef _MY_GAZE_
#define _MY_GAZE_
#include <gazeapi.h>
#include <windows.h>
#include <iostream>
using namespace std;
class MyGaze : public gtl::IGazeListener
{
public:
MyGaze();
~MyGaze();
void on_gaze_data( gtl::GazeData const &gazeData );
private:
gtl::GazeApi mApi;
};
#endif
/******MyGaze.cpp******/
#include "MyGaze.h"
MyGaze::MyGaze()
{
// Connect to the server in push mode on the default TCP port (6555)
if( mApi.connect( true ) )
{
// Enable GazeData notifications
mApi.add_listener( *this );
if ( mApi.is_connected() )
{
printf("Connected!!\n");
// Set screen
gtl::Screen screen;
screen.set( 1, 1920, 1080, 0.5003, 0.2814 );
mApi.set_screen( screen );
}
}
}
MyGaze::~MyGaze()
{
mApi.remove_listener( *this );
mApi.disconnect();
}
void MyGaze::on_gaze_data( gtl::GazeData const & gazeData )
{
printf( "state = %d\n", gazeData.state );
if( gazeData.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
{
gtl::Point2D const & smoothedCoordinates = gazeData.avg;
// Move GUI point, do hit-testing, log coordinates, etc.
Sleep(1000);
gtl::Point2D const & smoothedCoordinatesLeftEye = gazeData.lefteye.avg; // smoothed data from left eye
gtl::Point2D const & smoothedCoordinatesRightEye=gazeData.righteye.avg; // smoothed data from right eye
//center values for left and right eyes, respectively.
cout << "x = " << (smoothedCoordinatesLeftEye.x+ smoothedCoordinatesRightEye.x)/2<< " y = " << (smoothedCoordinatesLeftEye.y+smoothedCoordinatesRightEye.y)/2 << endl;
printf( "\n" );
}
}
/****** Main.cpp ******/
#include <stdio.h>
#include "MyGaze.h"
int main()
{
MyGaze myGaze;
gtl::GazeData gazeData;
while (true)
{
Sleep(2000);
//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
printf( "\n-----------------------------------------------------\n" );
}
getchar();
return 0;
}