Extend SGWaypoint with track and speed data, and compute tracks with the

distance in SGRoute.
This commit is contained in:
jmt
2009-06-10 12:42:44 +00:00
committed by Tim Moore
parent 030d044d03
commit 6d1d3173fe
4 changed files with 57 additions and 45 deletions

View File

@@ -42,19 +42,21 @@ SGRoute::~SGRoute() {
}
/** Update the length of the leg ending at waypoint index */
void SGRoute::update_distance(int index)
void SGRoute::update_distance_and_track(int index)
{
SGWayPoint& curr = route[ index ];
double course, dist;
SGWayPoint& curr = route[ index ];
double course, dist;
if ( index == 0 ) {
dist = 0;
} else {
const SGWayPoint& prev = route[ index - 1 ];
curr.CourseAndDistance( prev, &course, &dist );
}
if ( index == 0 ) {
dist = 0;
course = 0.0;
} else {
const SGWayPoint& prev = route[index - 1];
curr.CourseAndDistance( prev, &course, &dist );
}
curr.set_distance( dist );
curr.set_distance(dist);
curr.set_track(course);
}
/**
@@ -69,9 +71,9 @@ void SGRoute::add_waypoint( const SGWayPoint &wp, int n ) {
} else {
route.insert( route.begin() + n, 1, wp );
// update distance of next leg if not at end of route
update_distance( n + 1 );
update_distance_and_track( n + 1 );
}
update_distance( n );
update_distance_and_track( n );
}
/** Delete waypoint with index n (last one if n < 0) */
@@ -85,7 +87,7 @@ void SGRoute::delete_waypoint( int n ) {
route.erase( route.begin() + n );
// update distance of next leg if not at end of route
if ( n < size - 1 )
update_distance( n );
update_distance_and_track( n );
}
double SGRoute::total_distance() const {

View File

@@ -52,7 +52,7 @@ private:
route_list route;
int current_wp;
void update_distance(int index);
void update_distance_and_track(int index);
public:
@@ -102,6 +102,22 @@ public:
return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
}
}
inline SGWayPoint get_previous() const {
if ( (current_wp > 0) && (current_wp < (int)route.size()) ) {
return route[current_wp - 1];
} else {
return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
}
}
inline SGWayPoint get_next() const {
if ( (current_wp + 1) < (int)route.size() ) {
return route[current_wp+1];
} else {
return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
}
}
/**
* Set the current waypoint

View File

@@ -33,21 +33,23 @@ using std::string;
// Constructor
SGWayPoint::SGWayPoint( const double lon, const double lat, const double alt,
const modetype m, const string& s, const string& n ) :
mode(m),
const modetype, const string& s, const string& n ) :
pos(SGGeod::fromDegM(lon, lat, alt)),
distance(0.0),
id(s),
name(n)
name(n),
_distance(0.0),
_track(0.0),
_speed(0.0)
{
}
SGWayPoint::SGWayPoint(const SGGeod& geod, const string& s, const string& n ) :
mode(WGS84),
pos(geod),
distance(0.0),
id(s),
name(n)
name(n),
_distance(0.0),
_track(0.0),
_speed(0.0)
{
}
@@ -56,15 +58,8 @@ SGWayPoint::~SGWayPoint() {
}
void SGWayPoint::CourseAndDistance(const SGGeod& cur, double& course, double& dist ) const {
if ( mode == WGS84 ) {
double reverse;
SGGeodesy::inverse(cur, pos, course, reverse, dist);
} else if ( mode == SPHERICAL ) {
Point3D currentPoint(cur.getLongitudeRad(), cur.getLatitudeRad(), 0.0 );
Point3D targetPoint(pos.getLongitudeRad(), pos.getLatitudeRad(), 0.0 );
calc_gc_course_dist( currentPoint, targetPoint, &course, &dist );
course = 360.0 - course * SGD_RADIANS_TO_DEGREES;
}
double reverse;
SGGeodesy::inverse(cur, pos, course, reverse, dist);
}
// Calculate course and distances. For WGS84 and SPHERICAL

View File

@@ -27,12 +27,6 @@
#ifndef _WAYPOINT_HXX
#define _WAYPOINT_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <simgear/compiler.h>
#include <simgear/math/SGMath.hxx>
@@ -61,19 +55,18 @@ public:
*/
enum modetype {
WGS84 = 0,
SPHERICAL = 1,
};
private:
modetype mode;
SGGeod pos;
double distance;
std::string id;
std::string name;
// route data associated with the waypoint
double _distance;
double _track;
double _speed;
public:
/**
@@ -147,14 +140,20 @@ public:
* is for your convenience only.
* @return waypoint distance holder (what ever the user has stashed here)
*/
inline double get_distance() const { return distance; }
inline double get_distance() const { return _distance; }
/**
* Set the waypoint distance value to a value of our choice.
* @param d distance
*/
inline void set_distance( double d ) { distance = d; }
inline void set_distance( double d ) { _distance = d; }
inline double get_track() const { return _track; }
inline void set_track(double t) { _track = t; }
inline double get_speed() const { return _speed; }
inline void set_speed(double v) { _speed = v; }
/** @return waypoint id */
inline const std::string& get_id() const { return id; }