]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Wing.cpp
Use bool where the source and destination variable is bool.
[flightgear.git] / src / FDM / YASim / Wing.cpp
index 22cc84a663dcb89b864eb82b97fed1ddcb97bb0e..5c9fd6a33a6b1542fea0fe874b1a3bc6fbdf8d08 100644 (file)
@@ -15,8 +15,10 @@ Wing::Wing()
     _stall = 0;
     _stallWidth = 0;
     _stallPeak = 0;
+    _twist = 0;
     _camber = 0;
     _incidence = 0;
+    _inducedDrag = 1;
     _dragScale = 1;
     _liftRatio = 1;
     _flap0Start = 0;
@@ -113,6 +115,11 @@ void Wing::setStallPeak(float fraction)
     _stallPeak = fraction;
 }
 
+void Wing::setTwist(float angle)
+{
+    _twist = angle;
+}
+
 void Wing::setCamber(float camber)
 {
     _camber = camber;
@@ -208,6 +215,21 @@ float Wing::getGroundEffect(float* posOut)
     return span;
 }
 
+void Wing::getTip(float* tip)
+{
+    tip[0] = -Math::tan(_sweep);
+    tip[1] = Math::cos(_dihedral);
+    tip[2] = Math::sin(_dihedral);
+    Math::unit3(tip, tip);
+    Math::mul3(_length, tip, tip);
+    Math::add3(_base, tip, tip);
+}
+
+bool Wing::isMirrored()
+{
+    return _mirror;
+}
+
 void Wing::compile()
 {
     // Have we already been compiled?
@@ -249,7 +271,7 @@ void Wing::compile()
 
     // Calculate a "nominal" segment length equal to an average chord,
     // normalized to lie within 0-1 over the length of the wing.
-    float segLen = _chord * (0.5*(_taper+1)) / _length;
+    float segLen = _chord * (0.5f*(_taper+1)) / _length;
 
     // Generating a unit vector pointing out the left wing.
     float left[3];
@@ -308,11 +330,13 @@ void Wing::compile()
         // and flap1 are set.  Right now flap1 overrides.
 
         int nSegs = (int)Math::ceil((end-start)/segLen);
+        if (_twist != 0 && nSegs < 8) // more segments if twisted
+            nSegs = 8;
         float segWid = _length * (end - start)/nSegs;
 
         int j;
         for(j=0; j<nSegs; j++) {
-            float frac = start + (j+0.5) * (end-start)/nSegs;
+            float frac = start + (j+0.5f) * (end-start)/nSegs;
             float pos[3];
             interp(root, tip, frac, pos);
 
@@ -325,6 +349,7 @@ void Wing::compile()
             sr->surface = s;
             sr->weight = chord * segWid;
             s->setTotalDrag(sr->weight);
+            s->setTwist(_twist * frac);
             _surfs.add(sr);
 
             if(_mirror) {
@@ -335,10 +360,15 @@ void Wing::compile()
                 sr->surface = s;
                 sr->weight = chord * segWid;
                 s->setTotalDrag(sr->weight);
+                s->setTwist(_twist * frac);
                 _surfs.add(sr);
             }
         }
     }
+
+    // Last of all, re-set the incidence in case setIncidence() was
+    // called before we were compiled.
+    setIncidence(_incidence);
 }
 
 float Wing::getDragScale()
@@ -390,8 +420,8 @@ Surface* Wing::newSurface(float* pos, float* orient, float chord,
     // The negative AoA stall is the same if we're using an uncambered
     // airfoil, otherwise a "little badder".
     if(_camber > 0) {
-        s->setStall(1, stallAoA * 0.8);
-        s->setStallWidth(1, _stallWidth * 0.5);
+        s->setStall(1, stallAoA * 0.8f);
+        s->setStallWidth(1, _stallWidth * 0.5f);
     } else {
         s->setStall(1, stallAoA);
         s->setStall(1, _stallWidth);
@@ -402,8 +432,8 @@ Surface* Wing::newSurface(float* pos, float* orient, float chord,
     s->setStallPeak(1, 1);
     int i;
     for(i=2; i<4; i++) {
-        s->setStall(i, 0.2267);
-        s->setStallWidth(i, 1);
+        s->setStall(i, 0.2267f);
+        s->setStallWidth(i, 0.01);
     }
     
     if(flap0)   s->setFlapParams(_flap0Lift, _flap0Drag);
@@ -416,6 +446,8 @@ Surface* Wing::newSurface(float* pos, float* orient, float chord,
     if(slat)    _slatSurfs.add(s);
     if(spoiler) _spoilerSurfs.add(s);
 
+    s->setInducedDrag(_inducedDrag);
+
     return s;
 }