Follow aircraft allow to zoom in/out

* renamed sniffer
* ignore keystrokes if NO aircraft is followed
* allow to zoom in/out my multiplying the distance
This commit is contained in:
Klaus Basan
2019-08-23 01:02:45 +02:00
committed by Mat Sutcliffe
parent 0d29471144
commit 62f5ddab99
2 changed files with 15 additions and 7 deletions

View File

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

View File

@@ -167,7 +167,7 @@ namespace XSwiftBus
static int orbitOwnAircraftFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon); static int orbitOwnAircraftFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon);
static int orbitPlaneFunc(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 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 //! Remote aircraft
struct Plane struct Plane
@@ -236,6 +236,7 @@ namespace XSwiftBus
bool m_isSpacePressed = false; bool m_isSpacePressed = false;
int m_lastMouseX = -1; int m_lastMouseX = -1;
int m_lastMouseY = -1; int m_lastMouseY = -1;
double m_followAircraftDistanceMultiplier = 1.0;
DeltaCameraPosition m_deltaCameraPosition; DeltaCameraPosition m_deltaCameraPosition;
bool m_emitSimFrame = true; bool m_emitSimFrame = true;