]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.cxx
21f999a61d5bb89585a2a49b8562e3aaca11ad6f
[flightgear.git] / src / AIModel / submodel.cxx
1 // submodel.cxx - models a releasable submodel.
2 // Written by Dave Culp, started Aug 2004
3 // With major additions by Vivian Meaaza 2004 - 2007
4 //
5 // This file is in the Public Domain and comes with no warranty.
6
7 #ifdef HAVE_CONFIG_H
8 #  include "config.h"
9 #endif
10
11 #include "submodel.hxx"
12
13 #include <simgear/structure/exception.hxx>
14 #include <simgear/misc/sg_path.hxx>
15 #include <simgear/math/sg_geodesy.hxx>
16
17 #include <Main/fg_props.hxx>
18 #include <Main/util.hxx>
19
20 #include "AIBase.hxx"
21 #include "AIManager.hxx"
22 #include "AIBallistic.hxx"
23
24
25 const double FGSubmodelMgr::lbs_to_slugs = 0.031080950172;
26
27 FGSubmodelMgr::FGSubmodelMgr()
28 {
29
30     x_offset = y_offset = 0.0;
31     z_offset = -4.0;
32     pitch_offset = 2.0;
33     yaw_offset = 0.0;
34
35     out[0] = out[1] = out[2] = 0;
36     in[3] = out[3] = 1;
37     string contents_node;
38     contrail_altitude = 30000;
39 }
40
41 FGSubmodelMgr::~FGSubmodelMgr()
42 {}
43
44 void FGSubmodelMgr::init()
45 {
46
47     index = 0;
48     load();
49
50     _serviceable_node = fgGetNode("/sim/submodels/serviceable", true);
51     _serviceable_node->setBoolValue(true);
52
53     _user_lat_node = fgGetNode("/position/latitude-deg", true);
54     _user_lon_node = fgGetNode("/position/longitude-deg", true);
55     _user_alt_node = fgGetNode("/position/altitude-ft", true);
56
57     _user_heading_node = fgGetNode("/orientation/heading-deg", true);
58     _user_pitch_node =   fgGetNode("/orientation/pitch-deg", true);
59     _user_roll_node =    fgGetNode("/orientation/roll-deg", true);
60     _user_yaw_node =     fgGetNode("/orientation/yaw-deg", true);
61     _user_alpha_node =   fgGetNode("/orientation/alpha-deg", true);
62
63     _user_speed_node = fgGetNode("/velocities/uBody-fps", true);
64
65     _user_wind_from_east_node  = fgGetNode("/environment/wind-from-east-fps", true);
66     _user_wind_from_north_node = fgGetNode("/environment/wind-from-north-fps", true);
67
68     _user_speed_down_fps_node   = fgGetNode("/velocities/speed-down-fps", true);
69     _user_speed_east_fps_node   = fgGetNode("/velocities/speed-east-fps", true);
70     _user_speed_north_fps_node  = fgGetNode("/velocities/speed-north-fps", true);
71
72     _contrail_altitude_node = fgGetNode("/environment/params/contrail-altitude", true);
73     contrail_altitude = _contrail_altitude_node->getDoubleValue();
74     _contrail_trigger = fgGetNode("ai/submodels/contrails", true);
75     _contrail_trigger->setBoolValue(false);
76
77     ai = (FGAIManager*)globals->get_subsystem("ai_model");
78
79     loadAI();
80 }
81
82 void FGSubmodelMgr::bind()
83 {}
84
85 void FGSubmodelMgr::unbind()
86 {
87     submodel_iterator = submodels.begin();
88
89     while (submodel_iterator != submodels.end()) {
90         (*submodel_iterator)->prop->untie("count");
91         ++submodel_iterator;
92     }
93
94 }
95
96 void FGSubmodelMgr::update(double dt)
97 {
98
99     if (!(_serviceable_node->getBoolValue()))
100         return;
101
102     int i = -1;
103     bool in_range = true;
104     bool trigger = false;
105
106     _contrail_trigger->setBoolValue(_user_alt_node->getDoubleValue() > contrail_altitude);
107
108     submodel_iterator = submodels.begin();
109     while (submodel_iterator != submodels.end()) {
110         i++;
111
112         if ((*submodel_iterator)->trigger_node != 0) {
113             trigger = (*submodel_iterator)->trigger_node->getBoolValue();
114             //cout << (*submodel_iterator)->name << "trigger node found" << trigger << endl;
115         } else {
116             trigger = true;
117             //cout << (*submodel_iterator)->name << "trigger node not found" << trigger << endl;
118         }
119
120         if (trigger) {
121             int id = (*submodel_iterator)->id;
122
123             // don't release submodels from AI Objects if they are
124             // too far away to be seen. id 0 is not an AI model,
125             // so we can skip the whole process
126             sm_list_iterator sm_list_itr = sm_list.begin();
127             sm_list_iterator end = sm_list.end();
128
129             while (sm_list_itr != end) {
130
131                 if (id == 0) {
132                     SG_LOG(SG_GENERAL, SG_DEBUG,
133                            "Submodels: continuing: " << id);
134                     ++sm_list_itr;
135                     continue;
136                 }
137
138                 int parent_id = (*sm_list_itr)->getID();
139
140                 if (parent_id == id) {
141                     double parent_lat = (*sm_list_itr)->_getLatitude();
142                     double parent_lon = (*sm_list_itr)->_getLongitude();
143                     double own_lat    = _user_lat_node->getDoubleValue();
144                     double own_lon    = _user_lon_node->getDoubleValue();
145                     double range_nm   = getRange(parent_lat, parent_lon, own_lat, own_lon);
146                     /* cout << "parent " << parent_id << ", "<< parent_lat << ", " << parent_lon << endl;
147                     cout << "own " << own_lat << ", " << own_lon << " range " << range_nm << endl;*/
148
149                     if (range_nm > 15) {
150                         SG_LOG(SG_GENERAL, SG_DEBUG,
151                                "Submodels: skipping release: " << id);
152                         in_range = false;
153                     }
154
155                 }
156
157                 ++sm_list_itr;
158             } // end while
159
160             if ((*submodel_iterator)->count != 0 && in_range)
161                 release((*submodel_iterator), dt);
162
163         } else
164             (*submodel_iterator)->first_time = true;
165
166         ++submodel_iterator;
167     } // end while
168
169 }
170
171 bool FGSubmodelMgr::release(submodel* sm, double dt)
172 {
173     // only run if first time or repeat is set to true
174     if (!sm->first_time && !sm->repeat)
175         return false;
176
177     sm->timer += dt;
178
179     if (sm->timer < sm->delay)
180         return false;
181
182     sm->timer = 0.0;
183
184     if (sm->first_time) {
185         dt = 0.0;
186         sm->first_time = false;
187     }
188
189     transform(sm);  // calculate submodel's initial conditions in world-coordinates
190
191     FGAIBallistic* ballist = new FGAIBallistic;
192     ballist->setPath(sm->model.c_str());
193     ballist->setLatitude(IC.lat);
194     ballist->setLongitude(IC.lon);
195     ballist->setAltitude(IC.alt);
196     ballist->setAzimuth(IC.azimuth);
197     ballist->setElevation(IC.elevation);
198     ballist->setRoll(IC.roll);
199     ballist->setSpeed(IC.speed / SG_KT_TO_FPS);
200     ballist->setWind_from_east(IC.wind_from_east);
201     ballist->setWind_from_north(IC.wind_from_north);
202     ballist->setMass(IC.mass);
203     ballist->setDragArea(sm->drag_area);
204     ballist->setLife(sm->life);
205     ballist->setBuoyancy(sm->buoyancy);
206     ballist->setWind(sm->wind);
207     ballist->setCd(sm->cd);
208     ballist->setStabilisation(sm->aero_stabilised);
209     ballist->setNoRoll(sm->no_roll);
210     ballist->setName(sm->name);
211     ai->attach(ballist);
212
213     if (sm->count > 0)
214         (sm->count)--;
215
216     return true;
217 }
218
219 void FGSubmodelMgr::load()
220 {
221     SGPropertyNode *path = fgGetNode("/sim/submodels/path");
222     SGPropertyNode root;
223
224     if (path) {
225         SGPath config(globals->get_fg_root());
226         config.append(path->getStringValue());
227
228         try {
229             readProperties(config.str(), &root);
230         } catch (const sg_exception &e) {
231             SG_LOG(SG_GENERAL, SG_INFO,
232                    "Submodels: unable to read submodels file: " << config.str());
233             return;
234         }
235     }
236
237     vector<SGPropertyNode_ptr> children = root.getChildren("submodel");
238     vector<SGPropertyNode_ptr>::iterator it = children.begin();
239     vector<SGPropertyNode_ptr>::iterator end = children.end();
240
241     for (int i = 0; it != end; ++it, i++) {
242         // cout << "Reading submodel " << (*it)->getPath() << endl;
243         submodel* sm = new submodel;
244         SGPropertyNode * entry_node = *it;
245         sm->name           = entry_node->getStringValue("name", "none_defined");
246         sm->model          = entry_node->getStringValue("model", "Models/Geometry/rocket.ac");
247         sm->speed          = entry_node->getDoubleValue("speed", 2329.4);
248         sm->repeat         = entry_node->getBoolValue("repeat", false);
249         sm->delay          = entry_node->getDoubleValue("delay", 0.25);
250         sm->count          = entry_node->getIntValue("count", 1);
251         sm->slaved         = entry_node->getBoolValue("slaved", false);
252         sm->x_offset       = entry_node->getDoubleValue("x-offset", 0.0);
253         sm->y_offset       = entry_node->getDoubleValue("y-offset", 0.0);
254         sm->z_offset       = entry_node->getDoubleValue("z-offset", 0.0);
255         sm->yaw_offset     = entry_node->getDoubleValue("yaw-offset", 0.0);
256         sm->pitch_offset   = entry_node->getDoubleValue("pitch-offset", 0.0);
257         sm->drag_area      = entry_node->getDoubleValue("eda", 0.034);
258         sm->life           = entry_node->getDoubleValue("life", 900.0);
259         sm->buoyancy       = entry_node->getDoubleValue("buoyancy", 0);
260         sm->wind           = entry_node->getBoolValue("wind", false);
261         sm->cd             = entry_node->getDoubleValue("cd", 0.193);
262         sm->weight         = entry_node->getDoubleValue("weight", 0.25);
263         sm->aero_stabilised = entry_node->getBoolValue("aero-stabilised", true);
264         sm->no_roll         = entry_node->getBoolValue("no-roll", false);
265         sm->contents_node   = fgGetNode(entry_node->getStringValue("contents", "none"), false);
266         sm->trigger_node    = fgGetNode(entry_node->getStringValue("trigger", "none"), false);
267         sm->speed_node      = fgGetNode(entry_node->getStringValue("speed-node", "none"), false);
268
269         //cout <<  "sm->contents_node " << sm->contents_node << endl;
270         if (sm->contents_node != 0)
271             sm->contents = sm->contents_node->getDoubleValue();
272
273         //cout << sm->name <<  " sm->trigger_node " << sm->trigger_node << endl;
274         if (sm->trigger_node != 0)
275             sm->trigger_node->setBoolValue(false);
276
277         if (sm->speed_node != 0)
278             sm->speed = sm->speed_node->getDoubleValue();
279
280         sm->timer = sm->delay;
281         sm->id = 0;
282         sm->first_time = false;
283
284         sm->prop = fgGetNode("/ai/submodels/submodel", index, true);
285         sm->prop->tie("count", SGRawValuePointer<int>(&(sm->count)));
286         sm->prop->tie("repeat", SGRawValuePointer<bool>(&(sm->repeat)));
287         sm->prop->tie("id", SGRawValuePointer<int>(&(sm->id)));
288         string name = sm->name;
289         sm->prop->setStringValue("name", name.c_str());
290
291         if (sm->contents_node != 0) {
292             sm->prop->tie("contents-lbs", SGRawValuePointer<double>(&(sm->contents)));
293         }
294
295         index++;
296         submodels.push_back(sm);
297     }
298
299     submodel_iterator = submodels.begin();
300 }
301
302 void FGSubmodelMgr::transform(submodel* sm)
303 {
304     // get initial conditions
305     if (sm->contents_node != 0) {
306         // get the weight of the contents (lbs) and convert to mass (slugs)
307         sm->contents = sm->contents_node->getDoubleValue();
308         IC.mass = (sm->weight + sm->contents) * lbs_to_slugs;
309
310         // set contents to 0 in the parent
311         sm->contents_node->setDoubleValue(0);
312     } else
313         IC.mass = sm->weight * lbs_to_slugs;
314
315     //cout << "mass "  << IC.mass << endl;
316
317     if (sm->speed_node != 0)
318         sm->speed = sm->speed_node->getDoubleValue();
319
320     int ind = sm->id;
321
322     if (ind == 0) {
323         // set the data for a submodel tied to the main model
324         IC.lat =        _user_lat_node->getDoubleValue();
325         IC.lon =        _user_lon_node->getDoubleValue();
326         IC.alt =        _user_alt_node->getDoubleValue();
327         IC.roll =       _user_roll_node->getDoubleValue();    // rotation about x axis
328         IC.elevation =  _user_pitch_node->getDoubleValue();   // rotation about y axis
329         IC.azimuth =    _user_heading_node->getDoubleValue(); // rotation about z axis
330         IC.speed =           _user_speed_node->getDoubleValue();
331         IC.speed_down_fps =   _user_speed_down_fps_node->getDoubleValue();
332         IC.speed_east_fps =   _user_speed_east_fps_node->getDoubleValue();
333         IC.speed_north_fps =  _user_speed_north_fps_node->getDoubleValue();
334
335     } else {
336         // set the data for a submodel tied to an AI Object
337         sm_list_iterator sm_list_itr = sm_list.begin();
338         sm_list_iterator end = sm_list.end();
339
340         while (sm_list_itr != end) {
341             int id = (*sm_list_itr)->getID();
342
343             if (ind != id) {
344                 ++sm_list_itr;
345                 continue;
346             }
347
348             //cout << "found id " << id << endl;
349             IC.lat             = (*sm_list_itr)->_getLatitude();
350             IC.lon             = (*sm_list_itr)->_getLongitude();
351             IC.alt             = (*sm_list_itr)->_getAltitude();
352             IC.roll            = (*sm_list_itr)->_getRoll();
353             IC.elevation       = (*sm_list_itr)->_getPitch();
354             IC.azimuth         = (*sm_list_itr)->_getHeading();
355             IC.alt             = (*sm_list_itr)->_getAltitude();
356             IC.speed           = (*sm_list_itr)->_getSpeed() * SG_KT_TO_FPS;
357             IC.speed_down_fps  = -(*sm_list_itr)->_getVS_fps();
358             IC.speed_east_fps  = (*sm_list_itr)->_get_speed_east_fps();
359             IC.speed_north_fps = (*sm_list_itr)->_get_speed_north_fps();
360
361             ++sm_list_itr;
362         }
363
364     }
365
366     /*cout << "heading " << IC.azimuth << endl ;
367     cout << "speed down " << IC.speed_down_fps << endl ;
368     cout << "speed east " << IC.speed_east_fps << endl ;
369     cout << "speed north " << IC.speed_north_fps << endl ;
370     cout << "parent speed fps in" << IC.speed << "sm speed in " << sm->speed << endl ;*/
371
372     IC.wind_from_east =  _user_wind_from_east_node->getDoubleValue();
373     IC.wind_from_north = _user_wind_from_north_node->getDoubleValue();
374
375     in[0] = sm->x_offset;
376     in[1] = sm->y_offset;
377     in[2] = sm->z_offset;
378
379     // pre-process the trig functions
380     cosRx = cos(-IC.roll * SG_DEGREES_TO_RADIANS);
381     sinRx = sin(-IC.roll * SG_DEGREES_TO_RADIANS);
382     cosRy = cos(-IC.elevation * SG_DEGREES_TO_RADIANS);
383     sinRy = sin(-IC.elevation * SG_DEGREES_TO_RADIANS);
384     cosRz = cos(IC.azimuth * SG_DEGREES_TO_RADIANS);
385     sinRz = sin(IC.azimuth * SG_DEGREES_TO_RADIANS);
386
387     // set up the transform matrix
388     trans[0][0] =  cosRy * cosRz;
389     trans[0][1] =  -1 * cosRx * sinRz + sinRx * sinRy * cosRz ;
390     trans[0][2] =  sinRx * sinRz + cosRx * sinRy * cosRz;
391
392     trans[1][0] =  cosRy * sinRz;
393     trans[1][1] =  cosRx * cosRz + sinRx * sinRy * sinRz;
394     trans[1][2] =  -1 * sinRx * cosRx + cosRx * sinRy * sinRz;
395
396     trans[2][0] =  -1 * sinRy;
397     trans[2][1] =  sinRx * cosRy;
398     trans[2][2] =  cosRx * cosRy;
399
400
401     // multiply the input and transform matrices
402     out[0] = in[0] * trans[0][0] + in[1] * trans[0][1] + in[2] * trans[0][2];
403     out[1] = in[0] * trans[1][0] + in[1] * trans[1][1] + in[2] * trans[1][2];
404     out[2] = in[0] * trans[2][0] + in[1] * trans[2][1] + in[2] * trans[2][2];
405
406     // convert ft to degrees of latitude
407     out[0] = out[0] / (366468.96 - 3717.12 * cos(IC.lat * SG_DEGREES_TO_RADIANS));
408
409     // convert ft to degrees of longitude
410     out[1] = out[1] / (365228.16 * cos(IC.lat * SG_DEGREES_TO_RADIANS));
411
412     // set submodel initial position
413     IC.lat += out[0];
414     IC.lon += out[1];
415     IC.alt += out[2];
416
417     // get aircraft velocity vector angles in XZ and XY planes
418     //double alpha = _user_alpha_node->getDoubleValue();
419     //double velXZ = IC.elevation - alpha * cosRx;
420     //double velXY = IC.azimuth - (IC.elevation - alpha * sinRx);
421
422     // Get submodel initial velocity vector angles in XZ and XY planes.
423     // This needs to be fixed. This vector should be added to aircraft's vector.
424     IC.elevation += (sm->yaw_offset * sinRx) + (sm->pitch_offset * cosRx);
425     IC.azimuth   += (sm->yaw_offset * cosRx) - (sm->pitch_offset * sinRx);
426
427     // calcuate the total speed north
428     IC.total_speed_north = sm->speed * cos(IC.elevation * SG_DEGREES_TO_RADIANS)
429             * cos(IC.azimuth * SG_DEGREES_TO_RADIANS) + IC.speed_north_fps;
430
431     // calculate the total speed east
432     IC.total_speed_east = sm->speed * cos(IC.elevation * SG_DEGREES_TO_RADIANS)
433             * sin(IC.azimuth * SG_DEGREES_TO_RADIANS) + IC.speed_east_fps;
434
435     // calculate the total speed down
436     IC.total_speed_down = sm->speed * -sin(IC.elevation * SG_DEGREES_TO_RADIANS)
437             + IC.speed_down_fps;
438
439     // re-calculate speed, elevation and azimuth
440     IC.speed = sqrt(IC.total_speed_north * IC.total_speed_north
441             + IC.total_speed_east * IC.total_speed_east
442             + IC.total_speed_down * IC.total_speed_down);
443
444     //cout << " speed fps out" << IC.speed << endl ;
445     IC.azimuth = atan(IC.total_speed_east / IC.total_speed_north) * SG_RADIANS_TO_DEGREES;
446
447     // rationalise the output
448     if (IC.total_speed_north <= 0) {
449         IC.azimuth = 180 + IC.azimuth;
450     } else {
451
452         if (IC.total_speed_east <= 0)
453             IC.azimuth = 360 + IC.azimuth;
454
455     }
456
457     IC.elevation = -atan(IC.total_speed_down / sqrt(IC.total_speed_north
458             * IC.total_speed_north + IC.total_speed_east * IC.total_speed_east))
459             * SG_RADIANS_TO_DEGREES;
460
461 }
462
463 void FGSubmodelMgr::updatelat(double lat)
464 {
465     ft_per_deg_latitude = 366468.96 - 3717.12 * cos(lat / SG_RADIANS_TO_DEGREES);
466     ft_per_deg_longitude = 365228.16 * cos(lat / SG_RADIANS_TO_DEGREES);
467 }
468
469 void FGSubmodelMgr::loadAI()
470 {
471     SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading AI submodels ");
472     SGPropertyNode root;
473     sm_list = ai->get_ai_list();
474
475     if (sm_list.empty()) {
476         SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Unable to read AI submodel list");
477         return;
478     }
479
480     sm_list_iterator sm_list_itr = sm_list.begin();
481     sm_list_iterator end = sm_list.end();
482
483     while (sm_list_itr != end) {
484         string path = (*sm_list_itr)->_getPath();
485         bool serviceable = (*sm_list_itr)->_getServiceable();
486         if (path.empty()) {
487             ++sm_list_itr;
488             continue;
489         }
490
491         //cout << " path " << path << " serviceable " << serviceable << endl;
492
493         SGPath config(globals->get_fg_root());
494         config.append(path);
495         int id = (*sm_list_itr)->getID();
496
497         //cout << "id: " << id << endl;
498
499         try {
500             SG_LOG(SG_GENERAL, SG_DEBUG,
501                    "Submodels: Trying to read AI submodels file: " << config.str());
502             readProperties(config.str(), &root);
503         } catch (const sg_exception &e) {
504             SG_LOG(SG_GENERAL, SG_DEBUG,
505                    "Submodels: Unable to read AI submodels file: " << config.str());
506             return;
507         }
508
509         vector<SGPropertyNode_ptr> children = root.getChildren("submodel");
510         vector<SGPropertyNode_ptr>::iterator it = children.begin();
511         vector<SGPropertyNode_ptr>::iterator end = children.end();
512
513         for (int i = 0; it != end; ++it, i++) {
514             //cout << "Reading AI submodel " << (*it)->getPath() << endl;
515             submodel* sm = new submodel;
516             SGPropertyNode * entry_node = *it;
517             sm->name            = entry_node->getStringValue("name", "none_defined");
518             sm->model           = entry_node->getStringValue("model", "Models/Geometry/rocket.ac");
519             sm->speed           = entry_node->getDoubleValue("speed", 2329.4);
520             sm->repeat          = entry_node->getBoolValue("repeat", false);
521             sm->delay           = entry_node->getDoubleValue("delay", 0.25);
522             sm->count           = entry_node->getIntValue("count", 1);
523             sm->slaved          = entry_node->getBoolValue("slaved", false);
524             sm->x_offset        = entry_node->getDoubleValue("x-offset", 0.0);
525             sm->y_offset        = entry_node->getDoubleValue("y-offset", 0.0);
526             sm->z_offset        = entry_node->getDoubleValue("z-offset", 0.0);
527             sm->yaw_offset      = entry_node->getDoubleValue("yaw-offset", 0.0);
528             sm->pitch_offset    = entry_node->getDoubleValue("pitch-offset", 0.0);
529             sm->drag_area       = entry_node->getDoubleValue("eda", 0.034);
530             sm->life            = entry_node->getDoubleValue("life", 900.0);
531             sm->buoyancy        = entry_node->getDoubleValue("buoyancy", 0);
532             sm->wind            = entry_node->getBoolValue("wind", false);
533             sm->cd              = entry_node->getDoubleValue("cd", 0.193);
534             sm->weight          = entry_node->getDoubleValue("weight", 0.25);
535             sm->aero_stabilised = entry_node->getBoolValue("aero-stabilised", true);
536             sm->no_roll         = entry_node->getBoolValue("no-roll", false);
537             sm->contents_node   = fgGetNode(entry_node->getStringValue("contents", "none"), false);
538             sm->trigger_node    = fgGetNode(entry_node->getStringValue("trigger", "none"), false);
539             sm->speed_node      = fgGetNode(entry_node->getStringValue("speed-node", "none"), false);
540
541             //cout <<  "sm->contents_node " << sm->contents_node << endl;
542             if (sm->contents_node != 0)
543                 sm->contents = sm->contents_node->getDoubleValue();
544             //cout <<  "sm->trigger_node " << sm->trigger_node << endl;
545             if (sm->trigger_node != 0)
546                 sm->trigger_node->setBoolValue(false);
547
548             if (sm->speed_node != 0)
549                 sm->speed = sm->speed_node->getDoubleValue();
550
551             sm->timer = sm->delay;
552             sm->id = id;
553             sm->first_time = false;
554
555             sm->serviceable = (*sm_list_itr)->_getServiceable();
556
557             sm->prop = fgGetNode("/ai/submodels/submodel", index, true);
558             sm->prop->tie("count", SGRawValuePointer<int>(&(sm->count)));
559             sm->prop->tie("repeat", SGRawValuePointer<bool>(&(sm->repeat)));
560             sm->prop->tie("id", SGRawValuePointer<int>(&(sm->id)));
561             sm->prop->tie("serviceable", SGRawValuePointer<bool>(&(sm->serviceable)));
562             string name = sm->name;
563             sm->prop->setStringValue("name", name.c_str());
564
565             if (sm->contents_node != 0)
566                 sm->prop->tie("contents-lbs", SGRawValuePointer<double>(&(sm->contents)));
567
568             index++;
569             submodels.push_back(sm);
570         }
571
572         submodel_iterator = submodels.begin();
573         ++sm_list_itr;
574     }
575
576 }
577
578 double FGSubmodelMgr::getRange(double lat, double lon, double lat2, double lon2) const
579 {
580
581     double course, distance, az2;
582
583     //calculate the bearing and range of the second pos from the first
584     geo_inverse_wgs_84(lat, lon, lat2, lon2, &course, &az2, &distance);
585     distance *= SG_METER_TO_NM;
586     return distance;
587 }
588 // end of submodel.cxx