From 35285cac2fe7ca803ffe494e1aafc6215ab6d1d0 Mon Sep 17 00:00:00 2001 From: Jason Watkins Date: Mon, 20 Jun 2016 09:57:59 -0700 Subject: [PATCH] Updated SetPosition - SetPosition now updates the aircraft's orientation after moving the aircraft - This should improve the handling of the aircraft when setting the position while paused and then unpausing - Fixes #91 --- xpcPlugin/DataManager.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xpcPlugin/DataManager.cpp b/xpcPlugin/DataManager.cpp index 72b5f17..5636bbd 100644 --- a/xpcPlugin/DataManager.cpp +++ b/xpcPlugin/DataManager.cpp @@ -680,6 +680,17 @@ namespace XPC pos[2] = (float)GetDouble(DREF_Elevation, aircraft); } + // See: http://www.xsquawkbox.net/xpsdk/mediawiki/MovingThePlane + // Need to get the aircraft's current orientation before moving and + // reset the orientation after moving to update the quaternion + float orient[3]; + orient[0] = GetFloat(DREF_Pitch, aircraft); + orient[1] = GetFloat(DREF_Roll, aircraft); + orient[2] = GetFloat(DREF_HeadingTrue, aircraft); + + // Now set the aircraft's position. Need to set world position for + // "long" moves, but since there isn't an easy way to calculate "long", + // we just set it every time. double local[3]; XPLMWorldToLocal(pos[0], pos[1], pos[2], &local[0], &local[1], &local[2]); // If the sim is paused, setting global position won't update the @@ -691,6 +702,9 @@ namespace XPC Set(DREF_Latitude, (double)pos[0], aircraft); Set(DREF_Longitude, (double)pos[1], aircraft); Set(DREF_Elevation, (double)pos[2], aircraft); + + // Now reset orientation to update q + SetOrientation(orient, aircraft); } void DataManager::SetOrientation(float orient[3], char aircraft)