summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_freepie-udp
diff options
context:
space:
mode:
Diffstat (limited to 'ftnoir_tracker_freepie-udp')
-rw-r--r--ftnoir_tracker_freepie-udp/freepie-udp-controls.ui69
-rw-r--r--ftnoir_tracker_freepie-udp/freepie-udp-res.qrc5
-rw-r--r--ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp.cpp94
-rw-r--r--ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp.h65
-rw-r--r--ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp_dialog.cpp27
-rw-r--r--ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp_dll.cpp27
-rw-r--r--ftnoir_tracker_freepie-udp/glovepie.pngbin0 -> 3584 bytes
7 files changed, 287 insertions, 0 deletions
diff --git a/ftnoir_tracker_freepie-udp/freepie-udp-controls.ui b/ftnoir_tracker_freepie-udp/freepie-udp-controls.ui
new file mode 100644
index 00000000..48290bf2
--- /dev/null
+++ b/ftnoir_tracker_freepie-udp/freepie-udp-controls.ui
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UI_freepie_udp_dialog</class>
+ <widget class="QWidget" name="UI_freepie_udp_dialog">
+ <property name="windowModality">
+ <enum>Qt::NonModal</enum>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>198</width>
+ <height>71</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>UDP tracker settings</string>
+ </property>
+ <property name="windowIcon">
+ <iconset>
+ <normaloff>../facetracknoir/images/facetracknoir.png</normaloff>../facetracknoir/images/facetracknoir.png</iconset>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::LeftToRight</enum>
+ </property>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>UDP port</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QSpinBox" name="port">
+ <property name="minimum">
+ <number>0</number>
+ </property>
+ <property name="maximum">
+ <number>65535</number>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <slots>
+ <slot>startEngineClicked()</slot>
+ <slot>stopEngineClicked()</slot>
+ <slot>cameraSettingsClicked()</slot>
+ </slots>
+</ui>
diff --git a/ftnoir_tracker_freepie-udp/freepie-udp-res.qrc b/ftnoir_tracker_freepie-udp/freepie-udp-res.qrc
new file mode 100644
index 00000000..3fd3edc4
--- /dev/null
+++ b/ftnoir_tracker_freepie-udp/freepie-udp-res.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>glovepie.png</file>
+ </qresource>
+</RCC>
diff --git a/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp.cpp b/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp.cpp
new file mode 100644
index 00000000..ad505229
--- /dev/null
+++ b/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp.cpp
@@ -0,0 +1,94 @@
+#include "ftnoir_tracker_freepie-udp.h"
+#include "facetracknoir/plugin-support.h"
+
+#include <cinttypes>
+#include <algorithm>
+
+TrackerImpl::TrackerImpl() : pose { 0,0,0, 0,0,0 }, should_quit(false)
+{
+}
+
+TrackerImpl::~TrackerImpl()
+{
+ should_quit = true;
+ wait();
+}
+
+void TrackerImpl::run() {
+#pragma pack(push, 1)
+ struct {
+ uint8_t pad1;
+ uint8_t flags;
+ uint8_t pad2;
+ float fl[12];
+ } data;
+#pragma pack(pop)
+ enum F {
+ flag_Raw = 1 << 0,
+ flag_Orient = 1 << 1,
+ Mask = flag_Raw | flag_Orient
+ };
+
+ while (1) {
+ if (should_quit)
+ break;
+
+ float orient[3];
+ bool filled = false;
+
+ while (sock.hasPendingDatagrams())
+ {
+ using t = decltype(data);
+ t tmp {0,0,0, {0,0,0, 0,0,0}};
+ (void) sock.readDatagram(reinterpret_cast<char*>(&tmp), sizeof(data));
+
+ int flags = tmp.flags & F::Mask;
+
+ switch (flags)
+ {
+ case flag_Raw:
+ continue;
+ case flag_Raw | flag_Orient:
+ for (int i = 0; i < 3; i++)
+ orient[i] = tmp.fl[i+9];
+ break;
+ case flag_Orient:
+ for (int i = 0; i < 3; i++)
+ orient[i] = tmp.fl[i];
+ break;
+ }
+
+ filled = true;
+ data = tmp;
+ }
+
+ if (filled)
+ {
+ QMutexLocker foo(&mtx);
+ static constexpr double d2r = 57.295781;
+ for (int i = 0; i < 3; i++)
+ pose[Yaw + i] = d2r * orient[i];
+ }
+ usleep(4000);
+ }
+}
+
+void TrackerImpl::StartTracker(QFrame*)
+{
+ (void) sock.bind(QHostAddress::Any, (int) s.port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
+ start();
+}
+
+void TrackerImpl::GetHeadPoseData(double *data)
+{
+ QMutexLocker foo(&mtx);
+
+ data[Yaw] = pose[Yaw];
+ data[Pitch] = pose[Pitch];
+ data[Roll] = pose[Roll];
+}
+
+extern "C" OPENTRACK_EXPORT ITracker* GetConstructor()
+{
+ return new TrackerImpl;
+}
diff --git a/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp.h b/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp.h
new file mode 100644
index 00000000..de32e64b
--- /dev/null
+++ b/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp.h
@@ -0,0 +1,65 @@
+/* Copyright (c) 2014 Stanislaw Halik <sthalik@misaki.pl>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#include <cinttypes>
+#include <QUdpSocket>
+#include <QThread>
+#include "ui_freepie-udp-controls.h"
+#include "facetracknoir/plugin-api.hpp"
+#include "facetracknoir/options.h"
+using namespace options;
+
+struct settings {
+ pbundle b;
+ value<int> port;
+ settings() :
+ b(bundle("freepie-udp-tracker")),
+ port(b, "port", 4237)
+ {}
+};
+
+class TrackerImpl : public ITracker, private QThread
+{
+public:
+ TrackerImpl();
+ ~TrackerImpl() override;
+ void StartTracker(QFrame *);
+ void GetHeadPoseData(double *data);
+protected:
+ void run() override;
+private:
+ double pose[6];
+ QUdpSocket sock;
+ settings s;
+ QMutex mtx;
+ volatile bool should_quit;
+};
+
+class TrackerDialog : public QWidget, public ITrackerDialog
+{
+ Q_OBJECT
+public:
+ TrackerDialog();
+ void registerTracker(ITracker *) {}
+ void unRegisterTracker() {}
+private:
+ Ui::UI_freepie_udp_dialog ui;
+ settings s;
+private slots:
+ void doOK();
+ void doCancel();
+};
+
+class TrackerMeta : public Metadata
+{
+public:
+ void getFullName(QString *strToBeFilled);
+ void getShortName(QString *strToBeFilled);
+ void getDescription(QString *strToBeFilled);
+ void getIcon(QIcon *icon);
+};
+
diff --git a/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp_dialog.cpp b/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp_dialog.cpp
new file mode 100644
index 00000000..6d6a951e
--- /dev/null
+++ b/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp_dialog.cpp
@@ -0,0 +1,27 @@
+#include "ftnoir_tracker_freepie-udp.h"
+#include "facetracknoir/plugin-support.h"
+
+TrackerDialog::TrackerDialog()
+{
+ ui.setupUi(this);
+
+ connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));
+ connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));
+
+ tie_setting(s.port, ui.port);
+}
+
+void TrackerDialog::doOK() {
+ s.b->save();
+ this->close();
+}
+
+void TrackerDialog::doCancel() {
+ s.b->reload();
+ this->close();
+}
+
+extern "C" OPENTRACK_EXPORT ITrackerDialog* GetDialog()
+{
+ return new TrackerDialog;
+}
diff --git a/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp_dll.cpp b/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp_dll.cpp
new file mode 100644
index 00000000..afcc8c6e
--- /dev/null
+++ b/ftnoir_tracker_freepie-udp/ftnoir_tracker_freepie-udp_dll.cpp
@@ -0,0 +1,27 @@
+#include "ftnoir_tracker_freepie-udp.h"
+#include "facetracknoir/plugin-support.h"
+
+void TrackerMeta::getFullName(QString *strToBeFilled)
+{
+ *strToBeFilled = "FreePIE UDP";
+}
+
+void TrackerMeta::getShortName(QString *strToBeFilled)
+{
+ *strToBeFilled = "FreePIE";
+}
+
+void TrackerMeta::getDescription(QString *strToBeFilled)
+{
+ *strToBeFilled = "FreePIE UDP";
+}
+
+void TrackerMeta::getIcon(QIcon *icon)
+{
+ *icon = QIcon(":/glovepie.png");
+}
+
+extern "C" OPENTRACK_EXPORT Metadata* GetMetadata()
+{
+ return new TrackerMeta;
+}
diff --git a/ftnoir_tracker_freepie-udp/glovepie.png b/ftnoir_tracker_freepie-udp/glovepie.png
new file mode 100644
index 00000000..2156b7af
--- /dev/null
+++ b/ftnoir_tracker_freepie-udp/glovepie.png
Binary files differ