X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAIModel%2FAIGroundVehicle.cxx;h=257a73517c3397e78eeb3d18043b3c3d881ff8c7;hb=ff985e43df33be1698b994f6e0ee1f6e573ba390;hp=e65ea5b7ee7d6eba8326b165c7407211598080c7;hpb=72c5a314e6daa5052165310a600c4a9a4c20e43f;p=flightgear.git diff --git a/src/AIModel/AIGroundVehicle.cxx b/src/AIModel/AIGroundVehicle.cxx index e65ea5b7e..257a73517 100644 --- a/src/AIModel/AIGroundVehicle.cxx +++ b/src/AIModel/AIGroundVehicle.cxx @@ -37,20 +37,19 @@ FGAIShip(otGroundVehicle), _pitch(0), _pitch_deg(0), _speed_kt(0), -_selected_ac(0), _range_ft(0), _relbrg (0), _parent_speed(0), -_dt_count(0), -_next_run(0), _parent_x_offset(0), _parent_y_offset(0), _parent_z_offset(0), -_parent(""), +_dt_count(0), +_next_run(0), _break_count(0) { invisible = false; + _parent = ""; } FGAIGroundVehicle::~FGAIGroundVehicle() {} @@ -61,9 +60,9 @@ void FGAIGroundVehicle::readFromScenario(SGPropertyNode* scFileNode) { FGAIShip::readFromScenario(scFileNode); - setNoRoll(scFileNode->getBoolValue("no-roll", true)); setName(scFileNode->getStringValue("name", "groundvehicle")); - setSMPath(scFileNode->getStringValue("submodel-path", "")); + setParentName(scFileNode->getStringValue("parent", "")); + setNoRoll(scFileNode->getBoolValue("no-roll", true)); setContactX1offset(scFileNode->getDoubleValue("contact-x1-offset", 0.0)); setContactX2offset(scFileNode->getDoubleValue("contact-x2-offset", 0.0)); setXOffset(scFileNode->getDoubleValue("hitch-x-offset", 35.0)); @@ -74,7 +73,6 @@ void FGAIGroundVehicle::readFromScenario(SGPropertyNode* scFileNode) { setYawoffset(scFileNode->getDoubleValue("yaw-offset", 0.0)); setPitchCoeff(scFileNode->getDoubleValue("pitch-coefficient", 0.1)); setElevCoeff(scFileNode->getDoubleValue("elevation-coefficient", 0.25)); - setParentName(scFileNode->getStringValue("parent", "")); setTowAngleGain(scFileNode->getDoubleValue("tow-angle-gain", 1.0)); setTowAngleLimit(scFileNode->getDoubleValue("tow-angle-limit-deg", 2.0)); setInitialTunnel(scFileNode->getBoolValue("tunnel", false)); @@ -125,7 +123,7 @@ void FGAIGroundVehicle::unbind() { FGAIShip::unbind(); props->untie("controls/constants/elevation-coeff"); - props->untie("controls/constants/pitch-coeff"); + props->untie("controls/constants/pitch-coeff"); props->untie("position/ht-AGL-ft"); props->untie("hitch/rel-bearing-deg"); props->untie("hitch/tow-angle-deg"); @@ -150,6 +148,21 @@ bool FGAIGroundVehicle::init(bool search_in_AI_path) { _limit = 200; no_roll = true; + props->setStringValue("controls/parent-name", _parent.c_str()); + + if (setParentNode()){ + _parent_x_offset = _selected_ac->getDoubleValue("hitch/x-offset-ft"); + _parent_y_offset = _selected_ac->getDoubleValue("hitch/y-offset-ft"); + _parent_z_offset = _selected_ac->getDoubleValue("hitch/z-offset-ft"); + _hitch_x_offset_m = _selected_ac->getDoubleValue("hitch/x-offset-ft") + * SG_FEET_TO_METER; + _hitch_y_offset_m = _selected_ac->getDoubleValue("hitch/y-offset-ft") + * SG_FEET_TO_METER; + _hitch_z_offset_m = _selected_ac->getDoubleValue("hitch/z-offset-ft") + * SG_FEET_TO_METER; + setParent(); + } + return true; } @@ -210,10 +223,6 @@ void FGAIGroundVehicle::setPitch(double p, double dt, double coeff){ _pitch_deg = (p * c) + (_pitch_deg * (1 - c)); } -void FGAIGroundVehicle::setParentName(const string& p) { - _parent = p; -} - void FGAIGroundVehicle::setTowAngle(double ta, double dt, double coeff){ ta *= _tow_angle_gain; double factor = -0.0045 * speed + 1; @@ -223,39 +232,6 @@ void FGAIGroundVehicle::setTowAngle(double ta, double dt, double coeff){ SG_CLAMP_RANGE(_tow_angle, -limit, limit); } -bool FGAIGroundVehicle::getGroundElev(SGGeod inpos) { - - double height_m ; - - if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(inpos, 3000), height_m, &_material,0)){ - _ht_agl_ft = inpos.getElevationFt() - height_m * SG_METER_TO_FEET; - - if (_material) { - const vector& names = _material->get_names(); - - _solid = _material->get_solid(); - - if (!names.empty()) - props->setStringValue("material/name", names[0].c_str()); - else - props->setStringValue("material/name", ""); - - //cout << "material " << names[0].c_str() - // << " _elevation_m " << _elevation_m - // << " solid " << _solid - // << " load " << _load_resistance - // << " frictionFactor " << _frictionFactor - // << endl; - - } - - return true; - } else { - return false; - } - -} - bool FGAIGroundVehicle::getPitch() { if (!_tunnel){ @@ -276,7 +252,7 @@ bool FGAIGroundVehicle::getPitch() { double rear_elev_m = 0; double elev_front = 0; double elev_rear = 0; - double max_alt = 10000; + //double max_alt = 10000; if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(geodFront, 3000), elev_front, &_material, 0)){ @@ -342,81 +318,35 @@ bool FGAIGroundVehicle::getPitch() { } - getGroundElev(pos); - return true; } -void FGAIGroundVehicle::setParent() { - - 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 +void FGAIGroundVehicle::setParent(){ - if (_selected_ac != 0){ - const string name = _selected_ac->getStringValue("name"); - double lat = _selected_ac->getDoubleValue("position/latitude-deg"); - double lon = _selected_ac->getDoubleValue("position/longitude-deg"); - double elevation = _selected_ac->getDoubleValue("position/altitude-ft"); - double hitch_x_offset_m = _selected_ac->getDoubleValue("hitch/x-offset-ft") - * SG_FEET_TO_METER; - double hitch_y_offset_m = _selected_ac->getDoubleValue("hitch/y-offset-ft") - * SG_FEET_TO_METER; - double hitch_z_offset_m = _selected_ac->getDoubleValue("hitch/z-offset-ft") - * SG_FEET_TO_METER; - - _selectedpos.setLatitudeDeg(lat); - _selectedpos.setLongitudeDeg(lon); - _selectedpos.setElevationFt(elevation); + double lat = _selected_ac->getDoubleValue("position/latitude-deg"); + double lon = _selected_ac->getDoubleValue("position/longitude-deg"); + double elevation = _selected_ac->getDoubleValue("position/altitude-ft"); - _parent_x_offset = _selected_ac->getDoubleValue("hitch/x-offset-ft"); - _parent_y_offset = _selected_ac->getDoubleValue("hitch/y-offset-ft"); - _parent_z_offset = _selected_ac->getDoubleValue("hitch/z-offset-ft"); + _selectedpos.setLatitudeDeg(lat); + _selectedpos.setLongitudeDeg(lon); + _selectedpos.setElevationFt(elevation); - _parent_speed = _selected_ac->getDoubleValue("velocities/true-airspeed-kt"); + _parent_speed = _selected_ac->getDoubleValue("velocities/true-airspeed-kt"); - SGVec3d rear_hitch(-hitch_x_offset_m, hitch_y_offset_m, 0); - SGVec3d RearHitch = getCartHitchPosAt(rear_hitch); + SGVec3d rear_hitch(-_hitch_x_offset_m, _hitch_y_offset_m, 0); + SGVec3d RearHitch = getCartHitchPosAt(rear_hitch); - SGGeod rearpos = SGGeod::fromCart(RearHitch); + SGGeod rearpos = SGGeod::fromCart(RearHitch); - double user_lat = rearpos.getLatitudeDeg(); - double user_lon = rearpos.getLongitudeDeg(); + double user_lat = rearpos.getLatitudeDeg(); + double user_lon = rearpos.getLongitudeDeg(); - double range, bearing; - - calcRangeBearing(pos.getLatitudeDeg(), pos.getLongitudeDeg(), - user_lat, user_lon, range, bearing); - _range_ft = range * 6076.11549; - _relbrg = calcRelBearingDeg(bearing, hdg); - } else { - SG_LOG(SG_GENERAL, SG_ALERT, "AIGroundVeh1cle: " << _name - << " parent not found: dying "); - setDie(true); - } + double range, bearing; + calcRangeBearing(pos.getLatitudeDeg(), pos.getLongitudeDeg(), + user_lat, user_lon, range, bearing); + _range_ft = range * 6076.11549; + _relbrg = calcRelBearingDeg(bearing, hdg); } void FGAIGroundVehicle::calcRangeBearing(double lat, double lon, double lat2, double lon2, @@ -428,12 +358,6 @@ void FGAIGroundVehicle::calcRangeBearing(double lat, double lon, double lat2, do range = distance * SG_METER_TO_NM; } -double FGAIGroundVehicle::calcRelBearingDeg(double bearing, double heading) -{ - double angle = bearing - heading; - SG_NORMALIZE_RANGE(angle, -180.0, 180.0); - return angle; -} SGVec3d FGAIGroundVehicle::getCartHitchPosAt(const SGVec3d& _off) const { double hdg = _selected_ac->getDoubleValue("orientation/true-heading-deg"); @@ -517,7 +441,7 @@ void FGAIGroundVehicle::AdvanceFP(){ void FGAIGroundVehicle::setTowSpeed(){ - double diff = _range_ft - _x_offset; + //double diff = _range_ft - _x_offset; double x = 0; if (_range_ft > _x_offset * 3) x = 50; @@ -574,7 +498,7 @@ void FGAIGroundVehicle::RunGroundVehicle(double dt){ string parent_next_name = _selected_ac->getStringValue("waypoint/name-next"); bool parent_waiting = _selected_ac->getBoolValue("waypoint/waiting"); - bool parent_restart = _selected_ac->getBoolValue("controls/restart"); + //bool parent_restart = _selected_ac->getBoolValue("controls/restart"); if (parent_next_name == "END" && fp->getNextWaypoint()->name != "END" ){ SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name