X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAIModel%2FAIBase.cxx;h=33cb073cbd5a3b30c5480fe7d88f8dd5c9e4265c;hb=38226af24ec01e8f0a20d7fd73ef838a69f6ef25;hp=a57b5505d636c4d50ca17048702c93ff56d99ae2;hpb=58a427fb126d753c626e3c9e828be52a14f1c27a;p=flightgear.git diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index a57b5505d..33cb073cb 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -41,9 +41,9 @@ #include
#include +#include #include "AIBase.hxx" -#include "AIModelData.hxx" #include "AIManager.hxx" const char *default_model = "Models/Geometry/glider.ac"; @@ -53,11 +53,14 @@ const double FGAIBase::lbs_to_slugs = 0.031080950172; //conversion factor using namespace simgear; FGAIBase::FGAIBase(object_type ot) : + _max_speed(300), + _name(""), + _parent(""), props( NULL ), model_removed( fgGetNode("/ai/models/model-removed", true) ), manager( NULL ), + _installed(false), fp( NULL ), - _impact_lat(0), _impact_lon(0), _impact_elev(0), @@ -65,10 +68,10 @@ FGAIBase::FGAIBase(object_type ot) : _impact_pitch(0), _impact_roll(0), _impact_speed(0), - _refID( _newAIModelID() ), _otype(ot), _initialized(false) + { tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0; tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0; @@ -81,7 +84,43 @@ FGAIBase::FGAIBase(object_type ot) : delete_me = false; _impact_reported = false; _collision_reported = false; + _expiry_reported = false; + _subID = 0; + + _x_offset = 0; + _y_offset = 0; + _z_offset = 0; + + _pitch_offset = 0; + _roll_offset = 0; + _yaw_offset = 0; + + userpos = SGGeod::fromDeg(0, 0); + + pos = SGGeod::fromDeg(0, 0); + speed = 0; + altitude_ft = 0; + speed_north_deg_sec = 0; + speed_east_deg_sec = 0; + turn_radius_ft = 0; + + ft_per_deg_lon = 0; + ft_per_deg_lat = 0; + + horiz_offset = 0; + vert_offset = 0; + ht_diff = 0; + + serviceable = false; + + fp = 0; + + rho = 1; + T = 280; + p = 1e5; + a = 340; + Mach = 0; } FGAIBase::~FGAIBase() { @@ -156,20 +195,31 @@ void FGAIBase::Transform() { } bool FGAIBase::init(bool search_in_AI_path) { - osg::ref_ptr opt= - new osgDB::ReaderWriter::Options(*osgDB::Registry::instance()->getOptions()); - + + string f; if(search_in_AI_path) { - SGPath ai_path(globals->get_fg_root()); - ai_path.append("AI"); - opt->getDatabasePathList().push_front(ai_path.str()); + // setup a modified Options structure, with only the $fg-root/AI defined; + // we'll check that first, then give the normal search logic a chance. + // this ensures that models in AI/ are preferred to normal models, where + // both exist. + osg::ref_ptr + opt(osg::clone(osgDB::Registry::instance()->getOptions(), osg::CopyOp::SHALLOW_COPY)); + + SGPath ai_path(globals->get_fg_root(), "AI"); + opt->setDatabasePath(ai_path.str()); + + f = osgDB::findDataFile(model_path, opt.get()); } - string f = osgDB::findDataFile(model_path, opt.get()); - + if (f.empty()) { + f = simgear::SGModelLib::findDataFile(model_path); + } + if(f.empty()) f = fgGetString("/sim/multiplay/default-model", default_model); + else + _installed = true; model = load3DModel(f, props); @@ -182,6 +232,8 @@ bool FGAIBase::init(bool search_in_AI_path) { } else if (!model_path.empty()) { SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path); + // not properly installed... + _installed = false; } setDie(false); @@ -190,24 +242,30 @@ bool FGAIBase::init(bool search_in_AI_path) { void FGAIBase::initModel(osg::Node *node) { - if (model.valid()) { - // Disable altitude computations for general AI models. - model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT); + if (model.valid()) { + + if( _path != ""){ + props->setStringValue("submodels/path", _path.c_str()); + SG_LOG(SG_INPUT, SG_DEBUG, "AIBase: submodels/path " << _path); + } - fgSetString("/ai/models/model-added", props->getPath()); + if( _parent!= ""){ + props->setStringValue("parent-name", _parent.c_str()); + } + fgSetString("/ai/models/model-added", props->getPath().c_str()); } else if (!model_path.empty()) { SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path); } - props->setStringValue("submodels/path", _path.c_str()); setDie(false); } osg::Node* FGAIBase::load3DModel(const string &path, SGPropertyNode *prop_root) { - model = SGModelLib::loadPagedModel(path, prop_root, new FGAIModelData(this, prop_root)); + model = SGModelLib::loadPagedModel(path, prop_root, new FGNasalModelData(prop_root)); + initModel(model.get()); return model.get(); } @@ -317,9 +375,16 @@ void FGAIBase::unbind() { props->untie("radar/ht-diff-ft"); props->untie("controls/lighting/nav-lights"); + + props->setBoolValue("/sim/controls/radar/", true); + } double FGAIBase::UpdateRadar(FGAIManager* manager) { + bool control = fgGetBool("/sim/controls/radar", true); + + if(!control) return 0; + double radar_range_ft2 = fgGetDouble("/instrumentation/radar/range"); bool force_on = fgGetBool("/instrumentation/radar/debug-mode", false); radar_range_ft2 *= SG_NM_TO_METER * SG_METER_TO_FEET * 1.1; // + 10% @@ -430,7 +495,7 @@ SGVec3d FGAIBase::getCartPosAt(const SGVec3d& _off) const { hlTrans *= SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll); // The offset converted to the usual body fixed coordinate system - // rotated to the earth fiexed coordinates axis + // rotated to the earth fixed coordinates axis SGVec3d off = hlTrans.backTransform(_off); // Add the position offset of the AIModel to gain the earth centered position @@ -444,6 +509,12 @@ SGVec3d FGAIBase::getCartPos() const { return cartPos; } +bool FGAIBase::getGroundElevationM(const SGGeod& pos, double& elev, + const SGMaterial** material) const { + return globals->get_scenery()->get_elevation_m(pos, elev, material, + model.get()); +} + double FGAIBase::_getCartPosX() const { SGVec3d cartPos = getCartPos(); return cartPos.x(); @@ -477,6 +548,52 @@ void FGAIBase::_setSubID( int s ) { _subID = s; } +bool FGAIBase::setParentNode() { + + if (_parent == ""){ + SG_LOG(SG_GENERAL, SG_ALERT, "AIBase: " << _name + << " parent not set "); + return false; + } + + const SGPropertyNode_ptr ai = fgGetNode("/ai/models", true); + + for (int i = ai->nChildren() - 1; i >= -1; i--) { + SGPropertyNode_ptr model; + + if (i < 0) { // last iteration: selected model + model = _selected_ac; + } else { + model = ai->getChild(i); + string path = ai->getPath(); + const string name = model->getStringValue("name"); + + if (!model->nChildren()){ + continue; + } + if (name == _parent) { + _selected_ac = model; // save selected model for last iteration + break; + } + + } + if (!model) + continue; + + }// end for loop + + if (_selected_ac != 0){ + const string name = _selected_ac->getStringValue("name"); + return true; + } else { + SG_LOG(SG_GENERAL, SG_ALERT, "AIBase: " << _name + << " parent not found: dying "); + setDie(true); + return false; + } + +} + double FGAIBase::_getLongitude() const { return pos.getLongitudeDeg(); } @@ -485,7 +602,7 @@ double FGAIBase::_getLatitude() const { return pos.getLatitudeDeg(); } -double FGAIBase::_getElevationFt () const { +double FGAIBase::_getElevationFt() const { return pos.getElevationFt(); } @@ -494,7 +611,7 @@ double FGAIBase::_getRdot() const { } double FGAIBase::_getVS_fps() const { - return vs*60.0; + return vs/60.0; } double FGAIBase::_get_speed_east_fps() const { @@ -506,13 +623,19 @@ double FGAIBase::_get_speed_north_fps() const { } void FGAIBase::_setVS_fps( double _vs ) { - vs = _vs/60.0; + vs = _vs*60.0; } double FGAIBase::_getAltitude() const { return altitude_ft; } +double FGAIBase::_getAltitudeAGL(SGGeod inpos, double start){ + getGroundElevationM(SGGeod::fromGeodM(inpos, start), + _elevation_m, &_material); + return inpos.getElevationFt() - _elevation_m * SG_METER_TO_FEET; +} + bool FGAIBase::_getServiceable() const { return serviceable; } @@ -533,6 +656,10 @@ bool FGAIBase::_getCollisionData() { return _collision_reported; } +bool FGAIBase::_getExpiryData() { + return _expiry_reported; +} + bool FGAIBase::_getImpactData() { return _impact_reported; }