Hi,
I have followed the above steps.
- Code: Select all
/****** 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;
}
I have some questions.
1. Why the state of gazeData always becomes 4,6,8 or 16 suddenly and never returns to 7( there is GD_STATE_TRACKING_GAZE = 1 << 0) ? When it happened, I have to run your UI or your C# sample simultaniously to do "recalibration" so that the console can output from value of coordinates again.
2. When my project is running, does it have any problem that your EyeTribe UI or C# sample runs as well?
3. Why the EyeTribe UI often stops suddenly? The figure of the eyes stays in the same place without moving ( the EyeTribe Server still connected ) and the values of coordinates are 0. I need to restart both of them and recalibrate the eye tribe.