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