Tobii Pro SDK C API
hmd_calibration.c
#include <stdio.h>
#if _WIN32 || _WIN64
#include <windows.h>
static void sleep_ms(int time) {
Sleep(time);
}
#else
#include <unistd.h>
static void sleep_ms(int time) {
usleep(time * 1000);
}
#endif
void hmd_calibration_example(TobiiResearchEyeTracker* eyetracker) {
/* Enter calibration mode. */
char* serial_number;
tobii_research_get_serial_number(eyetracker, &serial_number);
printf("Entered calibration mode for eye tracker with serial number %s \n.", serial_number);
/* Define the points we should calibrate at. */
/* The coordinates are in HMD coordinates (x,y,z) */
{
#define NUM_OF_POINTS 3U
TobiiResearchPoint3D points_to_calibrate[NUM_OF_POINTS] = \
{{0.0f, 0.0f, 1000.0f}, {20.0f, 0.0f, 1000.0f}, {0.0f, 20.0f, 1000.0f}};
size_t i = 0;
for(; i < NUM_OF_POINTS; i++) {
TobiiResearchPoint3D* point = &points_to_calibrate[i];
printf("Show a point on screen at (%f,%f).\n", point->x, point->y);
// Wait a little for user to focus.
sleep_ms(700);
printf("Collecting data at (%f,%f,%f).\n", point->x, point->y, point->z);
if (tobii_research_hmd_based_calibration_collect_data(eyetracker, point->x, point->y, point->z) != TOBII_RESEARCH_STATUS_OK) {
/* Try again if it didn't go well the first time. */
/* Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply. */
tobii_research_hmd_based_calibration_collect_data(eyetracker, point->x, point->y, point->z);
}
}
printf("Computing and applying calibration.\n");
status = tobii_research_hmd_based_calibration_compute_and_apply(eyetracker, &calibration_result);
if (status == TOBII_RESEARCH_STATUS_OK) {
if (calibration_result.status == TOBII_RESEARCH_CALIBRATION_SUCCESS)
printf("Calibration was successful!\n");
else if (calibration_result.status == TOBII_RESEARCH_CALIBRATION_FAILURE)
printf("Calibration failed!\n");
}
}
/* The calibration is done. Leave calibration mode. */
printf("Left calibration mode.\n");
}