1 // submodel.cxx - models a releasable submodel.
2 // Written by Dave Culp, started Aug 2004
3 // With major additions by Vivian Meaaza 2004 - 2007
5 // This file is in the Public Domain and comes with no warranty.
11 #include "submodel.hxx"
13 #include <simgear/structure/exception.hxx>
14 #include <simgear/misc/sg_path.hxx>
15 #include <simgear/math/sg_geodesy.hxx>
17 #include <Main/fg_props.hxx>
18 #include <Main/util.hxx>
22 #include "AIManager.hxx"
23 #include "AIBallistic.hxx"
26 const double FGSubmodelMgr::lbs_to_slugs = 0.031080950172;
28 FGSubmodelMgr::FGSubmodelMgr()
30 x_offset = y_offset = 0.0;
35 out[0] = out[1] = out[2] = 0;
38 contrail_altitude = 30000;
42 FGSubmodelMgr::~FGSubmodelMgr()
46 void FGSubmodelMgr::init()
50 _serviceable_node = fgGetNode("/sim/submodels/serviceable", true);
51 _serviceable_node->setBoolValue(true);
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);
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);
63 _user_speed_node = fgGetNode("/velocities/uBody-fps", true);
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);
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);
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);
77 ai = (FGAIManager*)globals->get_subsystem("ai_model");
82 void FGSubmodelMgr::postinit() {
83 // postinit, so that the AI list is populated
87 //TODO reload submodels if an MP ac joins
90 void FGSubmodelMgr::bind()
93 void FGSubmodelMgr::unbind()
95 submodel_iterator = submodels.begin();
96 while (submodel_iterator != submodels.end()) {
97 (*submodel_iterator)->prop->untie("count");
102 void FGSubmodelMgr::update(double dt)
104 if (!_serviceable_node->getBoolValue())
110 // check if the submodel hit an object or terrain
111 sm_list = ai->get_ai_list();
112 sm_list_iterator sm_list_itr = sm_list.begin();
113 sm_list_iterator end = sm_list.end();
115 for (; sm_list_itr != end; ++sm_list_itr) {
116 _impact = (*sm_list_itr)->_getImpactData();
117 _hit = (*sm_list_itr)->_getCollisionData();
118 int parent_subID = (*sm_list_itr)->_getSubID();
120 if ( parent_subID == 0) // this entry in the list has no associated submodel
121 continue; // so we can continue
123 if (_impact || _hit) {
124 SG_LOG(SG_GENERAL, SG_ALERT, "Submodel: Impact " << _impact << " hit! " << _hit );
126 submodel_iterator = submodels.begin();
128 while (submodel_iterator != submodels.end()) {
129 int child_ID = (*submodel_iterator)->id;
130 cout << "Impact: parent SubID " << parent_subID << " child_ID " << child_ID << endl;
132 if ( parent_subID == child_ID ) {
133 _parent_lat = (*sm_list_itr)->_getImpactLat();
134 _parent_lon = (*sm_list_itr)->_getImpactLon();
135 _parent_elev = (*sm_list_itr)->_getImpactElevFt();
136 _parent_hdg = (*sm_list_itr)->_getImpactHdg();
137 _parent_pitch = (*sm_list_itr)->_getImpactPitch();
138 _parent_roll = (*sm_list_itr)->_getImpactRoll();
139 _parent_speed = (*sm_list_itr)->_getImpactSpeed();
140 (*submodel_iterator)->first_time = true;
142 if (release(*submodel_iterator, dt))
143 (*sm_list_itr)->setDie(true);
151 _contrail_trigger->setBoolValue(_user_alt_node->getDoubleValue() > contrail_altitude);
154 bool in_range = true;
155 bool trigger = false;
158 submodel_iterator = submodels.begin();
159 while (submodel_iterator != submodels.end()) {
163 SG_LOG(SG_GENERAL, SG_DEBUG,
164 "Submodels: " << (*submodel_iterator)->id
165 << " name " << (*submodel_iterator)->name
166 << " in range " << in_range
169 if ((*submodel_iterator)->trigger_node != 0) {
170 _trigger_node = (*submodel_iterator)->trigger_node;
171 trigger = _trigger_node->getBoolValue();
172 //cout << "trigger node found " << trigger << endl;
175 //cout << (*submodel_iterator)->name << "trigger node not found " << trigger << endl;
179 int id = (*submodel_iterator)->id;
180 string name = (*submodel_iterator)->name;
181 // don't release submodels from AI Objects if they are
182 // too far away to be seen. id 0 is not an AI model,
183 // so we can skip the whole process
184 sm_list_iterator sm_list_itr = sm_list.begin();
185 sm_list_iterator end = sm_list.end();
187 while (sm_list_itr != end) {
190 SG_LOG(SG_GENERAL, SG_DEBUG,
191 "Submodels: continuing: " << id << " name " << name );
197 int parent_id = (*submodel_iterator)->id;
199 if (parent_id == id) {
200 double parent_lat = (*sm_list_itr)->_getLatitude();
201 double parent_lon = (*sm_list_itr)->_getLongitude();
202 double own_lat = _user_lat_node->getDoubleValue();
203 double own_lon = _user_lon_node->getDoubleValue();
204 double range_nm = getRange(parent_lat, parent_lon, own_lat, own_lon);
205 // cout << "parent " << parent_id << ", "<< parent_lat << ", " << parent_lon << endl;
206 //cout << "own " << own_lat << ", " << own_lon << " range " << range_nm << endl;
209 SG_LOG(SG_GENERAL, SG_DEBUG,
210 "Submodels: skipping release: " << id);
219 SG_LOG(SG_GENERAL, SG_DEBUG,
220 "Submodels end: " << (*submodel_iterator)->id
221 << " name " << (*submodel_iterator)->name
222 << " count " << (*submodel_iterator)->count
223 << " in range " << in_range
226 if ((*submodel_iterator)->count != 0 && in_range)
227 release(*submodel_iterator, dt);
230 (*submodel_iterator)->first_time = true;
236 bool FGSubmodelMgr::release(submodel *sm, double dt)
238 //cout << "release id " << sm->id << " name " << sm->name
239 //<< " first time " << sm->first_time << " repeat " << (*sm)->repeat <<
242 // only run if first time or repeat is set to true
243 if (!sm->first_time && !sm->repeat) {
244 //cout<< "not first time " << sm->first_time<< " repeat " << sm->repeat <<endl;
250 if (sm->timer < sm->delay) {
251 //cout << "not yet: timer" << sm->timer << " delay " << sm->delay<< endl;
257 if (sm->first_time) {
259 sm->first_time = false;
262 transform(sm); // calculate submodel's initial conditions in world-coordinates
264 FGAIBallistic* ballist = new FGAIBallistic;
265 ballist->setPath(sm->model.c_str());
266 ballist->setLatitude(IC.lat);
267 ballist->setLongitude(IC.lon);
268 ballist->setAltitude(IC.alt);
269 ballist->setAzimuth(IC.azimuth);
270 ballist->setElevation(IC.elevation);
271 ballist->setRoll(IC.roll);
272 ballist->setSpeed(IC.speed / SG_KT_TO_FPS);
273 ballist->setWind_from_east(IC.wind_from_east);
274 ballist->setWind_from_north(IC.wind_from_north);
275 ballist->setMass(IC.mass);
276 ballist->setDragArea(sm->drag_area);
277 ballist->setLife(sm->life);
278 ballist->setBuoyancy(sm->buoyancy);
279 ballist->setWind(sm->wind);
280 ballist->setCd(sm->cd);
281 ballist->setStabilisation(sm->aero_stabilised);
282 ballist->setNoRoll(sm->no_roll);
283 ballist->setName(sm->name);
284 ballist->setCollision(sm->collision);
285 ballist->setImpact(sm->impact);
286 ballist->setImpactReportNode(sm->impact_report);
287 ballist->setFuseRange(sm->fuse_range);
288 ballist->setSubmodel(sm->submodel.c_str());
289 ballist->setSubID(sm->sub_id);
298 void FGSubmodelMgr::load()
302 SGPropertyNode *path = fgGetNode("/sim/submodels/path");
306 string Path = path->getStringValue();
307 bool Seviceable =_serviceable_node->getBoolValue();
308 setData(id, Path, Seviceable);
312 void FGSubmodelMgr::transform(submodel *sm)
314 // set initial conditions
315 if (sm->contents_node != 0) {
316 // get the weight of the contents (lbs) and convert to mass (slugs)
317 sm->contents = sm->contents_node->getDoubleValue();
318 IC.mass = (sm->weight + sm->contents) * lbs_to_slugs;
320 // set contents to 0 in the parent
321 sm->contents_node->setDoubleValue(0);
323 IC.mass = sm->weight * lbs_to_slugs;
325 // cout << "mass " << IC.mass << endl;
327 if (sm->speed_node != 0)
328 sm->speed = sm->speed_node->getDoubleValue();
331 //int sub_id = (*submodel)->sub_id;
332 string name = sm->name;
334 //cout << " name " << name << " id " << id << " sub id" << sub_id << endl;
336 if (_impact || _hit) {
337 // set the data for a submodel tied to a submodel
339 //cout << "Submodels: release sub sub " << _count<< endl;
340 //cout << " id " << sm->id
341 // << " lat " << _parent_lat
342 // << " lon " << _parent_lon
343 // << " elev " << _parent_elev
344 // << " name " << sm->name
347 IC.lat = _parent_lat;
348 IC.lon = _parent_lon;
349 IC.alt = _parent_elev;
350 IC.roll = _parent_roll; // rotation about x axis
351 IC.elevation = _parent_pitch; // rotation about y axis
352 IC.azimuth = _parent_hdg; // rotation about z axis
353 IC.speed = _parent_speed;
354 IC.speed_down_fps = 0;
355 IC.speed_east_fps = 0;
356 IC.speed_north_fps = 0;
358 } else if (id == 0) {
359 //set the data for a submodel tied to the main model
360 /*cout << "Submodels: release main sub " << endl;
361 cout << " name " << sm->name
364 IC.lat = _user_lat_node->getDoubleValue();
365 IC.lon = _user_lon_node->getDoubleValue();
366 IC.alt = _user_alt_node->getDoubleValue();
367 IC.roll = _user_roll_node->getDoubleValue(); // rotation about x axis
368 IC.elevation = _user_pitch_node->getDoubleValue(); // rotation about y axis
369 IC.azimuth = _user_heading_node->getDoubleValue(); // rotation about z axis
370 IC.speed = _user_speed_node->getDoubleValue();
371 IC.speed_down_fps = _user_speed_down_fps_node->getDoubleValue();
372 IC.speed_east_fps = _user_speed_east_fps_node->getDoubleValue();
373 IC.speed_north_fps = _user_speed_north_fps_node->getDoubleValue();
376 // set the data for a submodel tied to an AI Object
377 sm_list_iterator sm_list_itr = sm_list.begin();
378 sm_list_iterator end = sm_list.end();
380 while (sm_list_itr != end) {
381 int parent_id = (*sm_list_itr)->getID();
383 if (id != parent_id) {
388 //cout << "found id " << id << endl;
389 IC.lat = (*sm_list_itr)->_getLatitude();
390 IC.lon = (*sm_list_itr)->_getLongitude();
391 IC.alt = (*sm_list_itr)->_getAltitude();
392 IC.roll = (*sm_list_itr)->_getRoll();
393 IC.elevation = (*sm_list_itr)->_getPitch();
394 IC.azimuth = (*sm_list_itr)->_getHeading();
395 IC.alt = (*sm_list_itr)->_getAltitude();
396 IC.speed = (*sm_list_itr)->_getSpeed() * SG_KT_TO_FPS;
397 IC.speed_down_fps = -(*sm_list_itr)->_getVS_fps();
398 IC.speed_east_fps = (*sm_list_itr)->_get_speed_east_fps();
399 IC.speed_north_fps = (*sm_list_itr)->_get_speed_north_fps();
405 /*cout << "heading " << IC.azimuth << endl ;
406 cout << "speed down " << IC.speed_down_fps << endl ;
407 cout << "speed east " << IC.speed_east_fps << endl ;
408 cout << "speed north " << IC.speed_north_fps << endl ;
409 cout << "parent speed fps in" << IC.speed << "sm speed in " << sm->speed << endl ;*/
411 IC.wind_from_east = _user_wind_from_east_node->getDoubleValue();
412 IC.wind_from_north = _user_wind_from_north_node->getDoubleValue();
414 in[0] = sm->x_offset;
415 in[1] = sm->y_offset;
416 in[2] = sm->z_offset;
418 // pre-process the trig functions
419 cosRx = cos(-IC.roll * SG_DEGREES_TO_RADIANS);
420 sinRx = sin(-IC.roll * SG_DEGREES_TO_RADIANS);
421 cosRy = cos(-IC.elevation * SG_DEGREES_TO_RADIANS);
422 sinRy = sin(-IC.elevation * SG_DEGREES_TO_RADIANS);
423 cosRz = cos(IC.azimuth * SG_DEGREES_TO_RADIANS);
424 sinRz = sin(IC.azimuth * SG_DEGREES_TO_RADIANS);
426 // set up the transform matrix
427 trans[0][0] = cosRy * cosRz;
428 trans[0][1] = -1 * cosRx * sinRz + sinRx * sinRy * cosRz ;
429 trans[0][2] = sinRx * sinRz + cosRx * sinRy * cosRz;
431 trans[1][0] = cosRy * sinRz;
432 trans[1][1] = cosRx * cosRz + sinRx * sinRy * sinRz;
433 trans[1][2] = -1 * sinRx * cosRx + cosRx * sinRy * sinRz;
435 trans[2][0] = -1 * sinRy;
436 trans[2][1] = sinRx * cosRy;
437 trans[2][2] = cosRx * cosRy;
440 // multiply the input and transform matrices
441 out[0] = in[0] * trans[0][0] + in[1] * trans[0][1] + in[2] * trans[0][2];
442 out[1] = in[0] * trans[1][0] + in[1] * trans[1][1] + in[2] * trans[1][2];
443 out[2] = in[0] * trans[2][0] + in[1] * trans[2][1] + in[2] * trans[2][2];
445 // convert ft to degrees of latitude
446 out[0] = out[0] / (366468.96 - 3717.12 * cos(IC.lat * SG_DEGREES_TO_RADIANS));
448 // convert ft to degrees of longitude
449 out[1] = out[1] / (365228.16 * cos(IC.lat * SG_DEGREES_TO_RADIANS));
451 // set submodel initial position
456 // get aircraft velocity vector angles in XZ and XY planes
457 //double alpha = _user_alpha_node->getDoubleValue();
458 //double velXZ = IC.elevation - alpha * cosRx;
459 //double velXY = IC.azimuth - (IC.elevation - alpha * sinRx);
461 // Get submodel initial velocity vector angles in XZ and XY planes.
462 // This needs to be fixed. This vector should be added to aircraft's vector.
463 IC.elevation += (sm->yaw_offset * sinRx) + (sm->pitch_offset * cosRx);
464 IC.azimuth += (sm->yaw_offset * cosRx) - (sm->pitch_offset * sinRx);
466 // calculate the total speed north
467 IC.total_speed_north = sm->speed * cos(IC.elevation * SG_DEGREES_TO_RADIANS)
468 * cos(IC.azimuth * SG_DEGREES_TO_RADIANS) + IC.speed_north_fps;
470 // calculate the total speed east
471 IC.total_speed_east = sm->speed * cos(IC.elevation * SG_DEGREES_TO_RADIANS)
472 * sin(IC.azimuth * SG_DEGREES_TO_RADIANS) + IC.speed_east_fps;
474 // calculate the total speed down
475 IC.total_speed_down = sm->speed * -sin(IC.elevation * SG_DEGREES_TO_RADIANS)
478 // re-calculate speed, elevation and azimuth
479 IC.speed = sqrt(IC.total_speed_north * IC.total_speed_north
480 + IC.total_speed_east * IC.total_speed_east
481 + IC.total_speed_down * IC.total_speed_down);
483 // if speeds are low this calculation can become unreliable
485 IC.azimuth = atan2(IC.total_speed_east , IC.total_speed_north) * SG_RADIANS_TO_DEGREES;
486 // cout << "azimuth1 " << IC.azimuth<<endl;
488 // rationalise the output
491 else if (IC.azimuth >= 360)
495 // cout << "azimuth2 " << IC.azimuth<<endl;
497 IC.elevation = -atan(IC.total_speed_down / sqrt(IC.total_speed_north
498 * IC.total_speed_north + IC.total_speed_east * IC.total_speed_east))
499 * SG_RADIANS_TO_DEGREES;
502 void FGSubmodelMgr::updatelat(double lat)
504 ft_per_deg_latitude = 366468.96 - 3717.12 * cos(lat / SG_RADIANS_TO_DEGREES);
505 ft_per_deg_longitude = 365228.16 * cos(lat / SG_RADIANS_TO_DEGREES);
508 void FGSubmodelMgr::loadAI()
510 SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading AI submodels ");
512 sm_list = ai->get_ai_list();
514 if (sm_list.empty()) {
515 SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Unable to read AI submodel list");
519 sm_list_iterator sm_list_itr = sm_list.begin();
520 sm_list_iterator end = sm_list.end();
522 while (sm_list_itr != end) {
523 string path = (*sm_list_itr)->_getPath();
530 int id = (*sm_list_itr)->getID();
531 bool serviceable = (*sm_list_itr)->_getServiceable();
532 setData(id, path, serviceable);
538 double FGSubmodelMgr::getRange(double lat, double lon, double lat2, double lon2) const
540 double course, distance, az2;
542 //calculate the bearing and range of the second pos from the first
543 geo_inverse_wgs_84(lat, lon, lat2, lon2, &course, &az2, &distance);
544 distance *= SG_METER_TO_NM;
548 void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
552 SGPath config(globals->get_fg_root());
554 SG_LOG(SG_GENERAL, SG_DEBUG,
555 "Submodels: path " << path);
557 SG_LOG(SG_GENERAL, SG_DEBUG,
558 "Submodels: Trying to read AI submodels file: " << config.str());
559 readProperties(config.str(), &root);
560 } catch (const sg_exception &e) {
561 SG_LOG(SG_GENERAL, SG_DEBUG,
562 "Submodels: Unable to read AI submodels file: " << config.str());
566 vector<SGPropertyNode_ptr> children = root.getChildren("submodel");
567 vector<SGPropertyNode_ptr>::iterator it = children.begin();
568 vector<SGPropertyNode_ptr>::iterator end = children.end();
570 for (int i = 0; it != end; ++it, i++) {
571 //cout << "Reading AI submodel " << (*it)->getPath() << endl;
572 submodel* sm = new submodel;
573 SGPropertyNode * entry_node = *it;
574 sm->name = entry_node->getStringValue("name", "none_defined");
575 sm->model = entry_node->getStringValue("model", "Models/Geometry/rocket.ac");
576 sm->speed = entry_node->getDoubleValue("speed", 2329.4);
577 sm->repeat = entry_node->getBoolValue("repeat", false);
578 sm->delay = entry_node->getDoubleValue("delay", 0.25);
579 sm->count = entry_node->getIntValue("count", 1);
580 sm->slaved = entry_node->getBoolValue("slaved", false);
581 sm->x_offset = entry_node->getDoubleValue("x-offset", 0.0);
582 sm->y_offset = entry_node->getDoubleValue("y-offset", 0.0);
583 sm->z_offset = entry_node->getDoubleValue("z-offset", 0.0);
584 sm->yaw_offset = entry_node->getDoubleValue("yaw-offset", 0.0);
585 sm->pitch_offset = entry_node->getDoubleValue("pitch-offset", 0.0);
586 sm->drag_area = entry_node->getDoubleValue("eda", 0.034);
587 sm->life = entry_node->getDoubleValue("life", 900.0);
588 sm->buoyancy = entry_node->getDoubleValue("buoyancy", 0);
589 sm->wind = entry_node->getBoolValue("wind", false);
590 sm->cd = entry_node->getDoubleValue("cd", 0.193);
591 sm->weight = entry_node->getDoubleValue("weight", 0.25);
592 sm->aero_stabilised = entry_node->getBoolValue("aero-stabilised", true);
593 sm->no_roll = entry_node->getBoolValue("no-roll", false);
594 sm->collision = entry_node->getBoolValue("collision", false);
595 sm->impact = entry_node->getBoolValue("impact", false);
596 sm->impact_report = entry_node->getStringValue("impact-reports");
597 sm->fuse_range = entry_node->getDoubleValue("fuse-range", 0.0);
598 sm->contents_node = fgGetNode(entry_node->getStringValue("contents", "none"), false);
599 sm->speed_node = fgGetNode(entry_node->getStringValue("speed-node", "none"), false);
600 sm->submodel = entry_node->getStringValue("submodel-path", "");
602 //cout << "sm->contents_node " << sm->contents_node << endl;
603 if (sm->contents_node != 0)
604 sm->contents = sm->contents_node->getDoubleValue();
606 const char *trigger_path = entry_node->getStringValue("trigger", 0);
608 sm->trigger_node = fgGetNode(trigger_path, true);
609 sm->trigger_node->setBoolValue(sm->trigger_node->getBoolValue());
611 sm->trigger_node = 0;
614 if (sm->speed_node != 0)
615 sm->speed = sm->speed_node->getDoubleValue();
617 sm->timer = sm->delay;
619 sm->first_time = false;
620 sm->serviceable = serviceable;
623 sm->prop = fgGetNode("/ai/submodels/submodel", index, true);
624 sm->prop->tie("count", SGRawValuePointer<int>(&(sm->count)));
625 sm->prop->tie("repeat", SGRawValuePointer<bool>(&(sm->repeat)));
626 sm->prop->tie("id", SGRawValuePointer<int>(&(sm->id)));
627 sm->prop->tie("sub-id", SGRawValuePointer<int>(&(sm->sub_id)));
629 sm->prop->tie("serviceable", SGRawValuePointer<bool>(&(sm->serviceable)));
630 string name = sm->name;
631 sm->prop->setStringValue("name", name.c_str());
633 string submodel = sm->submodel;
634 sm->prop->setStringValue("submodel", submodel.c_str());
635 //cout << " set submodel path " << submodel << endl;
637 if (sm->contents_node != 0)
638 sm->prop->tie("contents-lbs", SGRawValuePointer<double>(&(sm->contents)));
641 submodels.push_back(sm);
645 void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
649 SGPath config(globals->get_fg_root());
651 SG_LOG(SG_GENERAL, SG_DEBUG,
652 "Submodels: path " << path);
654 SG_LOG(SG_GENERAL, SG_DEBUG,
655 "Submodels: Trying to read AI submodels file: " << config.str());
656 readProperties(config.str(), &root);
658 } catch (const sg_exception &e) {
659 SG_LOG(SG_GENERAL, SG_DEBUG,
660 "Submodels: Unable to read AI submodels file: " << config.str());
664 vector<SGPropertyNode_ptr> children = root.getChildren("submodel");
665 vector<SGPropertyNode_ptr>::iterator it = children.begin();
666 vector<SGPropertyNode_ptr>::iterator end = children.end();
668 for (int i = 0; it != end; ++it, i++) {
669 //cout << "Reading AI submodel " << (*it)->getPath() << endl;
670 submodel* sm = new submodel;
671 SGPropertyNode * entry_node = *it;
672 sm->name = entry_node->getStringValue("name", "none_defined");
673 sm->model = entry_node->getStringValue("model", "Models/Geometry/rocket.ac");
674 sm->speed = entry_node->getDoubleValue("speed", 2329.4);
675 sm->repeat = entry_node->getBoolValue("repeat", false);
676 sm->delay = entry_node->getDoubleValue("delay", 0.25);
677 sm->count = entry_node->getIntValue("count", 1);
678 sm->slaved = entry_node->getBoolValue("slaved", false);
679 sm->x_offset = entry_node->getDoubleValue("x-offset", 0.0);
680 sm->y_offset = entry_node->getDoubleValue("y-offset", 0.0);
681 sm->z_offset = entry_node->getDoubleValue("z-offset", 0.0);
682 sm->yaw_offset = entry_node->getDoubleValue("yaw-offset", 0.0);
683 sm->pitch_offset = entry_node->getDoubleValue("pitch-offset", 0.0);
684 sm->drag_area = entry_node->getDoubleValue("eda", 0.034);
685 sm->life = entry_node->getDoubleValue("life", 900.0);
686 sm->buoyancy = entry_node->getDoubleValue("buoyancy", 0);
687 sm->wind = entry_node->getBoolValue("wind", false);
688 sm->cd = entry_node->getDoubleValue("cd", 0.193);
689 sm->weight = entry_node->getDoubleValue("weight", 0.25);
690 sm->aero_stabilised = entry_node->getBoolValue("aero-stabilised", true);
691 sm->no_roll = entry_node->getBoolValue("no-roll", false);
692 sm->collision = entry_node->getBoolValue("collision", false);
693 sm->impact = entry_node->getBoolValue("impact", false);
694 sm->impact_report = entry_node->getStringValue("impact-reports");
695 sm->fuse_range = entry_node->getDoubleValue("fuse-range", 0.0);
696 sm->contents_node = fgGetNode(entry_node->getStringValue("contents", "none"), false);
697 sm->speed_node = fgGetNode(entry_node->getStringValue("speed-node", "none"), false);
698 sm->submodel = entry_node->getStringValue("submodel-path", "");
700 //cout << "sm->contents_node " << sm->contents_node << endl;
701 if (sm->contents_node != 0)
702 sm->contents = sm->contents_node->getDoubleValue();
704 const char *trigger_path = entry_node->getStringValue("trigger", 0);
706 sm->trigger_node = fgGetNode(trigger_path, true);
707 sm->trigger_node->setBoolValue(sm->trigger_node->getBoolValue());
709 sm->trigger_node = 0;
712 if (sm->speed_node != 0)
713 sm->speed = sm->speed_node->getDoubleValue();
715 sm->timer = sm->delay;
717 sm->first_time = false;
718 sm->serviceable = serviceable;
721 sm->prop = fgGetNode("/ai/submodels/subsubmodel", index, true);
722 sm->prop->tie("count", SGRawValuePointer<int>(&(sm->count)));
723 sm->prop->tie("repeat", SGRawValuePointer<bool>(&(sm->repeat)));
724 sm->prop->tie("id", SGRawValuePointer<int>(&(sm->id)));
725 sm->prop->tie("sub-id", SGRawValuePointer<int>(&(sm->sub_id)));
726 sm->prop->tie("serviceable", SGRawValuePointer<bool>(&(sm->serviceable)));
727 string name = sm->name;
728 sm->prop->setStringValue("name", name.c_str());
730 string submodel = sm->submodel;
731 sm->prop->setStringValue("submodel", submodel.c_str());
732 // cout << " set submodel path " << submodel<< endl;
734 if (sm->contents_node != 0)
735 sm->prop->tie("contents-lbs", SGRawValuePointer<double>(&(sm->contents)));
738 subsubmodels.push_back(sm);
742 void FGSubmodelMgr::loadSubmodels()
744 SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading sub submodels");
746 submodel_iterator = submodels.begin();
748 while (submodel_iterator != submodels.end()) {
749 string submodel = (*submodel_iterator)->submodel;
750 if (!submodel.empty()) {
751 //int id = (*submodel_iterator)->id;
752 bool serviceable = true;
753 SG_LOG(SG_GENERAL, SG_ALERT, "found path sub sub "
755 << " index " << index
756 << "name " << (*submodel_iterator)->name);
758 (*submodel_iterator)->sub_id = index;
759 setSubData(index, submodel, serviceable);
765 subsubmodel_iterator = subsubmodels.begin();
767 while (subsubmodel_iterator != subsubmodels.end()) {
768 submodels.push_back(*subsubmodel_iterator);
769 ++subsubmodel_iterator;
772 submodel_iterator = submodels.begin();
774 while (submodel_iterator != submodels.end()) {
775 int id = (*submodel_iterator)->id;
776 SG_LOG(SG_GENERAL, SG_DEBUG,"after pusback "
778 << " name " << (*submodel_iterator)->name
779 << " sub id " << (*submodel_iterator)->sub_id);
785 // end of submodel.cxx