diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index 8a2504023..d20d45b1d 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -947,7 +947,7 @@ namespace XSwiftBus // Ideally we would like to test against right mouse button, but X-Plane SDK does not // allow that. - if (!traffic->m_deltaCameraPosition.isInitialized) + if (!traffic->m_deltaCameraPosition.isInitialized || traffic->m_isSpacePressed) { int w = 0, h = 0, x = 0, y = 0; // First get the screen size and mouse location. We will use this to decide @@ -956,6 +956,12 @@ namespace XSwiftBus XPLMGetScreenSize(&w, &h); XPLMGetMouseLocation(&x, &y); if (DEBUG) { DEBUG_LOG("Follow aircraft coordinates w,h,x,y: " + std::to_string(w) + " " + std::to_string(h) + " " + std::to_string(x) + " " + std::to_string(y)); } + if (traffic->m_lastMouseX == x && traffic->m_lastMouseY == y && traffic->m_lastMouseX >= 0 && traffic->m_lastMouseY >= 0) + { + // mouse NOT moving, we lost focus or we do NOT move anymore + // to avoid issues we reset the space key, see https://discordapp.com/channels/539048679160676382/539925070550794240/614162134644949002 + traffic->m_isSpacePressed = false; + } // avoid follow aircraft in too small windows // int cannot be NaN @@ -971,8 +977,9 @@ namespace XSwiftBus return 0; } - traffic->m_deltaCameraPosition.headingDeg = normalizeToZero360Deg(360.0 * static_cast(x) / static_cast(w)); // range 0-360 - double usedCameraPitchDeg = 60.0 - (60.0 * 2.0 * static_cast(y) / static_cast(h)); // range +- + // the 1.25 factor allows to turn around completely + traffic->m_deltaCameraPosition.headingDeg = normalizeToZero360Deg(1.25 * 360.0 * static_cast(x) / static_cast(w)); // range 0-360 + double usedCameraPitchDeg = 60.0-(60.0 * 2.0 * static_cast(y) / static_cast(h)); // range +- // make sure we can use it with tan in range +-90 degrees and the result of tan not getting too high // we limit to +-85deg, tan 45deg: 1 | tan 60deg: 1.73 | tan 85deg: 11.4 @@ -1116,7 +1123,7 @@ namespace XSwiftBus { // if XPlane looses focus it can happen that key down is NOT reset // for the camera we use the init flag instead, so it is only run once - if (flags & xplm_DownFlag) { traffic->m_isSpacePressed = true; traffic->m_deltaCameraPosition.isInitialized = false; } + if (flags & xplm_DownFlag) { traffic->m_isSpacePressed = true; } if (flags & xplm_UpFlag) { traffic->m_isSpacePressed = false; } } diff --git a/src/xswiftbus/traffic.h b/src/xswiftbus/traffic.h index 29d4082db..2524aa0ed 100644 --- a/src/xswiftbus/traffic.h +++ b/src/xswiftbus/traffic.h @@ -234,6 +234,8 @@ namespace XSwiftBus DataRef m_ownAircraftPositionZ; bool m_isSpacePressed = false; + int m_lastMouseX = -1; + int m_lastMouseY = -1; DeltaCameraPosition m_deltaCameraPosition; bool m_emitSimFrame = true;