00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 # include <simgear_config.h>
00025 #endif
00026
00027 #include <plib/sg.h>
00028
00029 #include <simgear/math/vector.hxx>
00030
00031 #include "route.hxx"
00032
00033
00034
00035 SGRoute::SGRoute() {
00036 route.clear();
00037 }
00038
00039
00040
00041 SGRoute::~SGRoute() {
00042 }
00043
00045 void SGRoute::update_distance_and_track(int index)
00046 {
00047 SGWayPoint& curr = route[ index ];
00048 double course, dist;
00049
00050 if ( index == 0 ) {
00051 dist = 0;
00052 course = 0.0;
00053 } else {
00054 const SGWayPoint& prev = route[index - 1];
00055 curr.CourseAndDistance( prev, &course, &dist );
00056 }
00057
00058 curr.set_distance(dist);
00059 curr.set_track(course);
00060 }
00061
00066 void SGRoute::add_waypoint( const SGWayPoint &wp, int n ) {
00067 int size = route.size();
00068 if ( n < 0 || n >= size ) {
00069 n = size;
00070 route.push_back( wp );
00071 } else {
00072 route.insert( route.begin() + n, 1, wp );
00073
00074 update_distance_and_track( n + 1 );
00075 }
00076 update_distance_and_track( n );
00077 }
00078
00080 void SGRoute::delete_waypoint( int n ) {
00081 int size = route.size();
00082 if ( size == 0 )
00083 return;
00084 if ( n < 0 || n >= size )
00085 n = size - 1;
00086
00087 route.erase( route.begin() + n );
00088
00089 if ( n < size - 1 )
00090 update_distance_and_track( n );
00091 }
00092
00093 double SGRoute::total_distance() const {
00094 double total = 0.0;
00095 for (unsigned int i=0; i<route.size(); ++i) {
00096 total += route[i].get_distance();
00097 }
00098 return total;
00099 }