From: ehofman Date: Sun, 21 Dec 2003 22:16:57 +0000 (+0000) Subject: Use some C++ FOOmagic to get the lat and lon updated in the property tree properly X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c1eb54ae0ae687dfaf90538ebb60ef06df2837ab;p=flightgear.git Use some C++ FOOmagic to get the lat and lon updated in the property tree properly --- diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 5637ca38f..9271deef4 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -42,7 +42,14 @@ #include "AIBase.hxx" +FGAIBase *FGAIBase::_self = NULL; + +FGAIBase::FGAIBase() { + _self = this; +} + FGAIBase::~FGAIBase() { + _self = NULL; } void FGAIBase::update(double dt) { @@ -81,8 +88,12 @@ void FGAIBase::bind() { props->tie("velocities/vertical-speed-fps", SGRawValuePointer(&vs)); props->tie("position/altitude-ft", SGRawValuePointer(&altitude)); - props->tie("position/latitude-deg", SGRawValuePointer(&lat)); - props->tie("position/longitude-deg", SGRawValuePointer(&lon)); + props->tie("position/latitude-deg", + SGRawValueFunctions(FGAIBase::_getLatitude, + FGAIBase::_setLatitude)); + props->tie("position/longitude-deg", + SGRawValueFunctions(FGAIBase::_getLongitude, + FGAIBase::_setLongitude)); props->tie("orientation/pitch-deg", SGRawValuePointer(&pitch)); props->tie("orientation/roll-deg", SGRawValuePointer(&roll)); @@ -101,3 +112,16 @@ void FGAIBase::unbind() { props->untie("orientation/roll-deg"); props->untie("orientation/heading-deg"); } + + +void FGAIBase::_setLongitude( double longitude ) { + _self->pos.setlon(longitude); +} + +void FGAIBase::_setLatitude ( double latitude ) { + _self->pos.setlat(latitude); +} + +double FGAIBase::_getLongitude() { return _self->pos.lon(); } + +double FGAIBase::_getLatitude () { return _self->pos.lat(); } diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 9221ddb4f..0ea71d12b 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -29,8 +29,13 @@ SG_USING_STD(string); class FGAIBase { +private: + + static FGAIBase *_self; + public: + FGAIBase(); virtual ~FGAIBase(); virtual void update(double dt); inline Point3D GetPos() { return(pos); } @@ -42,9 +47,9 @@ public: void setPath( const char* model ); void setSpeed( double speed_KTAS ); void setAltitude( double altitude_ft ); - void setLongitude( double longitude ); - void setLatitude( double latitude ); void setHeading( double heading ); + void setLatitude( double latitude ); + void setLongitude( double longitude ); void setDie( bool die ); bool getDie(); @@ -54,7 +59,6 @@ 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 @@ -77,6 +81,11 @@ protected: void Transform(); +private: + static void _setLongitude( double longitude ); + static void _setLatitude ( double latitude ); + static double _getLongitude(); + static double _getLatitude (); }; @@ -93,19 +102,16 @@ inline void FGAIBase::setAltitude( double altitude_ft ) { pos.setelev(altitude * SG_FEET_TO_METER); } - -inline void FGAIBase::setLongitude( double longitude ) { - lon = longitude; - pos.setlon(longitude); +inline void FGAIBase::setHeading( double heading ) { + hdg = tgt_heading = heading; } -inline void FGAIBase::setLatitude( double latitude ) { - lat = latitude; - pos.setlat(latitude); +inline void FGAIBase::setLongitude( double longitude ) { + pos.setlon( longitude ); } -inline void FGAIBase::setHeading( double heading ) { - hdg = tgt_heading = heading; +inline void FGAIBase::setLatitude ( double latitude ) { + pos.setlat( latitude ); } inline void FGAIBase::setDie( bool die ) { delete_me = die; }