]> git.mxchange.org Git - flightgear.git/commitdiff
Work on AIAircraft gear animation.
authorJames Turner <zakalawe@mac.com>
Sun, 25 Nov 2012 21:37:15 +0000 (21:37 +0000)
committerJames Turner <zakalawe@mac.com>
Sun, 25 Nov 2012 21:37:15 +0000 (21:37 +0000)
Inspired by Harald's patch, attempt to get AI models show realistic gear animations. Unfortunately AI models seem to be ignoring the gear properties, so keeping the code disabled until I can trace down why.

src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx

index 2ad2b489ddaeafc856239f1048051499afcf51a7..b5ef2418798fd70e0299ec144d9e0c18c55fd7ac 100644 (file)
@@ -28,6 +28,7 @@
 #include <Scenery/tilemgr.hxx>
 #include <Airports/dynamics.hxx>
 #include <Airports/simple.hxx>
+#include <Main/util.hxx>
 
 #include <string>
 #include <math.h>
@@ -123,9 +124,6 @@ void FGAIAircraft::readFromScenario(SGPropertyNode* scFileNode) {
 void FGAIAircraft::bind() {
     FGAIBase::bind();
 
-    tie("controls/gear/gear-down",
-        SGRawValueMethods<FGAIAircraft,bool>(*this,
-                &FGAIAircraft::_getGearDown));
     tie("transponder-id",
         SGRawValueMethods<FGAIAircraft,const char*>(*this,
                 &FGAIAircraft::_getTransponderCode));
@@ -165,8 +163,14 @@ void FGAIAircraft::setPerformance(const std::string& acType, const std::string&
 
      handleATCRequests(); // ATC also has a word to say
      updateSecondaryTargetValues(); // target roll, vertical speed, pitch
-     updateActualState(); 
-    // We currently have one situation in which an AIAircraft object is used that is not attached to the 
+     updateActualState();
+#if 0
+   // 25/11/12 - added but disabled, since setting properties isn't
+   // affecting the AI-model as expected.
+     updateModelProperties(dt);
+#endif
+   
+    // We currently have one situation in which an AIAircraft object is used that is not attached to the
     // AI manager. In this particular case, the AIAircraft is used to shadow the user's aircraft's behavior in the AI world.
     // Since we perhaps don't want a radar entry of our own aircraft, the following conditional should probably be adequate
     // enough
@@ -449,12 +453,6 @@ void FGAIAircraft::checkTcas(void)
 void FGAIAircraft::initializeFlightPlan() {
 }
 
-
-bool FGAIAircraft::_getGearDown() const {
-    return _performance->gearExtensible(this);
-}
-
-
 const char * FGAIAircraft::_getTransponderCode() const {
   return transponderCode.c_str();
 }
@@ -1375,3 +1373,44 @@ time_t FGAIAircraft::checkForArrivalTime(const string& wptName) {
      }
      return (ete - secondsToGo); // Positive when we're too slow...
 }
+
+double limitRateOfChange(double cur, double target, double maxDeltaSec, double dt)
+{
+  double delta = target - cur;
+  double maxDelta = maxDeltaSec * dt;
+  
+// if delta is > maxDelta, use maxDelta, but with the sign of delta.
+  return (fabs(delta) < maxDelta) ? delta : copysign(maxDelta, delta);
+}
+
+// drive various properties in a semi-realistic fashion.
+void FGAIAircraft::updateModelProperties(double dt)
+{
+  if (!props) {
+    return;
+  }
+  
+  SGPropertyNode* gear = props->getChild("gear", 0, true);
+  double targetGearPos = fp->getCurrentWaypoint()->getGear_down() ? 1.0 : 0.0;
+  if (!gear->hasValue("gear/position-norm")) {
+    gear->setDoubleValue("gear/position-norm", targetGearPos);
+  }
+  
+  double gearPosNorm = gear->getDoubleValue("gear/position-norm");
+  if (gearPosNorm != targetGearPos) {
+    gearPosNorm += limitRateOfChange(gearPosNorm, targetGearPos, 0.1, dt);
+    if (gearPosNorm < 0.001) {
+      gearPosNorm = 0.0;
+    } else if (gearPosNorm > 0.999) {
+      gearPosNorm = 1.0;
+    }
+    
+    for (int i=0; i<6; ++i) {
+      SGPropertyNode* g = gear->getChild("gear", i, true);
+      g->setDoubleValue("position-norm", gearPosNorm);
+    } // of gear setting loop      
+  } // of gear in-transit
+  
+//  double flapPosNorm = props->getDoubleValue();
+}
+
index 3a149857fdd1b02d3bcae508894d146cd167ad4b..58fd417f63306816f8702942abf1e0714244d9b3 100644 (file)
@@ -153,6 +153,7 @@ private:
     void updateVerticalSpeedTarget();
     void updatePitchAngleTarget();
     void updateActualState();
+    void updateModelProperties(double dt);
     void handleATCRequests();
     void checkVisibility();
     inline bool isStationary() { return ((fabs(speed)<=0.0001)&&(fabs(tgt_speed)<=0.0001));}
@@ -171,8 +172,6 @@ private:
 
     bool holdPos;
 
-    bool _getGearDown() const;
-
     const char * _getTransponderCode() const;
 
     bool reachedWaypoint;