#ifdef WIN32
#include <windows.h>
#else
#include <csignal>
#endif
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
#include <memory>
#include <iostream>
#include <thread>
#include <chrono>
static inline void PrintMatrix(const std::array<float, 16>& mat)
{
for (int y = 0; y < 4; ++y)
{
for (int x = 0; x < 4; ++x)
{
std::cout << mat[x + y * 4] << "\t";
}
std::cout << "\n";
}
}
static bool running = true;
static const uint32_t numberOfSamplesToGrab = 1000;
{
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
running = false;
}
} listener;
std::shared_ptr<PSTech::pstsdk::Tracker> pst;
static void Exithandler(int sig)
{
pst->Shutdown();
running = false;
}
int main(int argc, char *argv[])
{
#ifdef WIN32
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#else
signal(SIGTERM, Exithandler);
signal(SIGKILL, Exithandler);
signal(SIGQUIT, Exithandler);
signal(SIGINT, Exithandler);
#endif
try
{
#ifdef WIN32
pst = std::make_shared<PSTech::pstsdk::Tracker>();
#else
pst = std::make_shared<PSTech::pstsdk::Tracker>("","config.cfg","models.db",argv[1]);
#endif
std::cout << "Running PST Server version " << pst->GetVersionInfo() << "\n";
pst->AddTrackerListener(&listener);
pst->Start();
std::cout << "System check: " << (int)pst->Systemcheck() << "\n";
pst->SetFramerate(30);
std::cout << "Frame rate set to " << pst->GetFramerate() << "\n\n";
std::cout << "*******************\n\n";
std::cout << "Current reference system transformation matrix:\n";
PrintMatrix(pst->GetReference());
std::cout << "\n\n*******************\n\n";
std::array<float, 16> reference{ -1.0f, 0.0f, 0.0f, 0.1f,
0.0f, 0.0f, 1.0f, -0.5f,
0.0f, 1.0f, 0.0f, 0.5f,
0.0f, 0.0f, 0.0f, 1.0f };
pst->SetReference(reference);
std::cout << "New reference system transformation matrix:\n";
PrintMatrix(pst->GetReference());
if (pst->GetReference() != reference)
std::cout << "Reference not set correctly!\n";
else
std::cout << "Reference set correctly!\n";
std::cout << "\n\n*******************\n\n";
std::array<float, 16> nonOrthonormalReference{ -1.0f, 1.0f, 0.0f, 0.1f,
0.0f, 0.0f, -1.0f, -0.5f,
0.0f, -1.0f, 0.0f, 0.5f,
0.0f, 0.0f, 0.0f, 1.0f };
pst->SetReference(nonOrthonormalReference);
std::cout << "New reference system after applying non-orthonormal transformation:\n";
PrintMatrix(pst->GetReference());
if (pst->GetReference() != nonOrthonormalReference)
std::cout << "Reference input correctly ignored!\n";
else
std::cout << "Reference input incorrectly applied!\n";
std::cout << "\n\n*******************\n\n";
std::array<float, 16> relativeReference{ 0.0f, -1.0f, 0.0f, 0.5f,
1.0f, 0.0f, 0.0f, 0.4f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
pst->SetReference(relativeReference, true);
std::cout << "New reference system after applying relative transformation:\n";
PrintMatrix(pst->GetReference());
std::cout << "\n\n*******************\n\n";
pst->SetDefaultReference();
std::cout << "Reset default reference system:\n";
PrintMatrix(pst->GetReference());
while (running)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
{
}
pst->Shutdown();
std::cout << "Press enter to continue...\n";
std::cin.get();
return 0;
}