1#include "Atmosphere.hpp"
14 _reverseThrust =
false;
53void Jet::setMaxThrust(
float thrust,
float afterburner)
56 if(afterburner == 0) _abFactor = 1;
57 else { _abFactor = afterburner/thrust;
58 _abThrust = afterburner - thrust;
62void Jet::setRPMs(
float idleN1,
float maxN1,
float idleN2,
float maxN2)
70void Jet::setSpooling(
float time)
75 _decay = 1.5f * 2.3f / time;
78void Jet::setReheat(
float reheat)
80 _reheat = Math::clamp(reheat, 0, 1);
83void Jet::setRotation(
float rot)
85 _rotControl = Math::clamp(rot, 0, 1);
90 return _n1 * _tempCorrect;
95 return _n2 * _tempCorrect;
102 return _atmo.getTemperature();
104 return _egt * _tempCorrect * _tempCorrect;
107float Jet::getFuelFlow()
109 return _fuelFlow * _pressureCorrect;
112void Jet::integrate(
float dt)
115 const static float P0 = Atmosphere::getStdPressure(0);
116 const static float T0 = Atmosphere::getStdTemperature(0);
117 const static float D0 = Atmosphere::getStdDensity(0);
119 float spd = -Math::dot3(_wind, _dir);
121 float statT, statP, statD;
122 _atmo.calcStaticAir(spd, &statP, &statT, &statD);
123 _pressureCorrect = statP/
P0;
124 _tempCorrect = Math::sqrt(statT/T0);
133 float vCorr = spd<0 ? 1 : (spd<_vMax ? 1-spd/_vMax : 0);
135 float maxThrust = _maxThrust * vCorr * (statD/D0);
136 float setThrust = maxThrust * _throttle;
140 float ibeta0 = 1/(_epr0 - 1);
141 float betaTarget = (_epr0 - 1) * (setThrust/_maxThrust) * (
P0/_atmo.getPressure())
142 * (_atmo.getTemperature()/statT);
143 float n2Target = _n2Min + (betaTarget*ibeta0) * (_n2Max - _n2Min);
148 _n2 = (_n2 + dt*_decay * n2Target) / (1 + dt*_decay);
150 float betaN2 = (_epr0-1) * (_n2 - _n2Min) / (_n2Max - _n2Min);
151 float n1Target = _n1Min + betaN2*ibeta0 * (_n1Max - _n1Min);
152 _n1 = (_n1 + dt*_decay * n1Target) / (1 + dt*_decay);
156 float betaN1 = (_epr0-1) * (_n1 - _n1Min) / (_n1Max - _n1Min);
157 _thrust = _maxThrust * betaN1/((_epr0-1)*(
P0/_atmo.getPressure())*(_atmo.getTemperature()/statT));
158 _thrust *= 1 + _reheat*(_abFactor-1);
162 float beta = 0.8f*betaN2 + 0.2f*betaN1;
164 float ff0 = _maxThrust*_tsfc*(1/(3600.0f*9.8f));
165 _fuelFlow = ff0 *
beta*ibeta0;
167 if(_atsfc > 0) _abFuelFactor = ((_maxThrust*_abFactor*_atsfc)-(_maxThrust*_tsfc))/_abThrust;
168 if(_atsfc == 0 ) _fuelFlow *= 1 + (_abFuelFactor * _reheat * _abFactor);
171 else _fuelFlow += _abThrust*_abFuelFactor*(1/(3600.0f*9.8f))*beta*ibeta0*_reheat;
174 _egt =
T0 +
beta*ibeta0 * (_egt0 -
T0);
177 if(_reverseThrust) _thrust *= -_reverseEff;
180void Jet::getThrust(
float* out)
182 Math::mul3(_thrust, _dir, out);
185 float angle = _rotControl * _maxRot;
186 float s = Math::sin(angle);
187 float c = Math::cos(angle);
189 out[0] = c * o0 + s * out[2];
190 out[2] = -s * o0 + c * out[2];
193void Jet::getTorque(
float* out)
195 out[0] = out[1] = out[2] = 0;
198void Jet::getGyro(
float* out)
200 out[0] = out[1] = out[2] = 0;
const double P0(101325.0)
const double T0(15.+freezing)