summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanisław Halik <sthalik@misaki.pl>2017-05-17 09:24:52 +0200
committerGitHub <noreply@github.com>2017-05-17 09:24:52 +0200
commit3953977d0a9048883adc5db80bd714bd9bc72ed8 (patch)
tree15aebb8977204cc4d964c9f68fb2da204e9e3f44
parent4bb333b4c9690f6e88d07b0ba6ccbd2d026cfd00 (diff)
parent0d8bfd9e607e0aea7c5af61496a6105449eae2b9 (diff)
Merge pull request #623 from miniskipper/unstable
x-plane plugin
-rw-r--r--proto-wine/ftnoir_protocol_wine.cpp3
-rw-r--r--x-plane-plugin/plugin.c47
2 files changed, 34 insertions, 16 deletions
diff --git a/proto-wine/ftnoir_protocol_wine.cpp b/proto-wine/ftnoir_protocol_wine.cpp
index ea7fadf2..b3a780e7 100644
--- a/proto-wine/ftnoir_protocol_wine.cpp
+++ b/proto-wine/ftnoir_protocol_wine.cpp
@@ -4,6 +4,7 @@
#include <QStringList>
#include <QCoreApplication>
#include <string.h>
+#include <math.h>
#include <sys/mman.h>
#include <sys/stat.h> /* For mode constants */
#include <fcntl.h> /* For O_* constants */
@@ -37,7 +38,7 @@ void wine::pose( const double *headpose )
{
lck_shm.lock();
for (int i = 3; i < 6; i++)
- shm->data[i] = headpose[i] / 57.295781;
+ shm->data[i] = headpose[i] / (180 / M_PI );
for (int i = 0; i < 3; i++)
shm->data[i] = headpose[i] * 10;
if (shm->gameid != gameid)
diff --git a/x-plane-plugin/plugin.c b/x-plane-plugin/plugin.c
index 7897abe6..3795024c 100644
--- a/x-plane-plugin/plugin.c
+++ b/x-plane-plugin/plugin.c
@@ -14,6 +14,7 @@
#include <sys/mman.h>
#include <limits.h>
#include <unistd.h>
+#include <math.h>
#include <XPLMPlugin.h>
#include <XPLMDataAccess.h>
@@ -34,7 +35,7 @@
#include "compat/export.hpp"
enum Axis {
- TX = 0, TY, TZ, Yaw, Pitch, Roll
+ TX = 0, TY, TZ, Yaw, Pitch, Roll
};
typedef struct PortableLockedShm
@@ -53,7 +54,8 @@ typedef struct WineSHM
static PortableLockedShm* lck_posix = NULL;
static WineSHM* shm_posix = NULL;
-static void *view_x, *view_y, *view_z, *view_heading, *view_pitch;
+static WineSHM* data_last = NULL;
+static void *view_x, *view_y, *view_z, *view_heading, *view_pitch, *view_roll;
static float offset_x, offset_y, offset_z;
static XPLMCommandRef track_toggle = NULL, translation_disable_toggle = NULL;
static int track_disabled = 1;
@@ -111,15 +113,29 @@ float write_head_position(
void * OT_UNUSED(inRefcon) )
{
if (lck_posix != NULL && shm_posix != NULL) {
- PortableLockedShm_lock(lck_posix);
- if (!translation_disabled)
- {
- XPLMSetDataf(view_x, shm_posix->data[TX] * 1e-3 + offset_x);
- XPLMSetDataf(view_y, shm_posix->data[TY] * 1e-3 + offset_y);
- XPLMSetDataf(view_z, shm_posix->data[TZ] * 1e-3 + offset_z);
+ if(data_last == NULL){
+ data_last = calloc(1, sizeof(WineSHM));
}
- XPLMSetDataf(view_heading, shm_posix->data[Yaw] * 180 / 3.141592654);
- XPLMSetDataf(view_pitch, shm_posix->data[Pitch] * 180 / 3.141592654);
+
+ //only set the view if tracking is running
+ if(memcmp(shm_posix, data_last, sizeof(shm_posix->data)) != 0){
+ PortableLockedShm_lock(lck_posix);
+ if (!translation_disabled)
+ {
+ XPLMSetDataf(view_x, shm_posix->data[TX] * 1e-3 + offset_x);
+ XPLMSetDataf(view_y, shm_posix->data[TY] * 1e-3 + offset_y);
+ XPLMSetDataf(view_z, shm_posix->data[TZ] * 1e-3 + offset_z);
+ }
+ XPLMSetDataf(view_heading, shm_posix->data[Yaw] * 180 / M_PI);
+ XPLMSetDataf(view_pitch, shm_posix->data[Pitch] * 180 / M_PI);
+ XPLMSetDataf(view_roll, shm_posix->data[Roll] * 180 / M_PI);
+ } else {
+ //reset roll, otherwise it would be stuck at last angle
+ XPLMSetDataf(view_roll, 0);
+ }
+
+ memcpy(&data_last, &shm_posix, sizeof(WineSHM));
+
PortableLockedShm_unlock(lck_posix);
}
return -1.0;
@@ -160,12 +176,13 @@ static int TranslationToggleHandler( XPLMCommandRef inCommand,
return 0;
}
-PLUGIN_API OPENTRACK_COMPAT_EXPORT int XPluginStart ( char * outName, char * outSignature, char * outDescription ) {
+PLUGIN_API OTR_COMPAT_EXPORT int XPluginStart ( char * outName, char * outSignature, char * outDescription ) {
view_x = XPLMFindDataRef("sim/aircraft/view/acf_peX");
view_y = XPLMFindDataRef("sim/aircraft/view/acf_peY");
view_z = XPLMFindDataRef("sim/aircraft/view/acf_peZ");
view_heading = XPLMFindDataRef("sim/graphics/view/pilots_head_psi");
view_pitch = XPLMFindDataRef("sim/graphics/view/pilots_head_the");
+ view_roll = XPLMFindDataRef("sim/graphics/view/field_of_view_roll_deg");
track_toggle = XPLMCreateCommand("opentrack/toggle", "Disable/Enable head tracking");
translation_disable_toggle = XPLMCreateCommand("opentrack/toggle_translation", "Disable/Enable input translation from opentrack");
@@ -198,7 +215,7 @@ PLUGIN_API OPENTRACK_COMPAT_EXPORT int XPluginStart ( char * outName, char * out
return 0;
}
-PLUGIN_API OPENTRACK_COMPAT_EXPORT void XPluginStop ( void ) {
+PLUGIN_API OTR_COMPAT_EXPORT void XPluginStop ( void ) {
if (lck_posix)
{
PortableLockedShm_free(lck_posix);
@@ -207,17 +224,17 @@ PLUGIN_API OPENTRACK_COMPAT_EXPORT void XPluginStop ( void ) {
}
}
-PLUGIN_API OPENTRACK_COMPAT_EXPORT void XPluginEnable ( void ) {
+PLUGIN_API OTR_COMPAT_EXPORT void XPluginEnable ( void ) {
XPLMRegisterFlightLoopCallback(write_head_position, -1.0, NULL);
track_disabled = 0;
}
-PLUGIN_API OPENTRACK_COMPAT_EXPORT void XPluginDisable ( void ) {
+PLUGIN_API OTR_COMPAT_EXPORT void XPluginDisable ( void ) {
XPLMUnregisterFlightLoopCallback(write_head_position, NULL);
track_disabled = 1;
}
-PLUGIN_API OPENTRACK_COMPAT_EXPORT void XPluginReceiveMessage(
+PLUGIN_API OTR_COMPAT_EXPORT void XPluginReceiveMessage(
XPLMPluginID OT_UNUSED(inFromWho),
int OT_UNUSED(inMessage),
void * OT_UNUSED(inParam))