Skip to content

Commit

Permalink
Merge branch 'Next'
Browse files Browse the repository at this point in the history
  • Loading branch information
TwinFan committed Feb 26, 2020
2 parents 100774d + 295fdf6 commit 7414314
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//
// MARK: Version Information (CHANGE VERSION HERE)
//
constexpr float VERSION_NR = 1.23f;
constexpr float VERSION_NR = 1.24f;
constexpr bool VERSION_BETA = false;
extern float verXPlaneOrg; // version on X-Plane.org
extern int verDateXPlaneOrg; // and its date
Expand Down
41 changes: 37 additions & 4 deletions Include/CoordCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,43 @@ vectorTy CoordVectorBetween (const positionTy& from, const positionTy& to );
// destination point given a starting point and a vetor
positionTy CoordPlusVector (const positionTy& pos, const vectorTy& vec);

// returns terrain altitude at given position
// returns NaN in case of failure
double YProbe_at_m (const positionTy& posAt, XPLMProbeRef& probeRef);

//
// MARK: Estimated Functions on coordinates
//

/// @details Length of a degree latitude
/// @see https://en.wikipedia.org/wiki/Geographic_coordinate_system#Length_of_a_degree
constexpr double LAT_DEG_IN_MTR = 111132.95;
/// @details Length of a degree longitude
/// @see https://en.wikipedia.org/wiki/Geographic_coordinate_system#Length_of_a_degree
inline double LonDegInMtr (double lat) { return LAT_DEG_IN_MTR * std::cos(deg2rad(lat)); }

/// @brief An _estimated_ **square** of the distance between 2 points given by lat/lon
/// @details Makes use simple formulas to convert lat/lon differences into meters
/// So this is not exact but quick and good enough for many purposes.
/// On short distances of less than 10m, difference to CoordDistance() is a few millimeters.
/// @return Square of distance (estimated) in meter
double DistLatLonSqr (double lat1, double lon1,
double lat2, double lon2);

/// @brief An _estimated_ distance between 2 points given by lat/lon
/// @details Makes use simple formulas to convert lat/lon differences into meters
/// So this is not exact but quick and good enough for many purposes.
/// On short distances of less than 10m, difference to CoordDistance() is a few millimeters.
/// @return Distance (estimated) in meter
inline double DistLatLon (double lat1, double lon1,
double lat2, double lon2)
{ return std::sqrt(DistLatLonSqr(lat1,lon1,lat2,lon2)); }


//
// MARK: Functions on 2D points, typically in meters
//

/// @brief Simple square of distance just by Pythagoras
inline double DistPythSqr (double x1, double y1,
double x2, double y2)
Expand Down Expand Up @@ -126,10 +163,6 @@ void DistResultToBaseLoc (double ln_x1, double ln_y1,
const distToLineTy& res,
double &x, double &y);

// returns terrain altitude at given position
// returns NaN in case of failure
double YProbe_at_m (const positionTy& posAt, XPLMProbeRef& probeRef);

//
//MARK: Data Structures
//
Expand Down
Binary file modified LiveTraffic.rc
Binary file not shown.
9 changes: 9 additions & 0 deletions Src/CoordCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ positionTy CoordPlusVector (const positionTy& p, const vectorTy& vec)
return ret.rad2deg();
}

//An estimated square of the distance between 2 points given by lat/lon
double DistLatLonSqr (double lat1, double lon1,
double lat2, double lon2)
{
const double dx = (lon2-lon1) * LonDegInMtr((lat1+lat2)/2);
const double dz = (lat2-lat1) * LAT_DEG_IN_MTR;
return sqr(dx) + sqr(dz);
}

// Square of distance between a location and a line defined by two points.
void DistPointToLineSqr (double pt_x, double pt_y,
double ln_x1, double ln_y1,
Expand Down
23 changes: 15 additions & 8 deletions Src/DataRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,22 +754,29 @@ bool DataRefs::RegisterCommands()
return bRet;
}


// Did the reference point to the local coordinate system change since last call to this function?
/// @note Will always return `true` on first call, intentionally.
bool DataRefs::DidLocalRefPointChange ()
{
const float nowLatRef = XPLMGetDataf(adrXP[DR_LAT_REF]);
const float nowLonRef = XPLMGetDataf(adrXP[DR_LON_REF]);

// return value:
const bool ret = (std::isnan(lstLonRef) || // never asked before?
(dequal(lstLatRef, nowLatRef) && dequal(lstLonRef, nowLonRef)));

// Update our known value of lat/lon reference
lstLatRef = nowLatRef;
lstLonRef = nowLonRef;
// Is this a change compared to what we know?
if (std::isnan(lstLonRef) || // never asked before?
!dequal(lstLatRef, nowLatRef) || // changed compared to last call?
!dequal(lstLonRef, nowLonRef))
{
// Update our known value of lat/lon reference
lstLatRef = nowLatRef;
lstLonRef = nowLonRef;

// ref point changed
return true;
}

return ret;
// no change
return false;
}

// return user's plane pos
Expand Down
4 changes: 0 additions & 4 deletions Src/LTAircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ bool NextCycle (int newCycle)
else
XPMPDisableAircraftLabels();

// Check if the reference point of the local coordinate system had changed
if (dataRefs.DidLocalRefPointChange())


// time should move forward (positive difference) and not too much either
// If time moved to far between two calls then we better start over
// (but no problem if no a/c yet displayed anyway)
Expand Down
Loading

0 comments on commit 7414314

Please sign in to comment.