diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index d20d45b1d..7eb3f6b44 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -60,7 +60,7 @@ namespace XSwiftBus assert(!s_instance); s_instance = this; XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this); - XPLMRegisterKeySniffer(spaceKeySniffer, 1, this); + XPLMRegisterKeySniffer(followAircraftKeySniffer, 1, this); // init labels this->setDrawingLabels(this->getSettings().isDrawingLabels()); @@ -921,7 +921,7 @@ namespace XSwiftBus int CTraffic::orbitPlaneFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon) { - constexpr bool DEBUG = true; + constexpr bool DEBUG = false; // DEBUG_LOG_C("Follow aircraft entry", DEBUG); if (isLosingControl == 1) { @@ -979,7 +979,7 @@ namespace XSwiftBus // 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 +- + 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 @@ -990,7 +990,7 @@ namespace XSwiftBus // Now calculate where the camera should be positioned to be x // meters from the plane and pointing at the plane at the pitch and // heading we wanted above. - const double distanceMeterM = static_cast(std::max(10, traffic->getSettings().getFollowAircraftDistanceM())); + const double distanceMeterM = traffic->m_followAircraftDistanceMultiplier * static_cast(std::max(10, traffic->getSettings().getFollowAircraftDistanceM())); static const double PI = std::acos(-1); traffic->m_deltaCameraPosition.dxMeters = -distanceMeterM * sin(traffic->m_deltaCameraPosition.headingDeg * PI / 180.0); traffic->m_deltaCameraPosition.dzMeters = distanceMeterM * cos(traffic->m_deltaCameraPosition.headingDeg * PI / 180.0); @@ -1023,6 +1023,7 @@ namespace XSwiftBus { INFO_LOG("Follow aircraft, no callsign to follow"); traffic->m_followPlaneViewCallsign.clear(); + traffic->m_followAircraftDistanceMultiplier = 1.0; return 0; } @@ -1031,6 +1032,7 @@ namespace XSwiftBus { INFO_LOG("Follow aircraft, no plane found for callsign " + traffic->m_followPlaneViewCallsign); traffic->m_followPlaneViewCallsign.clear(); + traffic->m_followAircraftDistanceMultiplier = 1.0; return 0; } @@ -1039,6 +1041,7 @@ namespace XSwiftBus { ERROR_LOG("Follow aircraft, no plane from iterator for callsign " + traffic->m_followPlaneViewCallsign); traffic->m_followPlaneViewCallsign.clear(); + traffic->m_followAircraftDistanceMultiplier = 1.0; return 0; } @@ -1072,6 +1075,7 @@ namespace XSwiftBus { WARNING_LOG("Invalid camera aircraft position"); WARNING_LOG("Pos: " + pos2String(cameraPosition)); + traffic->m_followAircraftDistanceMultiplier = 1.0; return 0; } @@ -1112,11 +1116,11 @@ namespace XSwiftBus return 1; } - int CTraffic::spaceKeySniffer(char character, XPLMKeyFlags flags, char virtualKey, void *refcon) + int CTraffic::followAircraftKeySniffer(char character, XPLMKeyFlags flags, char virtualKey, void *refcon) { (void) character; - (void) flags; CTraffic *traffic = static_cast(refcon); + if (!traffic || traffic->m_followPlaneViewCallsign.empty()) { return 1; } // totally ignore if nothing is being followed // We are only interested in Space key if (virtualKey == XPLM_VK_SPACE) @@ -1126,6 +1130,9 @@ namespace XSwiftBus if (flags & xplm_DownFlag) { traffic->m_isSpacePressed = true; } if (flags & xplm_UpFlag) { traffic->m_isSpacePressed = false; } } + else if (virtualKey == XPLM_VK_DOWN && (flags & xplm_UpFlag)) { traffic->m_followAircraftDistanceMultiplier /= 1.2; } + else if (virtualKey == XPLM_VK_UP && (flags & xplm_UpFlag)) { traffic->m_followAircraftDistanceMultiplier *= 1.2; } + else if (virtualKey == XPLM_VK_ESCAPE && (flags & xplm_UpFlag)) { traffic->m_followAircraftDistanceMultiplier = 1.0; } /* Return 1 to pass the keystroke to plugin windows and X-Plane. * Returning 0 would consume the keystroke. */ diff --git a/src/xswiftbus/traffic.h b/src/xswiftbus/traffic.h index 2524aa0ed..e5c65765e 100644 --- a/src/xswiftbus/traffic.h +++ b/src/xswiftbus/traffic.h @@ -167,7 +167,7 @@ namespace XSwiftBus static int orbitOwnAircraftFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon); static int orbitPlaneFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon); static int drawCallback(XPLMDrawingPhase phase, int isBefore, void *refcon); - static int spaceKeySniffer(char character, XPLMKeyFlags flags, char virtualKey, void *refcon); + static int followAircraftKeySniffer(char character, XPLMKeyFlags flags, char virtualKey, void *refcon); //! Remote aircraft struct Plane @@ -236,6 +236,7 @@ namespace XSwiftBus bool m_isSpacePressed = false; int m_lastMouseX = -1; int m_lastMouseY = -1; + double m_followAircraftDistanceMultiplier = 1.0; DeltaCameraPosition m_deltaCameraPosition; bool m_emitSimFrame = true;