1 // FGAIShip - FGAIBase-derived class creates an AI ship
3 // Written by David Culp, started October 2003.
4 // with major amendments and additions by Vivian Meazza, 2004 - 2007
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 # define finite _finite
27 #elif defined(__sun) || defined(sgi)
32 #include <simgear/math/sg_geodesy.hxx>
33 #include <simgear/timing/sg_time.hxx>
34 #include <simgear/math/sg_random.h>
35 #include <simgear/scene/util/SGNodeMasks.hxx>
40 FGAIShip::FGAIShip(object_type ot) :
47 FGAIShip::~FGAIShip() {
50 void FGAIShip::readFromScenario(SGPropertyNode* scFileNode) {
55 FGAIBase::readFromScenario(scFileNode);
57 setRudder(scFileNode->getFloatValue("rudder", 0.0));
58 setName(scFileNode->getStringValue("name", "Titanic"));
59 setRadius(scFileNode->getDoubleValue("turn-radius-ft", 2000));
60 std::string flightplan = scFileNode->getStringValue("flightplan");
61 setRepeat(scFileNode->getBoolValue("repeat", false));
62 setStartTime(scFileNode->getStringValue("time", ""));
64 if (!flightplan.empty()) {
65 FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan);
71 bool FGAIShip::init(bool search_in_AI_path) {
72 prev = 0; // the one behind you
73 curr = 0; // the one ahead
74 next = 0; // the next plus 1
78 props->setStringValue("name", _name.c_str());
79 props->setStringValue("position/waypoint-name-prev", _prev_name.c_str());
80 props->setStringValue("position/waypoint-name-curr", _curr_name.c_str());
81 props->setStringValue("position/waypoint-name-next", _next_name.c_str());
82 props->setStringValue("submodels/path", _path.c_str());
83 props->setStringValue("position/waypoint-start-time", _start_time.c_str());
84 props->setStringValue("position/waypoint-wait-until-time", _until_time.c_str());
90 _rudder_constant = 0.5;
91 _roll_constant = 0.001;
92 _speed_constant = 0.05;
94 _roll_factor = -0.0083335;
96 _rd_turn_radius_ft = _sp_turn_radius_ft = turn_radius_ft;
101 _new_waypoint = true;
105 _missed_time_sec = 30;
110 _wp_range = _old_range = 0;
114 _fp_init = initFlightPlan();
116 return FGAIBase::init(search_in_AI_path);
119 void FGAIShip::initModel(osg::Node *node) {
120 FGAIBase::initModel(node);
121 model->setNodeMask(model->getNodeMask() | SG_NODEMASK_TERRAIN_BIT);
124 void FGAIShip::bind() {
127 props->tie("surface-positions/rudder-pos-deg",
128 SGRawValuePointer<float>(&_rudder));
129 props->tie("controls/heading-lock",
130 SGRawValuePointer<bool>(&_hdg_lock));
131 props->tie("controls/tgt-speed-kts",
132 SGRawValuePointer<double>(&tgt_speed));
133 props->tie("controls/tgt-heading-degs",
134 SGRawValuePointer<double>(&tgt_heading));
135 props->tie("controls/constants/rudder",
136 SGRawValuePointer<double>(&_rudder_constant));
137 props->tie("controls/constants/roll-factor",
138 SGRawValuePointer<double>(&_roll_factor));
139 props->tie("controls/constants/roll",
140 SGRawValuePointer<double>(&_roll_constant));
141 props->tie("controls/constants/rudder",
142 SGRawValuePointer<double>(&_rudder_constant));
143 props->tie("controls/constants/speed",
144 SGRawValuePointer<double>(&_speed_constant));
145 props->tie("position/waypoint-range-nm",
146 SGRawValuePointer<double>(&_wp_range));
147 props->tie("position/waypoint-range-old-nm",
148 SGRawValuePointer<double>(&_old_range));
149 props->tie("position/waypoint-range-rate-nm-sec",
150 SGRawValuePointer<double>(&_range_rate));
151 props->tie("position/waypoint-new",
152 SGRawValuePointer<bool>(&_new_waypoint));
153 props->tie("position/waypoint-missed",
154 SGRawValuePointer<bool>(&_missed));
155 props->tie("position/waypoint-missed-count",
156 SGRawValuePointer<double>(&_missed_count));
157 props->tie("position/waypoint-missed-time-sec",
158 SGRawValuePointer<double>(&_missed_time_sec));
159 props->tie("position/waypoint-wait-count",
160 SGRawValuePointer<double>(&_wait_count));
161 props->tie("position/waypoint-waiting",
162 SGRawValuePointer<bool>(&_waiting));
163 props->tie("submodels/serviceable",
164 SGRawValuePointer<bool>(&_serviceable));
167 void FGAIShip::unbind() {
169 props->untie("surface-positions/rudder-pos-deg");
170 props->untie("controls/heading-lock");
171 props->untie("controls/tgt-speed-kts");
172 props->untie("controls/tgt-heading-degs");
173 props->untie("controls/constants/roll");
174 props->untie("controls/constants/rudder");
175 props->untie("controls/constants/roll-factor");
176 props->untie("controls/constants/speed");
177 props->untie("position/waypoint-range-nm");
178 props->untie("position/waypoint-range-old-nm");
179 props->untie("position/waypoint-range-rate-nm-sec");
180 props->untie("position/waypoint-new");
181 props->untie("position/waypoint-missed");
182 props->untie("position/waypoint-missed-count");
183 props->untie("position/waypoint-missed-time-sec");
184 props->untie("position/waypoint-wait-count");
185 props->untie("position/waypoint-waiting");
186 props->untie("submodels/serviceable");
189 void FGAIShip::update(double dt) {
190 // For computation of rotation speeds we just use finite differences here.
191 // That is perfectly valid since this thing is not driven by accelerations
192 // but by just apply discrete changes at its velocity variables.
193 // Update the velocity information stored in those nodes.
194 // Transform that one to the horizontal local coordinate system.
195 SGQuatd ec2hl = SGQuatd::fromLonLat(pos);
196 // The orientation of the carrier wrt the horizontal local frame
197 SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
198 // and postrotate the orientation of the AIModel wrt the horizontal
200 SGQuatd ec2body = ec2hl*hl2body;
201 // The cartesian position of the carrier in the wgs84 world
202 SGVec3d cartPos = SGVec3d::fromGeod(pos);
204 // Compute the velocity in m/s in the body frame
205 aip.setBodyLinearVelocity(SGVec3d(0.51444444*speed, 0, 0));
207 FGAIBase::update(dt);
211 // Only change these values if we are able to compute them safely
212 if (SGLimits<double>::min() < dt) {
213 // Now here is the finite difference ...
215 // Transform that one to the horizontal local coordinate system.
216 SGQuatd ec2hlNew = SGQuatd::fromLonLat(pos);
217 // compute the new orientation
218 SGQuatd hl2bodyNew = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
219 // The rotation difference
220 SGQuatd dOr = inverse(ec2body)*ec2hlNew*hl2bodyNew;
221 SGVec3d dOrAngleAxis;
222 dOr.getAngleAxis(dOrAngleAxis);
223 // divided by the time difference provides a rotation speed vector
226 aip.setBodyAngularVelocity(dOrAngleAxis);
230 void FGAIShip::Run(double dt) {
231 //cout << _name << " init: " << _fp_init << endl;
233 ProcessFlightPlan(dt);
235 // double speed_north_deg_sec;
236 // double speed_east_deg_sec;
242 double speed_diff = tgt_speed - speed;
244 if (fabs(speed_diff) > 0.1) {
246 if (speed_diff > 0.0)
247 speed += _speed_constant * dt;
249 if (speed_diff < 0.0)
250 speed -= _speed_constant * dt;
254 // do not allow unreasonable ship speeds
258 // convert speed to degrees per second
259 speed_north_deg_sec = cos(hdg / SGD_RADIANS_TO_DEGREES)
260 * speed * 1.686 / ft_per_deg_lat;
261 speed_east_deg_sec = sin(hdg / SGD_RADIANS_TO_DEGREES)
262 * speed * 1.686 / ft_per_deg_lon;
265 pos.setLatitudeDeg(pos.getLatitudeDeg() + speed_north_deg_sec * dt);
266 pos.setLongitudeDeg(pos.getLongitudeDeg() + speed_east_deg_sec * dt);
268 // adjust heading based on current _rudder angle
270 //cout << "turn_radius_ft " << turn_radius_ft ;
272 if (turn_radius_ft <= 0)
273 turn_radius_ft = 0; // don't allow nonsense values
281 //we assume that at slow speed ships will manoeuvre using engines/bow thruster
283 _sp_turn_radius_ft = 500;
285 // adjust turn radius for speed. The equation is very approximate.
286 // we need to allow for negative speeds
287 _sp_turn_radius_ft = 10 * pow ((fabs(speed) - 15), 2) + turn_radius_ft;
289 //cout << " speed turn radius " << _sp_turn_radius_ft ;
291 if (_rudder <= -0.25 || _rudder >= 0.25) {
292 // adjust turn radius for _rudder angle. The equation is even more approximate.
297 _rd_turn_radius_ft = (a * exp(b * fabs(_rudder)) + c) * _sp_turn_radius_ft;
299 //cout <<" _rudder turn radius " << _rd_turn_radius_ft << endl;
301 // calculate the angle, alpha, subtended by the arc traversed in time dt
302 alpha = ((speed * 1.686 * dt) / _rd_turn_radius_ft) * SG_RADIANS_TO_DEGREES;
304 // make sure that alpha is applied in the right direction
305 hdg += alpha * sign(_rudder);
313 //adjust roll for rudder angle and speed. Another bit of voodoo
314 raw_roll = _roll_factor * speed * _rudder;
316 // _rudder angle is 0
324 roll = (raw_roll * _roll_constant) + (roll * (1 - _roll_constant));
326 // adjust target _rudder angle if heading lock engaged
327 double rudder_diff = 0.0;
329 double rudder_sense = 0.0;
330 double diff = fabs(hdg - tgt_heading);
331 //cout << "_rudder diff" << diff << endl;
333 diff = fabs(diff - 360);
335 double sum = hdg + diff;
340 if (fabs(sum - tgt_heading)< 1.0)
346 rudder_sense = -rudder_sense;
349 _tgt_rudder = diff * rudder_sense;
351 _tgt_rudder = 45 * rudder_sense;
353 rudder_diff = _tgt_rudder - _rudder;
356 // set the _rudder limit by speed
358 rudder_limit = (-0.825 * speed) + 35;
362 if (fabs(rudder_diff)> 0.1) { // apply dead zone
364 if (rudder_diff > 0.0) {
365 _rudder += _rudder_constant * dt;
367 if (_rudder > rudder_limit) // apply the _rudder limit
368 _rudder = rudder_limit;
370 } else if (rudder_diff < 0.0) {
371 _rudder -= _rudder_constant * dt;
373 if (_rudder < -rudder_limit)
374 _rudder = -rudder_limit;
378 // do calculations for radar
379 UpdateRadar(manager);
383 void FGAIShip::AccelTo(double speed) {
387 void FGAIShip::PitchTo(double angle) {
391 void FGAIShip::RollTo(double angle) {
395 void FGAIShip::YawTo(double angle) {
398 void FGAIShip::ClimbTo(double altitude) {
402 void FGAIShip::TurnTo(double heading) {
403 tgt_heading = heading;
407 double FGAIShip::sign(double x) {
414 void FGAIShip::setFlightPlan(FGAIFlightPlan* f) {
418 void FGAIShip::setName(const string& n) {
422 void FGAIShip::setStartTime(const string& st) {
426 void FGAIShip::setUntilTime(const string& ut) {
428 props->setStringValue("position/waypoint-wait-until-time", _until_time.c_str());
431 void FGAIShip::setCurrName(const string& c) {
433 props->setStringValue("position/waypoint-name-curr", _curr_name.c_str());
436 void FGAIShip::setNextName(const string& n) {
438 props->setStringValue("position/waypoint-name-next", _next_name.c_str());
441 void FGAIShip::setPrevName(const string& p) {
443 props->setStringValue("position/waypoint-name-prev", _prev_name.c_str());
446 void FGAIShip::setRepeat(bool r) {
450 void FGAIShip::setMissed(bool m) {
452 props->setBoolValue("position/waypoint-missed", _missed);
455 void FGAIShip::setRudder(float r) {
459 void FGAIShip::setRoll(double rl) {
463 void FGAIShip::setWPNames() {
466 setPrevName(prev->name);
470 setCurrName(curr->name);
473 setNextName(next->name);
477 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: prev wp name " << prev->name);
478 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: current wp name " << curr->name);
479 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: next wp name " << next->name);
483 double FGAIShip::getRange(double lat, double lon, double lat2, double lon2) const {
485 double course, distance, az2;
487 //calculate the bearing and range of the second pos from the first
488 geo_inverse_wgs_84(lat, lon, lat2, lon2, &course, &az2, &distance);
489 distance *= SG_METER_TO_NM;
493 double FGAIShip::getCourse(double lat, double lon, double lat2, double lon2) const {
495 double course, distance, recip;
497 //calculate the bearing and range of the second pos from the first
498 geo_inverse_wgs_84(lat, lon, lat2, lon2, &course, &recip, &distance);
499 if (tgt_speed >= 0) {
506 void FGAIShip::ProcessFlightPlan(double dt) {
508 double time_sec = getDaySeconds();
509 double until_time_sec = 0;
514 ///////////////////////////////////////////////////////////////////////////
515 // Check Execution time (currently once every 1 sec)
516 // Add a bit of randomization to prevent the execution of all flight plans
517 // in synchrony, which can add significant periodic framerate flutter.
518 ///////////////////////////////////////////////////////////////////////////
520 //cout << "_start_sec " << _start_sec << " time_sec " << time_sec << endl;
521 if (_dt_count < _next_run && _start_sec < time_sec)
524 _next_run = 1.0 + (0.5 * sg_random());
526 // check to see if we've reached the point for our next turn
527 // if the range to the waypoint is less than the calculated turn
528 // radius we can start the turn to the next leg
529 _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
530 _range_rate = (_wp_range - _old_range) / _dt_count;
531 double sp_turn_radius_nm = _sp_turn_radius_ft / 6076.1155;
533 // we need to try to identify a _missed waypoint
535 // calculate the time needed to turn through an arc of 90 degrees, and allow an error of 30 secs
537 _missed_time_sec = 30 + ((SGD_PI * sp_turn_radius_nm * 60 * 60) / (2 * fabs(speed)));
539 _missed_time_sec = 30;
541 if ((_range_rate > 0) && (_wp_range < 3 * sp_turn_radius_nm) && !_new_waypoint)
542 _missed_count += _dt_count;
544 if (_missed_count >= _missed_time_sec) {
550 _old_range = _wp_range;
553 if ((_wp_range < sp_turn_radius_nm) || _missed || _waiting && !_new_waypoint) {
555 if (_next_name == "END") {
558 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: Flightplan restarting ");
561 curr = fp->getCurrentWaypoint();
562 next = fp->getNextWaypoint();
564 _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
565 _old_range = _wp_range;
567 _new_waypoint = true;
569 AccelTo(prev->speed);
571 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: Flightplan dieing ");
577 } else if (_next_name == "WAIT") {
579 if (_wait_count < next->time_sec) {
580 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " waiting ");
583 _wait_count += _dt_count;
587 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name
588 << " wait done: getting new waypoints ");
591 fp->IncrementWaypoint(false);
592 next = fp->getNextWaypoint();
594 if (next->name == "WAITUNTIL" || next->name == "WAIT"
595 || next->name == "END")
599 fp->IncrementWaypoint(false);
600 curr = fp->getCurrentWaypoint();
601 next = fp->getNextWaypoint();
604 } else if (_next_name == "WAITUNTIL") {
605 time_sec = getDaySeconds();
606 until_time_sec = processTimeString(next->time);
607 _until_time = next->time;
608 setUntilTime(next->time);
609 if (until_time_sec > time_sec) {
610 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " waiting until: "
611 << _until_time << " " << until_time_sec << " now " << time_sec );
616 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: "
617 << _name << " wait until done: getting new waypoints ");
619 fp->IncrementWaypoint(false);
621 while (next->name == "WAITUNTIL") {
622 fp->IncrementWaypoint(false);
623 next = fp->getNextWaypoint();
626 if (next->name == "WAIT")
630 fp->IncrementWaypoint(false);
631 curr = fp->getCurrentWaypoint();
632 next = fp->getNextWaypoint();
637 //now reorganise the waypoints, so that next becomes current and so on
638 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " getting new waypoints ");
639 fp->IncrementWaypoint(false);
640 prev = fp->getPreviousWaypoint(); //first waypoint
641 curr = fp->getCurrentWaypoint(); //second waypoint
642 next = fp->getNextWaypoint(); //third waypoint (might not exist!)
646 _new_waypoint = true;
649 _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
650 _old_range = _wp_range;
651 AccelTo(prev->speed);
653 _new_waypoint = false;
656 // now revise the required course for the next way point
657 double course = getCourse(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
662 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: Bearing or Range is not a finite number");
665 } // end Processing FlightPlan
667 bool FGAIShip::initFlightPlan() {
669 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " initializing waypoints ");
676 fp->IncrementWaypoint(false);
678 prev = fp->getPreviousWaypoint(); //first waypoint
679 curr = fp->getCurrentWaypoint(); //second waypoint
680 next = fp->getNextWaypoint(); //third waypoint (might not exist!)
682 while (curr->name == "WAIT" || curr->name == "WAITUNTIL") { // don't wait when initialising
683 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " re-initializing waypoints ");
684 fp->IncrementWaypoint(false);
685 curr = fp->getCurrentWaypoint();
686 next = fp->getNextWaypoint();
689 if (!_start_time.empty()){
690 _start_sec = processTimeString(_start_time);
691 double day_sec = getDaySeconds();
693 if (_start_sec < day_sec){
694 //cout << "flight plan has already started " << _start_time << endl;
695 init = advanceFlightPlan(_start_sec, day_sec);
697 } else if (_start_sec > day_sec && _repeat) {
698 //cout << "flight plan has not started, " << _start_time;
699 //cout << "offsetting start time by -24 hrs" << endl;
701 init = advanceFlightPlan(_start_sec, day_sec);
705 _start_sec = 0; // set to zero for an immediate start of the Flight Plan
708 fp->IncrementWaypoint(false);
709 prev = fp->getPreviousWaypoint();
710 curr = fp->getCurrentWaypoint();
711 next = fp->getNextWaypoint();
716 setLatitude(prev->latitude);
717 setLongitude(prev->longitude);
718 setSpeed(prev->speed);
722 setHeading(getCourse(prev->latitude, prev->longitude, curr->latitude, curr->longitude));
723 _wp_range = getRange(prev->latitude, prev->longitude, curr->latitude, curr->longitude);
724 _old_range = _wp_range;
729 _new_waypoint = true;
731 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " done initialising waypoints ");
740 } // end of initialization
743 double FGAIShip::processTimeString(const string& theTime) {
749 // first split theTime string into
750 // hour, minute, second and convert to int;
751 Hour = atoi(theTime.substr(0,2).c_str());
752 Minute = atoi(theTime.substr(3,5).c_str());
753 Second = atoi(theTime.substr(6,8).c_str());
755 // offset by a day-sec to allow for starting a day earlier
756 double time_seconds = Hour * 3600
763 double FGAIShip::getDaySeconds () {
765 struct tm *t = globals->get_time_params()->getGmt();
767 double day_seconds = t->tm_hour * 3600
774 bool FGAIShip::advanceFlightPlan (double start_sec, double day_sec) {
776 double elapsed_sec = start_sec;
777 double distance_nm = 0;
779 //cout << "advancing flight plan start_sec: " << start_sec << " " << day_sec << endl;
781 while ( elapsed_sec < day_sec ) {
783 if (next->name == "END") {
786 //cout << _name << ": " << "restarting flightplan" << endl;
788 curr = fp->getCurrentWaypoint();
789 next = fp->getNextWaypoint();
791 //cout << _name << ": " << "ending flightplan" << endl;
796 } else if (next->name == "WAIT") {
797 //cout << _name << ": begin WAIT: " << prev->name << " ";
798 //cout << curr->name << " " << next->name << endl;
800 elapsed_sec += next->time_sec;
802 if ( elapsed_sec >= day_sec)
805 fp->IncrementWaypoint(false);
806 next = fp->getNextWaypoint();
808 if (next->name != "WAITUNTIL" && next->name != "WAIT"
809 && next->name != "END") {
811 fp->IncrementWaypoint(false);
812 curr = fp->getCurrentWaypoint();
813 next = fp->getNextWaypoint();
816 } else if (next->name == "WAITUNTIL") {
817 double until_sec = processTimeString(next->time);
819 if (until_sec > _start_sec && start_sec < 0)
822 if (elapsed_sec < until_sec)
823 elapsed_sec = until_sec;
825 if (elapsed_sec >= day_sec )
828 fp->IncrementWaypoint(false);
829 next = fp->getNextWaypoint();
831 if (next->name != "WAITUNTIL" && next->name != "WAIT") {
833 fp->IncrementWaypoint(false);
834 curr = fp->getCurrentWaypoint();
835 next = fp->getNextWaypoint();
838 //cout << _name << ": end WAITUNTIL: ";
839 //cout << prev->name << " " << curr->name << " " << next->name << endl;
842 distance_nm = getRange(prev->latitude, prev->longitude, curr->latitude, curr->longitude);
843 elapsed_sec += distance_nm * 60 * 60 / prev->speed;
845 if (elapsed_sec >= day_sec)
848 fp->IncrementWaypoint(false);
849 prev = fp->getPreviousWaypoint();
850 curr = fp->getCurrentWaypoint();
851 next = fp->getNextWaypoint();
856 // the required position lies between the previous and current waypoints
857 // so we will calculate the distance back up the track from the current waypoint
858 // then calculate the lat and lon.
859 /*cout << "advancing flight plan done elapsed_sec: " << elapsed_sec
860 << " " << day_sec << endl;*/
862 double time_diff = elapsed_sec - day_sec;
863 double lat, lon, recip;
865 //cout << " time diff " << time_diff << endl;
867 if (next->name == "WAIT" ){
869 lat = curr->latitude;
870 lon = curr->longitude;
871 _wait_count= time_diff;
873 } else if (next->name == "WAITUNTIL") {
875 lat = curr->latitude;
876 lon = curr->longitude;
879 setSpeed(prev->speed);
880 distance_nm = speed * time_diff / (60 * 60);
881 double brg = getCourse(curr->latitude, curr->longitude, prev->latitude, prev->longitude);
883 //cout << " brg " << brg << " from " << curr->name << " to " << prev->name << " "
884 // << " lat " << curr->latitude << " lon " << curr->longitude
885 // << " distance m " << distance_nm * SG_NM_TO_METER << endl;
887 lat = geo_direct_wgs_84 (curr->latitude, curr->longitude, brg,
888 distance_nm * SG_NM_TO_METER, &lat, &lon, &recip );
889 lon = geo_direct_wgs_84 (curr->latitude, curr->longitude, brg,
890 distance_nm * SG_NM_TO_METER, &lat, &lon, &recip );
891 recip = geo_direct_wgs_84 (curr->latitude, curr->longitude, brg,
892 distance_nm * SG_NM_TO_METER, &lat, &lon, &recip );
895 //cout << "Pos " << lat << ", " << lon << " recip " << recip << endl;