From 4cbe540bec1e3fd6b2881c04b9c389ffd8583d57 Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Fri, 24 Feb 2017 20:47:08 +0100 Subject: [PATCH] YASim: convert local variables alpha and stallAlpha to members of Surface. --- src/FDM/YASim/Surface.cpp | 27 +++++++++------------------ src/FDM/YASim/Surface.hpp | 4 ++++ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/FDM/YASim/Surface.cpp b/src/FDM/YASim/Surface.cpp index 824b7d299..1a9aa810d 100644 --- a/src/FDM/YASim/Surface.cpp +++ b/src/FDM/YASim/Surface.cpp @@ -224,12 +224,6 @@ void Surface::calcForce(float* v, float rho, float* out, float* torque) // Diddle the Z force according to our configuration float stallMul = stallFunc(out); - if (_surfN != 0) { - _surfN->getNode("wind-loc-x", true)->setFloatValue(lwind[0]); - _surfN->getNode("wind-loc-y", true)->setFloatValue(lwind[1]); - _surfN->getNode("wind-loc-z", true)->setFloatValue(lwind[2]); - _surfN->getNode("stall-base-factor", true)->setFloatValue(stallMul); - } stallMul *= 1 + _spoilerPos * (_spoilerLift - 1); float stallLift = (stallMul - 1) * _cz * out[2]; float flaplift = flapLift(out[2]); @@ -310,43 +304,40 @@ float Surface::stallFunc(float* v) // Sanity check to treat FPU psychopathology if(v[0] == 0) return 1; - float alpha = Math::abs(v[2]/v[0]); - if (_surfN != 0) - _surfN->getNode("alpha-deg", true)->setFloatValue(alpha*57.295779513); + _alpha = Math::abs(v[2]/v[0]); // Wacky use of indexing, see setStall*() methods. int fwdBak = v[0] > 0; // set if this is "backward motion" int posNeg = v[2] < 0; // set if the airflow is toward -z int i = (fwdBak<<1) | posNeg; - if (_surfN != 0) - _surfN->getNode("mode", true)->setValue(i); - float stallAlpha = _stalls[i]; - if(stallAlpha == 0) + _stallAlpha = _stalls[i]; + if(_stallAlpha == 0) return 1; + // consider slat position, moves the stall aoa some degrees if(i == 0) { if( _version->isVersionOrNewer( Version::YASIM_VERSION_32 )) { - stallAlpha += _slatPos * _slatAlpha; + _stallAlpha += _slatPos * _slatAlpha; } else { - stallAlpha += _slatAlpha; + _stallAlpha += _slatAlpha; } } // Beyond the stall - if(alpha > stallAlpha+_widths[i]) + if(_alpha > _stallAlpha+_widths[i]) return 1; // (note mask: we want to use the "positive" stall angle here) float scale = 0.5f*_peaks[fwdBak]/_stalls[i&2]; // Before the stall - if(alpha <= stallAlpha) + if(_alpha <= _stallAlpha) return scale; // Inside the stall. Compute a cubic interpolation between the // pre-stall "scale" value and the post-stall unity. - float frac = (alpha - stallAlpha) / _widths[i]; + float frac = (_alpha - _stallAlpha) / _widths[i]; frac = frac*frac*(3-2*frac); return scale*(1-frac) + frac; diff --git a/src/FDM/YASim/Surface.hpp b/src/FDM/YASim/Surface.hpp index 43c477332..7b805c666 100644 --- a/src/FDM/YASim/Surface.hpp +++ b/src/FDM/YASim/Surface.hpp @@ -114,6 +114,10 @@ private: float _incidence; float _twist; float _inducedDrag; + + // used during calculations + float _stallAlpha; + float _alpha; Version * _version; };