From 9bc25174170d4d6baf76adca07e6749c24a1490c Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 21 Dec 2003 20:12:55 +0000 Subject: [PATCH] Make the AI model export it's internal state to the property tree under /ai/model[] using the same naming convention as used for the regular FDM. Also make sure the model animations are relative the the /ai/model[] node. --- src/AIModel/AIAircraft.cxx | 8 +++++ src/AIModel/AIAircraft.hxx | 2 ++ src/AIModel/AIBallistic.cxx | 7 +++++ src/AIModel/AIBallistic.hxx | 2 ++ src/AIModel/AIBase.cxx | 59 ++++++++++++++++++++----------------- src/AIModel/AIBase.hxx | 43 ++++++++++++++++++++++++++- src/AIModel/AIManager.cxx | 8 +++++ src/AIModel/AIShip.cxx | 6 ++++ src/AIModel/AIShip.hxx | 2 ++ 9 files changed, 109 insertions(+), 28 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index 49346f99a..f19c054fa 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -62,6 +62,14 @@ bool FGAIAircraft::init() { return FGAIBase::init(); } +void FGAIAircraft::bind() { + FGAIBase::bind(); +} + +void FGAIAircraft::unbind() { + FGAIBase::unbind(); +} + void FGAIAircraft::update(double dt) { diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index 43aab0384..8cf2a4036 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -53,6 +53,8 @@ public: ~FGAIAircraft(); bool init(); + virtual void bind(); + virtual void unbind(); void update(double dt); void SetPerformance(const PERF_STRUCT *ps); diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx index 2d96b7c75..750096af4 100644 --- a/src/AIModel/AIBallistic.cxx +++ b/src/AIModel/AIBallistic.cxx @@ -44,6 +44,13 @@ bool FGAIBallistic::init() { return true; } +void FGAIBallistic::bind() { + FGAIBase::bind(); +} + +void FGAIBallistic::unbind() { + FGAIBase::unbind(); +} void FGAIBallistic::update(double dt) { diff --git a/src/AIModel/AIBallistic.hxx b/src/AIModel/AIBallistic.hxx index 71951d204..3878778b9 100644 --- a/src/AIModel/AIBallistic.hxx +++ b/src/AIModel/AIBallistic.hxx @@ -32,6 +32,8 @@ public: ~FGAIBallistic(); bool init(); + virtual void bind(); + virtual void unbind(); void update(double dt); void setAzimuth( double az ); diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 11b17dc41..5637ca38f 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -22,16 +22,23 @@ # include #endif +#include + +#include STL_STRING + #include #include -#include
-#include + #include #include #include #include #include -#include +#include + +#include
+#include + #include "AIBase.hxx" @@ -50,9 +57,12 @@ void FGAIBase::Transform() { bool FGAIBase::init() { + + props = globals->get_props()->getNode("ai/model", true); + ssgBranch *model = sgLoad3DModel( globals->get_fg_root(), model_path.c_str(), - globals->get_props(), + props, globals->get_sim_time_sec() ); if (model) { aip.init( model ); @@ -66,33 +76,28 @@ bool FGAIBase::init() { setDie(false); } +void FGAIBase::bind() { + props->tie("velocities/airspeed-kt", SGRawValuePointer(&speed)); + props->tie("velocities/vertical-speed-fps", SGRawValuePointer(&vs)); -void FGAIBase::setPath( const char* model ) { - model_path.append(model); -} + props->tie("position/altitude-ft", SGRawValuePointer(&altitude)); + props->tie("position/latitude-deg", SGRawValuePointer(&lat)); + props->tie("position/longitude-deg", SGRawValuePointer(&lon)); -void FGAIBase::setSpeed( double speed_KTAS ) { - speed = tgt_speed = speed_KTAS; + props->tie("orientation/pitch-deg", SGRawValuePointer(&pitch)); + props->tie("orientation/roll-deg", SGRawValuePointer(&roll)); + props->tie("orientation/heading-deg", SGRawValuePointer(&hdg)); } -void FGAIBase::setAltitude( double altitude_ft ) { - altitude = tgt_altitude = altitude_ft; - pos.setelev(altitude * 0.3048); -} +void FGAIBase::unbind() { + props->untie("velocities/airspeed-kt"); + props->untie("velocities/vertical-speed-fps"); -void FGAIBase::setLongitude( double longitude ) { - pos.setlon(longitude); -} + props->untie("position/altitude-ft"); + props->untie("position/latitude-deg"); + props->untie("position/longitude-deg"); -void FGAIBase::setLatitude( double latitude ) { - pos.setlat(latitude); + props->untie("orientation/pitch-deg"); + props->untie("orientation/roll-deg"); + props->untie("orientation/heading-deg"); } - -void FGAIBase::setHeading( double heading ) { - hdg = tgt_heading = heading; -} - -void FGAIBase::setDie( bool die ) { - delete_me = die; -} - diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 8e562628f..9221ddb4f 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -20,6 +20,7 @@ #ifndef _FG_AIBASE_HXX #define _FG_AIBASE_HXX +#include #include #include #include @@ -33,7 +34,10 @@ public: virtual ~FGAIBase(); virtual void update(double dt); inline Point3D GetPos() { return(pos); } + virtual bool init(); + virtual void bind(); + virtual void unbind(); void setPath( const char* model ); void setSpeed( double speed_KTAS ); @@ -41,12 +45,16 @@ public: void setLongitude( double longitude ); void setLatitude( double latitude ); void setHeading( double heading ); + void setDie( bool die ); - inline bool getDie() { return delete_me; } + bool getDie(); protected: + SGPropertyNode *props; + Point3D pos; // WGS84 lat & lon in degrees, elev above sea-level in meters + double lat, lon; // As above, this is needed for the property bindings double hdg; // True heading in degrees double roll; // degrees, left is negative double pitch; // degrees, nose-down is negative @@ -68,7 +76,40 @@ protected: bool delete_me; void Transform(); + }; + +inline void FGAIBase::setPath( const char* model ) { + model_path.append(model); +} + +inline void FGAIBase::setSpeed( double speed_KTAS ) { + speed = tgt_speed = speed_KTAS; +} + +inline void FGAIBase::setAltitude( double altitude_ft ) { + altitude = tgt_altitude = altitude_ft; + pos.setelev(altitude * SG_FEET_TO_METER); +} + + +inline void FGAIBase::setLongitude( double longitude ) { + lon = longitude; + pos.setlon(longitude); +} + +inline void FGAIBase::setLatitude( double latitude ) { + lat = latitude; + pos.setlat(latitude); +} + +inline void FGAIBase::setHeading( double heading ) { + hdg = tgt_heading = heading; +} + +inline void FGAIBase::setDie( bool die ) { delete_me = die; } +inline bool FGAIBase::getDie() { return delete_me; } + #endif // _FG_AIBASE_HXX diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index c6dbda134..1b39b9afa 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -72,6 +72,7 @@ void FGAIManager::init() { ai_plane->setLongitude(entry->getDoubleValue("longitude")); ai_plane->setLatitude(entry->getDoubleValue("latitude")); ai_plane->init(); + ai_plane->bind(); } else if (!strcmp(entry->getStringValue("type", ""), "ship")) { FGAIShip* ai_ship = new FGAIShip; @@ -83,6 +84,7 @@ void FGAIManager::init() { ai_ship->setLongitude(entry->getDoubleValue("longitude")); ai_ship->setLatitude(entry->getDoubleValue("latitude")); ai_ship->init(); + ai_ship->bind(); } else if (!strcmp(entry->getStringValue("type", ""), "ballistic")) { FGAIBallistic* ai_ballistic = new FGAIBallistic; @@ -95,6 +97,7 @@ void FGAIManager::init() { ai_ballistic->setLongitude(entry->getDoubleValue("longitude")); ai_ballistic->setLatitude(entry->getDoubleValue("latitude")); ai_ballistic->init(); + ai_ballistic->bind(); } } } @@ -108,6 +111,11 @@ void FGAIManager::bind() { void FGAIManager::unbind() { + ai_list_itr = ai_list.begin(); + while(ai_list_itr != ai_list.end()) { + (*ai_list_itr)->unbind(); + ++ai_list_itr; + } } diff --git a/src/AIModel/AIShip.cxx b/src/AIModel/AIShip.cxx index 4a81972b6..650d83583 100644 --- a/src/AIModel/AIShip.cxx +++ b/src/AIModel/AIShip.cxx @@ -40,7 +40,13 @@ bool FGAIShip::init() { return FGAIBase::init(); } +void FGAIShip::bind() { + FGAIBase::bind(); +} +void FGAIShip::unbind() { + FGAIBase::unbind(); +} void FGAIShip::update(double dt) { diff --git a/src/AIModel/AIShip.hxx b/src/AIModel/AIShip.hxx index c36686245..d4d29f022 100644 --- a/src/AIModel/AIShip.hxx +++ b/src/AIModel/AIShip.hxx @@ -33,6 +33,8 @@ public: ~FGAIShip(); bool init(); + virtual void bind(); + virtual void unbind(); void update(double dt); void AccelTo(double speed); -- 2.39.5