1
0
Fork 0

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.

This commit is contained in:
ehofman 2003-12-21 20:12:55 +00:00
parent 8c0e2fbd2e
commit 9bc2517417
9 changed files with 110 additions and 29 deletions

View file

@ -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) {

View file

@ -53,6 +53,8 @@ public:
~FGAIAircraft();
bool init();
virtual void bind();
virtual void unbind();
void update(double dt);
void SetPerformance(const PERF_STRUCT *ps);

View file

@ -44,6 +44,13 @@ bool FGAIBallistic::init() {
return true;
}
void FGAIBallistic::bind() {
FGAIBase::bind();
}
void FGAIBallistic::unbind() {
FGAIBase::unbind();
}
void FGAIBallistic::update(double dt) {

View file

@ -32,6 +32,8 @@ public:
~FGAIBallistic();
bool init();
virtual void bind();
virtual void unbind();
void update(double dt);
void setAzimuth( double az );

View file

@ -22,16 +22,23 @@
# include <config.h>
#endif
#include <simgear/compiler.h>
#include STL_STRING
#include <plib/sg.h>
#include <plib/ssg.h>
#include <Main/globals.hxx>
#include <Scenery/scenery.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/scene/model/location.hxx>
#include <simgear/scene/model/model.hxx>
#include <simgear/debug/logstream.hxx>
#include <string>
#include <simgear/props/props.hxx>
#include <Main/globals.hxx>
#include <Scenery/scenery.hxx>
#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<double>(&speed));
props->tie("velocities/vertical-speed-fps", SGRawValuePointer<double>(&vs));
void FGAIBase::setPath( const char* model ) {
model_path.append(model);
props->tie("position/altitude-ft", SGRawValuePointer<double>(&altitude));
props->tie("position/latitude-deg", SGRawValuePointer<double>(&lat));
props->tie("position/longitude-deg", SGRawValuePointer<double>(&lon));
props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
props->tie("orientation/heading-deg", SGRawValuePointer<double>(&hdg));
}
void FGAIBase::setSpeed( double speed_KTAS ) {
speed = tgt_speed = speed_KTAS;
}
void FGAIBase::unbind() {
props->untie("velocities/airspeed-kt");
props->untie("velocities/vertical-speed-fps");
void FGAIBase::setAltitude( double altitude_ft ) {
altitude = tgt_altitude = altitude_ft;
pos.setelev(altitude * 0.3048);
}
props->untie("position/altitude-ft");
props->untie("position/latitude-deg");
props->untie("position/longitude-deg");
void FGAIBase::setLongitude( double longitude ) {
pos.setlon(longitude);
props->untie("orientation/pitch-deg");
props->untie("orientation/roll-deg");
props->untie("orientation/heading-deg");
}
void FGAIBase::setLatitude( double latitude ) {
pos.setlat(latitude);
}
void FGAIBase::setHeading( double heading ) {
hdg = tgt_heading = heading;
}
void FGAIBase::setDie( bool die ) {
delete_me = die;
}

View file

@ -20,6 +20,7 @@
#ifndef _FG_AIBASE_HXX
#define _FG_AIBASE_HXX
#include <simgear/constants.h>
#include <simgear/math/point3d.hxx>
#include <simgear/scene/model/placement.hxx>
#include <string>
@ -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

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -33,6 +33,8 @@ public:
~FGAIShip();
bool init();
virtual void bind();
virtual void unbind();
void update(double dt);
void AccelTo(double speed);