X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAIModel%2FAIBallistic.cxx;h=6d41d5d50fbc04cf3e4aef24405f85fa69be533e;hb=9d995907db00728da7eac9297ecbab93ed8a7400;hp=b3e3bceb55090b0cc3578ca9376e272c2d5f3350;hpb=f52cf4e3b8271779e136b886298abc883bdfd388;p=flightgear.git diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx index b3e3bceb5..6d41d5d50 100644 --- a/src/AIModel/AIBallistic.cxx +++ b/src/AIModel/AIBallistic.cxx @@ -32,14 +32,16 @@ #include "AIBallistic.hxx" #include
+#include using namespace simgear; +using std::string; const double FGAIBallistic::slugs_to_kgs = 14.5939029372; const double FGAIBallistic::slugs_to_lbs = 32.1740485564; FGAIBallistic::FGAIBallistic(object_type ot) : -FGAIBase(ot), +FGAIBase(ot, false), _height(0.0), _speed(0), _ht_agl_ft(0.0), @@ -51,7 +53,6 @@ _elapsed_time(0), _aero_stabilised(false), _drag_area(0.007), _life_timer(0.0), -_gravity(32.1740485564), _buoyancy(0), _wind(true), _mass(0), @@ -66,8 +67,7 @@ _report_collision(false), _report_impact(false), _external_force(false), _report_expiry(false), -_impact_report_node(fgGetNode("/ai/models/model-impact", true)), -_old_height(0) +_impact_report_node(fgGetNode("/ai/models/model-impact", true)) { no_roll = false; @@ -126,7 +126,11 @@ void FGAIBallistic::readFromScenario(SGPropertyNode* scFileNode) { bool FGAIBallistic::init(bool search_in_AI_path) { FGAIBase::init(search_in_AI_path); + reinit(); + return true; +} +void FGAIBallistic::reinit() { _impact_reported = false; _collision_reported = false; _expiry_reported = false; @@ -179,113 +183,81 @@ bool FGAIBallistic::init(bool search_in_AI_path) { setParentNodes(_selected_ac); - return true; + FGAIBase::reinit(); } void FGAIBallistic::bind() { // FGAIBase::bind(); - props->tie("sim/time/elapsed-sec", + _tiedProperties.setRoot(props); + tie("sim/time/elapsed-sec", SGRawValueMethods(*this, &FGAIBallistic::_getTime, &FGAIBallistic::setTime)); - //props->tie("mass-slug", + //tie("mass-slug", // SGRawValueMethods(*this, // &FGAIBallistic::getMass)); - props->tie("material/solid", + tie("material/solid", SGRawValuePointer(&_solid)); - props->tie("altitude-agl-ft", + tie("altitude-agl-ft", SGRawValuePointer(&_ht_agl_ft)); - props->tie("controls/slave-to-ac", + tie("controls/slave-to-ac", SGRawValueMethods (*this, &FGAIBallistic::getSlaved, &FGAIBallistic::setSlaved)); - props->tie("controls/invisible", + tie("controls/invisible", SGRawValuePointer(&invisible)); if(_external_force || _slave_to_ac){ - props->tie("controls/force_stabilized", + tie("controls/force_stabilized", SGRawValuePointer(&_force_stabilised)); - props->tie("position/global-x", + tie("position/global-x", SGRawValueMethods(*this, &FGAIBase::_getCartPosX, 0)); - props->tie("position/global-y", + tie("position/global-y", SGRawValueMethods(*this, &FGAIBase::_getCartPosY, 0)); - props->tie("position/global-z", + tie("position/global-z", SGRawValueMethods(*this, &FGAIBase::_getCartPosZ, 0)); - props->tie("velocities/vertical-speed-fps", + tie("velocities/vertical-speed-fps", SGRawValuePointer(&vs)); - props->tie("velocities/true-airspeed-kt", + tie("velocities/true-airspeed-kt", SGRawValuePointer(&speed)); - props->tie("velocities/horizontal-speed-fps", + tie("velocities/horizontal-speed-fps", SGRawValuePointer(&hs)); - props->tie("position/altitude-ft", + tie("position/altitude-ft", SGRawValueMethods(*this, &FGAIBase::_getElevationFt, &FGAIBase::_setAltitude)); - props->tie("position/latitude-deg", + tie("position/latitude-deg", SGRawValueMethods(*this, &FGAIBase::_getLatitude, &FGAIBase::_setLatitude)); - props->tie("position/longitude-deg", + tie("position/longitude-deg", SGRawValueMethods(*this, &FGAIBase::_getLongitude, &FGAIBase::_setLongitude)); - props->tie("orientation/hdg-deg", + tie("orientation/hdg-deg", SGRawValuePointer(&hdg)); - props->tie("orientation/pitch-deg", + tie("orientation/pitch-deg", SGRawValuePointer(&pitch)); - props->tie("orientation/roll-deg", + tie("orientation/roll-deg", SGRawValuePointer(&roll)); - props->tie("controls/slave-load-to-ac", + tie("controls/slave-load-to-ac", SGRawValueMethods (*this, &FGAIBallistic::getSlavedLoad, &FGAIBallistic::setSlavedLoad)); - props->tie("position/load-offset", + tie("position/load-offset", SGRawValueMethods (*this, &FGAIBallistic::getLoadOffset, &FGAIBallistic::setLoadOffset)); - props->tie("load/distance-to-hitch-ft", + tie("load/distance-to-hitch-ft", SGRawValueMethods (*this, &FGAIBallistic::getDistanceToHitch)); - props->tie("load/elevation-to-hitch-deg", + tie("load/elevation-to-hitch-deg", SGRawValueMethods (*this, &FGAIBallistic::getElevToHitch)); - props->tie("load/bearing-to-hitch-deg", + tie("load/bearing-to-hitch-deg", SGRawValueMethods (*this, &FGAIBallistic::getBearingToHitch)); - props->tie("material/load-resistance", + tie("material/load-resistance", SGRawValuePointer(&_load_resistance)); } } -void FGAIBallistic::unbind() { -// FGAIBase::unbind(); - - props->untie("sim/time/elapsed-sec"); - props->untie("mass-slug"); - props->untie("material/solid"); - props->untie("altitude-agl-ft"); - props->untie("controls/slave-to-ac"); - props->untie("controls/invisible"); - - if(_external_force || _slave_to_ac){ - props->untie("position/global-y"); - props->untie("position/global-x"); - props->untie("position/global-z"); - props->untie("velocities/vertical-speed-fps"); - props->untie("velocities/true-airspeed-kt"); - props->untie("velocities/horizontal-speed-fps"); - props->untie("position/altitude-ft"); - props->untie("position/latitude-deg"); - props->untie("position/longitude-deg"); - props->untie("position/ht-agl-ft"); - props->untie("orientation/hdg-deg"); - props->untie("orientation/pitch-deg"); - props->untie("orientation/roll-deg"); - props->untie("controls/force_stabilized"); - props->untie("position/load-offset"); - props->untie("load/distance-to-hitch-ft"); - props->untie("load/elevation-to-hitch-deg"); - props->untie("load/bearing-to-hitch-deg"); - props->untie("material/load-resistance"); - } -} - -void FGAIBallistic::update(double dt) { +void FGAIBallistic::update(double dt) +{ FGAIBase::update(dt); - _setUserPos(); if (_slave_to_ac){ slaveToAC(dt); @@ -526,16 +498,17 @@ void FGAIBallistic::setForcePath(const string& p) { } bool FGAIBallistic::getHtAGL(double start){ - + const simgear::BVHMaterial* mat = 0; if (getGroundElevationM(SGGeod::fromGeodM(pos, start), - _elevation_m, &_material)) { + _elevation_m, &mat)) { + const SGMaterial* material = dynamic_cast(mat); _ht_agl_ft = pos.getElevationFt() - _elevation_m * SG_METER_TO_FEET; - if (_material) { - const vector& names = _material->get_names(); - _solid = _material->get_solid(); - _load_resistance = _material->get_load_resistance(); - _frictionFactor =_material->get_friction_factor(); + if (material) { + const std::vector& names = material->get_names(); + _solid = material->get_solid(); + _load_resistance = material->get_load_resistance(); + _frictionFactor = material->get_friction_factor(); if (!names.empty()) props->setStringValue("material/name", names[0].c_str()); @@ -635,22 +608,22 @@ void FGAIBallistic::slaveToAC(double dt){ if (invisible) return; - double hdg, pch, rll, agl = 0; + double hdg, pch, rll;//, agl = 0; if (_pnode != 0) { setParentPos(); hdg = _p_hdg_node->getDoubleValue(); pch = _p_pch_node->getDoubleValue(); rll = _p_rll_node->getDoubleValue(); - agl = _p_agl_node->getDoubleValue(); +// agl = _p_agl_node->getDoubleValue(); setOffsetPos(_parentpos, hdg, pch, rll); setSpeed(_p_spd_node->getDoubleValue()); }else { hdg = manager->get_user_heading(); pch = manager->get_user_pitch(); rll = manager->get_user_roll(); - agl = manager->get_user_agl(); - setOffsetPos(userpos, hdg, pch, rll); +// agl = manager->get_user_agl(); + setOffsetPos(globals->get_aircraft_position(), hdg, pch, rll); setSpeed(manager->get_user_speed()); } @@ -684,15 +657,16 @@ void FGAIBallistic::Run(double dt) { if (_life_timer > life && life != -1){ if (_report_expiry && !_expiry_reported && !_impact_reported && !_collision_reported){ - //cout<<"AIBallistic run: name " << _name.c_str() << " expiry " << " pass " << _pass <getGravity(pos)); + vs -= (gravity - _buoyancy - v_force_acc_fpss - normal_force_fpss) * dt; if (vs <= 0.00001 && vs >= -0.00001) vs = 0; @@ -968,7 +943,7 @@ void FGAIBallistic::handle_impact() { return; if (_ht_agl_ft <= 0) { - SG_LOG(SG_GENERAL, SG_DEBUG, "AIBallistic: terrain impact material" << _mat_name); + SG_LOG(SG_AI, SG_DEBUG, "AIBallistic: terrain impact material" << _mat_name); report_impact(_elevation_m); _impact_reported = true; @@ -981,7 +956,7 @@ void FGAIBallistic::handle_impact() { void FGAIBallistic::handle_expiry() { - SG_LOG(SG_GENERAL, SG_DEBUG, "AIBallistic: handle_expiry " << pos.getElevationM()); + //SG_LOG(SG_AI, SG_DEBUG, "AIBallistic: handle_expiry " << pos.getElevationM()); report_impact(pos.getElevationM()); _expiry_reported = true; @@ -1022,7 +997,7 @@ void FGAIBallistic::report_impact(double elevation, const FGAIBase *object) else n->setStringValue("type", "terrain"); - SG_LOG(SG_GENERAL, SG_DEBUG, "AIBallistic: object impact " << _name + SG_LOG(SG_AI, SG_DEBUG, "AIBallistic: object impact " << _name << " lon " <<_impact_lon << " lat " <<_impact_lat << " sec " << _life_timer); n->setDoubleValue("longitude-deg", _impact_lon); @@ -1036,15 +1011,11 @@ void FGAIBallistic::report_impact(double elevation, const FGAIBase *object) _impact_report_node->setStringValue(props->getPath()); } -SGVec3d FGAIBallistic::getCartUserPos() const { - SGVec3d cartUserPos = SGVec3d::fromGeod(userpos); - return cartUserPos; -} - SGVec3d FGAIBallistic::getCartHitchPos() const{ // convert geodetic positions to geocentered - SGVec3d cartuserPos = SGVec3d::fromGeod(userpos); + SGVec3d cartuserPos = globals->get_aircraft_position_cart(); + //SGVec3d cartPos = getCartPos(); // Transform to the right coordinate frame, configuration is done in @@ -1056,7 +1027,7 @@ SGVec3d FGAIBallistic::getCartHitchPos() const{ -_z_offset * SG_FEET_TO_METER); // Transform the user position to the horizontal local coordinate system. - SGQuatd hlTrans = SGQuatd::fromLonLat(userpos); + SGQuatd hlTrans = SGQuatd::fromLonLat(globals->get_aircraft_position()); // and postrotate the orientation of the user model wrt the horizontal // local frame @@ -1128,7 +1099,7 @@ double FGAIBallistic::getRelBrgHitchToUser() const { //calculate the relative bearing double az1, az2, distance; - geo_inverse_wgs_84(_offsetpos, userpos, &az1, &az2, &distance); + geo_inverse_wgs_84(_offsetpos, globals->get_aircraft_position(), &az1, &az2, &distance); double rel_brg = az1 - hdg; @@ -1141,14 +1112,14 @@ double FGAIBallistic::getElevHitchToUser() const { //calculate the distance from the user position SGVec3d carthitchPos = getCartHitchPos(); - SGVec3d cartuserPos = getCartUserPos(); + SGVec3d cartuserPos = globals->get_aircraft_position_cart(); SGVec3d diff = cartuserPos - carthitchPos; double distance = norm(diff); double angle = 0; - double daltM = userpos.getElevationM() - _offsetpos.getElevationM(); + double daltM = globals->get_aircraft_position().getElevationM() - _offsetpos.getElevationM(); // now the angle, positive angles are upwards if (fabs(distance) < SGLimits::min()) {