1
0
Fork 0

- add heading-deg, pitch-deg, roll-deg to impact/

- if no <impact-reports> node is defined for a particular submodel, then
  write the path to /ai/models/model-impact instead
- don't tie() properties that are only ever set a single time, if at all!
- better variable names
This commit is contained in:
mfranz 2007-05-31 18:08:12 +00:00
parent e8f2255039
commit bbb1d2d0c3
2 changed files with 20 additions and 45 deletions

View file

@ -47,13 +47,8 @@ FGAIBallistic::FGAIBallistic() :
_ht_agl_ft(0), _ht_agl_ft(0),
_load_resistance(0), _load_resistance(0),
_solid(false), _solid(false),
_impact_data(false), _impact_reported(false),
_impact_report_node(0), _impact_report_node(fgGetNode("/ai/models/model-impact", true)),
_impact_energy(0),
_impact_speed(0),
_impact_lat(0),
_impact_lon(0),
_impact_elev(0),
_mat_name("") _mat_name("")
{ {
no_roll = false; no_roll = false;
@ -113,16 +108,6 @@ void FGAIBallistic::bind() {
SGRawValuePointer<bool>(&_solid)); SGRawValuePointer<bool>(&_solid));
props->tie("altitude-agl-ft", props->tie("altitude-agl-ft",
SGRawValuePointer<double>(&_ht_agl_ft)); SGRawValuePointer<double>(&_ht_agl_ft));
props->tie("impact/latitude-deg",
SGRawValuePointer<double>(&_impact_lat));
props->tie("impact/longitude-deg",
SGRawValuePointer<double>(&_impact_lon));
props->tie("impact/elevation-m",
SGRawValuePointer<double>(&_impact_elev));
props->tie("impact/speed-mps",
SGRawValuePointer<double>(&_impact_speed));
props->tie("impact/energy-kJ",
SGRawValuePointer<double>(&_impact_energy));
} }
void FGAIBallistic::unbind() { void FGAIBallistic::unbind() {
@ -131,11 +116,6 @@ void FGAIBallistic::unbind() {
props->untie("material/load-resistance"); props->untie("material/load-resistance");
props->untie("material/solid"); props->untie("material/solid");
props->untie("altitude-agl-ft"); props->untie("altitude-agl-ft");
props->untie("impact/latitude-deg");
props->untie("impact/longitude-deg");
props->untie("impact/elevation-m");
props->untie("impact/speed-mps");
props->untie("impact/energy-kJ");
} }
void FGAIBallistic::update(double dt) { void FGAIBallistic::update(double dt) {
@ -201,13 +181,11 @@ void FGAIBallistic::setRandom(bool r) {
} }
void FGAIBallistic::setImpact(bool i) { void FGAIBallistic::setImpact(bool i) {
_impact = i; _report_impact = i;
} }
void FGAIBallistic::setImpactReportNode(const string& path) { void FGAIBallistic::setImpactReportNode(const string& path) {
if (path.empty()) if (!path.empty())
_impact_report_node = 0;
else
_impact_report_node = fgGetNode(path.c_str(), true); _impact_report_node = fgGetNode(path.c_str(), true);
} }
@ -296,7 +274,7 @@ void FGAIBallistic::Run(double dt) {
// recalculate total speed // recalculate total speed
speed = sqrt( vs * vs + hs * hs) / SG_KT_TO_FPS; speed = sqrt( vs * vs + hs * hs) / SG_KT_TO_FPS;
if (_impact && !_impact_data) if (_report_impact && !_impact_reported)
handle_impact(); handle_impact();
// set destruction flag if altitude less than sea level -1000 // set destruction flag if altitude less than sea level -1000
@ -335,18 +313,21 @@ void FGAIBallistic::handle_impact() {
// report impact by setting property-tied variables // report impact by setting property-tied variables
if (_ht_agl_ft <= 0) { if (_ht_agl_ft <= 0) {
_impact_data = true; _impact_reported = true;
double speed_mps = speed * SG_KT_TO_MPS;
_impact_lat = pos.getLatitudeDeg(); SGPropertyNode *n = props->getNode("impact", true);
_impact_lon = pos.getLongitudeDeg(); n->setDoubleValue("longitude-deg", pos.getLongitudeDeg());
_impact_elev = elevation_m; n->setDoubleValue("latitude-deg", pos.getLatitudeDeg());
_impact_speed = speed * SG_KT_TO_MPS; n->setDoubleValue("elevation-m", elevation_m);
_impact_energy = (_mass * slugs_to_kgs) * _impact_speed n->setDoubleValue("heading-deg", hdg);
* _impact_speed / (2 * 1000); n->setDoubleValue("pitch-deg", pitch);
n->setDoubleValue("roll-deg", roll);
n->setDoubleValue("speed-mps", speed_mps);
n->setDoubleValue("energy-kJ", (_mass * slugs_to_kgs)
* speed_mps * speed_mps / (2 * 1000));
// and inform the owner _impact_report_node->setStringValue(props->getPath());
if (_impact_report_node)
_impact_report_node->setStringValue(props->getPath());
} }
} }

View file

@ -81,16 +81,10 @@ private:
double _ht_agl_ft; // height above ground level double _ht_agl_ft; // height above ground level
double _load_resistance; // ground load resistanc N/m^2 double _load_resistance; // ground load resistanc N/m^2
bool _solid; // if true ground is solid for FDMs bool _solid; // if true ground is solid for FDMs
bool _impact; // if true an impact point on the terrain is calculated bool _report_impact; // if true an impact point on the terrain is calculated
bool _impact_data; // if true impact data have been set bool _impact_reported; // if true impact data have been set
SGPropertyNode_ptr _impact_report_node; SGPropertyNode_ptr _impact_report_node;
double _impact_energy;
double _impact_speed;
double _impact_lat;
double _impact_lon;
double _impact_elev;
string _mat_name; string _mat_name;
string _name; string _name;