]> git.mxchange.org Git - flightgear.git/commitdiff
Use some C++ FOOmagic to get the lat and lon updated in the property tree properly
authorehofman <ehofman>
Sun, 21 Dec 2003 22:16:57 +0000 (22:16 +0000)
committerehofman <ehofman>
Sun, 21 Dec 2003 22:16:57 +0000 (22:16 +0000)
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx

index 5637ca38f6c0999f4da6a58a441daaba03d9aea0..9271deef4db5ad6ffb97d29c52855eaa7dea5053 100644 (file)
 
 #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<double>(&vs));
 
    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("position/latitude-deg",
+               SGRawValueFunctions<double>(FGAIBase::_getLatitude,
+                                           FGAIBase::_setLatitude));
+   props->tie("position/longitude-deg",
+               SGRawValueFunctions<double>(FGAIBase::_getLongitude,
+                                           FGAIBase::_setLongitude));
 
    props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
    props->tie("orientation/roll-deg", SGRawValuePointer<double>(&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(); }
index 9221ddb4f24894383064161bd58ae0b6e35d1ac0..0ea71d12bd089c4e081234cddad511ed6005dd9e 100644 (file)
@@ -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; }