328 orbitActuation.
valid=
false;
329 orbitActuation.rotationEffort={};
367 if (matrixInverse._11 > 1000.0f || matrixInverse._11 < -1000.0f || _isnan(matrixInverse._11) || isinf(matrixInverse._11) ||
368 matrixInverse._12 > 1000.0f || matrixInverse._12 < -1000.0f || _isnan(matrixInverse._12) || isinf(matrixInverse._12) ||
369 matrixInverse._13 > 1000.0f || matrixInverse._13 < -1000.0f || _isnan(matrixInverse._13) || isinf(matrixInverse._13) ||
370 matrixInverse._14 > 1000.0f || matrixInverse._14 < -1000.0f || _isnan(matrixInverse._14) || isinf(matrixInverse._14))
372 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after world matrix calculation...");
375 if (matrixInverse._21 > 1000.0f || matrixInverse._21 < -1000.0f || _isnan(matrixInverse._21) || isinf(matrixInverse._21) ||
376 matrixInverse._22 > 1000.0f || matrixInverse._22 < -1000.0f || _isnan(matrixInverse._22) || isinf(matrixInverse._22) ||
377 matrixInverse._23 > 1000.0f || matrixInverse._23 < -1000.0f || _isnan(matrixInverse._23) || isinf(matrixInverse._23) ||
378 matrixInverse._24 > 1000.0f || matrixInverse._24 < -1000.0f || _isnan(matrixInverse._24) || isinf(matrixInverse._24))
380 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after world matrix calculation...");
383 if (matrixInverse._31 > 1000.0f || matrixInverse._31 < -1000.0f || _isnan(matrixInverse._31) || isinf(matrixInverse._31) ||
384 matrixInverse._32 > 1000.0f || matrixInverse._32 < -1000.0f || _isnan(matrixInverse._32) || isinf(matrixInverse._32) ||
385 matrixInverse._33 > 1000.0f || matrixInverse._33 < -1000.0f || _isnan(matrixInverse._33) || isinf(matrixInverse._33) ||
386 matrixInverse._34 > 1000.0f || matrixInverse._34 < -1000.0f || _isnan(matrixInverse._34) || isinf(matrixInverse._34))
388 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after world matrix calculation...");
391 if (matrixInverse._41 > 1000.0f || matrixInverse._41 < -1000.0f || _isnan(matrixInverse._41) || isinf(matrixInverse._41) ||
392 matrixInverse._42 > 1000.0f || matrixInverse._42 < -1000.0f || _isnan(matrixInverse._42) || isinf(matrixInverse._42) ||
393 matrixInverse._43 > 1000.0f || matrixInverse._43 < -1000.0f || _isnan(matrixInverse._43) || isinf(matrixInverse._43) ||
394 matrixInverse._44 > 1000.0f || matrixInverse._44 < -1000.0f || _isnan(matrixInverse._44) || isinf(matrixInverse._44))
396 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after world matrix calculation...");
446 result.x = 0.0f; result.y = 0.0f; result.z = -1.0f;
464 _isnan(localBarycentric.x) || _isnan(localBarycentric.y) || _isnan(localBarycentric.z) ||
465 isinf(localBarycentric.x) || isinf(localBarycentric.y) || isinf(localBarycentric.z))
467 sprintf_s(
msg,
sizeof(
msg),
"\tbarycentric I: %f", localBarycentric.x);
469 sprintf_s(
msg,
sizeof(
msg),
"\tbarycentric J: %f", localBarycentric.y);
471 sprintf_s(
msg,
sizeof(
msg),
"\tbarycentric K: %f", localBarycentric.z);
479 sprintf_s(
msg,
sizeof(
msg),
"\tour barycentric I: %f",
playerships[0].barycentric.x);
481 sprintf_s(
msg,
sizeof(
msg),
"\tour barycentric J: %f",
playerships[0].barycentric.y);
483 sprintf_s(
msg,
sizeof(
msg),
"\tour barycentric K: %f",
playerships[0].barycentric.z);
485 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after groundvec calculation...");
505 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation when windspeed was calculated...");
511 sprintf_s(
msg,
sizeof(
msg),
"\twinddir I: %f", windDirectionOnly.x);
513 sprintf_s(
msg,
sizeof(
msg),
"\twinddir J: %f", windDirectionOnly.y);
515 sprintf_s(
msg,
sizeof(
msg),
"\twinddir K: %f", windDirectionOnly.z);
561 float machWaveEffect;
563 machWaveEffect = powf(
mach, 12.622f);
565 machWaveEffect = 1.0f / ((powf(
mach + 0.169f, 2.0f) - 1.0f) * 2.73f);
574 if (turbInput > 0.0f)
608 float vertical = (
viewscreen->
turbLow * 0.6f + mid * 0.3f + high * 0.1f) * t * penetrationResponse;
615 0.3f * t * penetrationResponse;
621 0.3f * t * penetrationResponse;
625 gust.x = lateralX * 0.01581f;
626 gust.y = vertical * 0.01581f;
627 gust.z = lateralZ * 0.01581f;
636 fabsf(vertical) > 0.5f * t)
648 sprintf_s(
msg,
sizeof(
msg),
"Turbulence clamp triggered");
661 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after windspeed transformed by inverse matrix...");
691 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after wind calculation...");
734 tvmTargetVelocity = parent.
velocity;
737 tvmTargetVelocity = network_objects.
velocity;
739 tvmTargetVelocity = network_objects.
dockingvel;
775 (entryBus.guidance.entryControl||entryBus.guidance.ascentControl||entryBus.guidance.poweredRendezvous)&&entryBus.guidance.valid&&entryBus.guidance.thrust;
777 entryFresh&&entryBus.speedHoldValid;
779 if(continuousEntry) {
780 const auto command=entryBus.guidance.accelerationCommand;
781 entryAcceleration={float(command.x),float(command.y),float(command.z)};
783 }
else if(entrySpeedHold) entryAcceleration.z=float(entryBus.speedHoldAcceleration);
786 float bypassMod = 1.0f;
787 float bypassGrowl = 0.0f;
790 float compressorDensity;
796 compressorDensity = 1.0f;
803 bypassMod += bypassGrowl;
812 float antiIceEffectiveness = 0.0f;
819 float zThrustAvgPercent = 0.0f, zThrustAcceleration = 0.0f, zThrustAcceleration4FF = 0.0f, rcsThrustYPR = 0.0f;
824 const bool dorThrust = orbital.
guidance.
valid && orbital.guidance.thrust &&
827 if(continuousEntry||entrySpeedHold) {
829 entryBus.entryForwardAcceleration,entryBus.entryReverseAcceleration,
842 if(!orbital.guidance.entryControl&&!orbital.guidance.ascentControl&&!orbital.guidance.poweredRendezvous&&
927 f_temp *= leftHealth;
932 f_temp *= rightHealth;
937 f_temp *= centerHealth;
969 if (_isnan(zThrustAcceleration) || isinf(zThrustAcceleration))
980 zThrustAcceleration = 0.0f;
1013 float strength = 0.f, weightedPitch = 0.f;
1019 weightedPitch += weight * (.2f + .8f * output);
1023 strength > 0.f ? weightedPitch / strength : .2f, 0.f,
false,
true,
false);
1030 zThrustAcceleration *= bypassMod;
1038 if (zThrustAcceleration > 0)
1041 if (zThrustAcceleration < 0.0f)
1042 zThrustAcceleration = 0.0f;
1047 if (zThrustAcceleration > 0.0f)
1048 zThrustAcceleration = 0.0f;
1054 zThrustAcceleration *= rainAirThrustMultiplier;
1069 if(entryBus.guidance.entryControl||entryBus.guidance.ascentControl||entryBus.guidance.poweredRendezvous) {
1087 static float rcsThrustOutputX = 0.0f, rcsThrustOutputY = 0.0f, rcsThrustOutputZ = 0.0f;
1137 float groundEffect = 1.0f;
1138 if (
ourcockpit.
wingspanM > 0.0f && wingElevationM < ourcockpit.wingspanM && wingElevationM >= 0.0f)
1149#pragma region Automatic Transmission
1158 signedSpeedKph = result.z * 3600.0f;
1162 if (fabsf(signedSpeedKph) < 0.25f)
1163 signedSpeedKph = 0.0f;
1165 auto GetRatio = [&]() ->
float
1176 auto Lerp = [](
float a,
float b,
float t) ->
float
1178 return a + (b - a) * t;
1181 auto Curve = [&](
float x,
float x0,
float y0,
float x1,
float y1) ->
float
1185 t =
Clamp((x - x0) / (x1 - x0), 0.0f, 1.0f);
1187 return Lerp(y0, y1, t);
1190 auto EngineTorqueCurve = [&](
float tachNorm) ->
float
1197 float t =
Clamp(tachNorm, idleNorm, 1.0f);
1200 return Curve(t, idleNorm, 0.45f, 0.25f, 0.78f);
1203 return Curve(t, 0.25f, 0.78f, 0.50f, 1.00f);
1206 return Curve(t, 0.50f, 1.00f, 0.75f, 0.92f);
1208 return Curve(t, 0.75f, 0.92f, 1.00f, 0.70f);
1211 float ratio = GetRatio();
1215 const float groundVehicleReferenceFwdLimit = 0.0085f;
1217 const float enginePowerW = enginePowerHp * 745.699872f * wear.
thrust;
1220 float launchTractiveEffortG = 0.0f;
1225 float desiredTach =
Clamp(rawPedal, idleNorm, 1.0f);
1230 const float zeroDemandTach =
RiseMath::Max(idleTach, groundVehicleLeverIdle);
1232 float throttleDemand = 0.0f;
1233 float speedLimiterScale = 1.0f;
1238 throttleDemand =
Clamp((desiredTach - zeroDemandTach) /
RiseMath::Max(1.0f - zeroDemandTach, 0.001f), 0.0f, 1.0f);
1241 float speedLimiterMotionKph = 0.0f;
1244 const float limiterDriveDirection = (ratio >= 0.0f) ? 1.0f : -1.0f;
1245 speedLimiterMotionKph = signedSpeedKph * limiterDriveDirection;
1253 speedLimiterScale =
Clamp(limiterScale, 0.0f, 1.0f);
1255 desiredTach *= speedLimiterScale;
1256 throttleDemand *= speedLimiterScale;
1260 const float oldFuel =
fuel;
1273 desiredTach =
fuel = 0.0f;
1281 const float shiftBlend =
1286 float wheelTach = 0.0f;
1287 if (ratio != FLT_MAX)
1288 wheelTach = signedSpeedKph / ratio / 77.7f;
1290 wheelTach =
Clamp(wheelTach, -1.0f, 1.0f);
1292 auto ComputeEngineTach = [&](
float wheel,
float desired,
float shiftSlipBlend) ->
float
1296 const float absWheel = fabsf(wheel);
1298 float converterSlip = 0.0f;
1299 if (throttleDemand > 0.0f && desired > idleTach)
1301 const float stallSlip = 0.65f;
1302 const float speedSlip =
Clamp(1.0f - absWheel /
RiseMath::Max(desired, idleTach + 0.001f), 0.0f, 1.0f);
1303 converterSlip = stallSlip * speedSlip * throttleDemand;
1306 const float slipBlend =
RiseMath::Max(shiftSlipBlend, converterSlip);
1308 float tach = wheel + (desired - wheel) * slipBlend;
1313 return Clamp(tach, 0.0f, 1.2f);
1316 float engineTach = desiredTach;
1317 bool shifted =
false;
1321 engineTach = ComputeEngineTach(wheelTach, desiredTach, shiftBlend);
1325 float downshiftWheelTach = 0.30f;
1326 float kickdownWheelTach = 0.44f;
1330 downshiftWheelTach = 0.36f;
1331 kickdownWheelTach = 0.45f;
1335 downshiftWheelTach = 0.30f;
1336 kickdownWheelTach = 0.44f;
1339 const float upshiftEngineTach = 0.82f;
1340 const float minWheelTachForUpshift = 0.48f;
1343 engineTach > upshiftEngineTach &&
1344 wheelTach > minWheelTachForUpshift &&
1352 const bool coastingDownshift =
1353 wheelTach < downshiftWheelTach;
1355 const bool kickdownDownshift =
1356 throttleDemand > 0.55f && wheelTach < kickdownWheelTach;
1358 if (coastingDownshift || kickdownDownshift)
1371 if (ratio != FLT_MAX)
1372 wheelTach = signedSpeedKph / ratio / 77.7f;
1376 wheelTach =
Clamp(wheelTach, -1.0f, 1.0f);
1380 const float newShiftBlend =
1383 engineTach = ComputeEngineTach(wheelTach, desiredTach, newShiftBlend);
1387 float torqueMultiplier = 0.0f;
1388 float torqueAcceleration = 0.0f;
1389 float powerAcceleration = 0.0f;
1390 float engineAcceleration = 0.0f;
1391 float netAcceleration = 0.0f;
1392 float powerReferenceKph = 0.0f;
1393 float torqueConverterRatioLog = 1.0f;
1394 float driveDemand = throttleDemand;
1395 float gearEngagement = 0.0f;
1396 float idleCreepDemand = 0.0f;
1397 float antiRollbackDemand = 0.0f;
1401 slip = engineTach - wheelTach;
1404 const float driveDirection = (ratio >= 0.0f) ? 1.0f : -1.0f;
1405 const float currentShiftBlend =
1408 torqueMultiplier = EngineTorqueCurve(engineTach);
1411 gearEngagement = 1.0f - currentShiftBlend;
1413 idleCreepDemand = atGroundVehicleIdleLever ?
1414 gearEngagement * Curve(fabsf(signedSpeedKph), 0.0f, idleCreepAtRestDemand, 8.0f, 0.0f) :
1420 const float selectedMotionKph = signedSpeedKph * driveDirection;
1421 if (atGroundVehicleIdleLever && selectedMotionKph < -0.25f)
1422 antiRollbackDemand = gearEngagement * Curve(-selectedMotionKph, 0.25f, 0.10f, 4.0f, 0.55f);
1433 const float peakPowerTachNorm = 0.80f;
1434 const float gearRedlineKph =
RiseMath::Max(absRatio * 77.7f, 1.0f);
1435 powerReferenceKph =
RiseMath::Max(gearRedlineKph * peakPowerTachNorm, 10.0f);
1438 const float peakPowerRadPerSec =
RiseMath::Max(redlineRadPerSec * peakPowerTachNorm, 1.0f);
1439 const float peakEngineTorqueNm = enginePowerW / peakPowerRadPerSec;
1441 const float gearRedlineMps =
RiseMath::Max(gearRedlineKph / 3.6f, 0.5f);
1442 const float gearReduction =
RiseMath::Max(redlineRadPerSec * wheelRadiusM / gearRedlineMps, 0.1f);
1443 const float converterSlipRatio =
1450 const float torqueConverterRatio = 1.0f + (stallTorqueRatio - 1.0f) * converterSlipRatio;
1451 const float drivelineEfficiency = 0.85f;
1453 torqueConverterRatioLog = torqueConverterRatio;
1455 const float maxTorqueLimitedForceN =
1457 peakEngineTorqueNm *
1459 torqueConverterRatio *
1460 drivelineEfficiency /
1465 torqueAcceleration =
1468 maxTorqueLimitedForceN /
1474 const float speedKphAbs = fabsf(signedSpeedKph);
1475 const float speedMps =
RiseMath::Max(speedKphAbs / 3.6f, 0.5f);
1476 const float powerLimitedForceN =
1480 drivelineEfficiency /
1485 powerLimitedForceN /
1491 engineAcceleration = torqueAcceleration;
1492 if (fabsf(powerAcceleration) < fabsf(engineAcceleration))
1493 engineAcceleration = powerAcceleration;
1498 const float engineBrakeStrength = 0.12f;
1499 const float engineBrakeDemand = 1.0f - driveDemand;
1500 const float wheelSpinForBrake =
Clamp(fabsf(wheelTach) - idleTach, 0.0f, 1.0f);
1502 float motionDirection = driveDirection;
1503 if (signedSpeedKph > 0.25f)
1504 motionDirection = 1.0f;
1505 else if (signedSpeedKph < -0.25f)
1506 motionDirection = -1.0f;
1507 else if (wheelTach > 0.001f)
1508 motionDirection = 1.0f;
1509 else if (wheelTach < -0.001f)
1510 motionDirection = -1.0f;
1512 const float engineBrakeAcceleration =
1516 engineBrakeStrength *
1517 maxTorqueLimitedForceN /
1521 engineAcceleration += engineBrakeAcceleration;
1524 const float tireMu = 0.80f;
1527 netAcceleration =
Clamp(engineAcceleration, -tractionLimit, tractionLimit);
1533 if (
playerships[0].groundvehicle && speedLimiterScale < 1.0f)
1540 signedSpeedKph = engineTach * fabsf(ratio) * 77.7f;
1569 actual.z = netAcceleration;
1576 "%7.3f (VT %u CT %i VID %u WT %.0f WF %.2f HP %.0f TEG %.3f LWS %.4f)(spd %5.1f kph)(gear %+i/%4.2f)"
1577 "(pedal %.2f target %.2f lim %.2f snd %.2f idle %.2f demand %.2f drive %.2f creep %.2f hold %.2f engage %.2f clutch %.2f shift %.2f)"
1578 "(engine %2.2f/%4.0f RPM)"
1579 "(wheel %2.2f/%4.0f RPM)"
1580 "(slip %+.4f tq %.2f TCR %.2f tqAcc %+.4f powRef %.1f powAcc %+.4f engAcc %+.4f acc %+.4f actualZ %+.4f drvZ %+.4f)"
1581 "(ref %i roll %.4f pitch %.4f)\n",
1589 launchTractiveEffortG,
1590 driveLiveWeightScale,
1612 torqueConverterRatioLog,
1619 actual.z * driveLiveWeightScale,
1640 result.x =
actual.x * fElapsedTime; result.y =
actual.y * fElapsedTime; result.z =
actual.z * fElapsedTime;
1643 if (result.x > 100.0f || result.x < -100.0f || _isnan(result.x) || isinf(result.x) ||
1644 result.y > 100.0f || result.y < -100.0f || _isnan(result.y) || isinf(result.y) ||
1645 result.z > 100.0f || result.z < -100.0f || _isnan(result.z) || isinf(result.z))
1647 sprintf_s(
msg,
sizeof(
msg),
"\tET: %f", fElapsedTime);
1649 sprintf_s(
msg,
sizeof(
msg),
"\tactual I: %f",
actual.x);
1651 sprintf_s(
msg,
sizeof(
msg),
"\tactual J: %f",
actual.y);
1653 sprintf_s(
msg,
sizeof(
msg),
"\tactual K: %f",
actual.z);
1655 sprintf_s(
msg,
sizeof(
msg),
"\tresult I: %f", result.x);
1657 sprintf_s(
msg,
sizeof(
msg),
"\tresult J: %f", result.y);
1659 sprintf_s(
msg,
sizeof(
msg),
"\tresult K: %f", result.z);
1665 sprintf_s(
msg,
sizeof(
msg),
"\tzThrustAcceleration: %f", zThrustAcceleration);
1667 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after xy thrust spoolup...");
1675 if (result.x > 100.0f || result.x < -100.0f || _isnan(result.x) || isinf(result.x) ||
1676 result.y > 100.0f || result.y < -100.0f || _isnan(result.y) || isinf(result.y) ||
1677 result.z > 100.0f || result.z < -100.0f || _isnan(result.z) || isinf(result.z))
1679 sprintf_s(
msg,
sizeof(
msg),
"\tET: %f", fElapsedTime);
1685 sprintf_s(
msg,
sizeof(
msg),
"\tfuel: %f",
fuel);
1691 sprintf_s(
msg,
sizeof(
msg),
"\tresult I: %f", result.x);
1693 sprintf_s(
msg,
sizeof(
msg),
"\tresult J: %f", result.y);
1695 sprintf_s(
msg,
sizeof(
msg),
"\tresult K: %f", result.z);
1697 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after weight adjustment spoolup...");
1702 if (fElapsedTime != 0)
1713 orbitActuation.sequence++;
1714 orbitActuation.programTime=orbitBus.ProgramTime;
1715 orbitActuation.guidanceTime=orbitBus.orbit.sourceTime;
1716 orbitActuation.dt=fElapsedTime;orbitActuation.dor=orbitBus.AFCS.DorOn;
1717 orbitActuation.phase=orbitBus.orbit.guidance.phase;
1718 orbitActuation.thrust=orbitBus.orbit.guidance.thrust;
1719 orbitActuation.valid=
true;
1721 orbitActuation.mainBodyKms2={0,0,zThrustAcceleration*wear.
thrust*weightScale};
1723 orbitActuation.rcsBodyKms2=delivered-orbitActuation.mainBodyKms2;
1726 orbitActuation.thrustWorldKms2=fElapsedTime>0?vector(world)/fElapsedTime:
Orbital::Vec{};
1730 static_assert(
MAX_ENGINES==3,
"Update Orbit actuation capture for the engine layout");
1732 orbitActuation.lever[i]=orbitBus.EngineThrustLever[i];
1733 orbitActuation.output[i]=orbitBus.EngineThrustOutput[i];
1736 orbitActuation.Accumulate(fElapsedTime,orbitActuation.mainBodyKms2,orbitActuation.rcsBodyKms2);
1744 sprintf_s(
msg,
sizeof(
msg),
"\tET: %f", fElapsedTime);
1752 sprintf_s(
msg,
sizeof(
msg),
"\tresult I: %f", result.x);
1754 sprintf_s(
msg,
sizeof(
msg),
"\tresult J: %f", result.y);
1756 sprintf_s(
msg,
sizeof(
msg),
"\tresult K: %f", result.z);
1759 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after thrust adjusted...");
1767 orbitActuation.aeroSampleTime = -1;
1770#pragma region Atmospheric Physics
1781 float S, tempaoa = 0.0f;
1782 float tempDragTail = 0.0f;
1786 static float fullsec = 0.0f;
1787 fullsec += fElapsedTime;
1810 ias = sqrtf(2 * qcOverRho0);
1835 const float molarMass = 0.9914103f + 29.5230397f / (1.0f + powf(
RiseMath::Max(
playerships[0].mslKm, 0) / 378.4386f, 1.425581f));
1836 const float molarMassMod = 29.0f / molarMass;
1840 sprintf_s(
msg,
sizeof msg,
"speedOfSoundKms was NAN, OAT %.3f MMM %.3f", outsideAirTemperatureKelvin, molarMassMod);
1857#pragma region Thermodynamics
1866 float radiationRate = 0.001f * 0.000000056703f * (powf(outsideAirTemperatureKelvin, 4.0f) - powf(airframeTempKelvin, 4.0f)) * (
ourcockpit.
i12WingAreaOneSideSqFt * 4.0f * 0.092903f) * 0.000526565066841f;
1869 if (radiationRate > 0)
1875 if (
playerships[0].baydoor) outsideConductionRate *= 1.2f;
1907 orbitActuation.airQPa=qxyz_lbsPerSqFt*47.88025898;
1909 orbitActuation.airMach=
mach;orbitActuation.airIasKms=
ias;orbitActuation.airTatC=
tatCelsius;
1915 static bool favorLeft = rand() % 2 == 0;
1916 static float leftWing = 0.0f;
1917 static float rightWing = 0.0f;
1920 if (leftWing >= 1.0f)
1926 favorLeft = rand() % 2 == 0;
1938 if (rightWing >= 1.0f)
1944 favorLeft = rand() % 2 == 0;
1962 float cloudSeverity = 0.0f;
1969 cloudSeverity *= 0.2f;
1994 float temperatureSeverity = 0.0f;
1995 if (leadingEdgeTempCelsius <= 0)
1996 temperatureSeverity = -leadingEdgeTempCelsius / 35.0f;
1997 const float iceIntensity = (dropSeverity + cloudSeverity) * temperatureSeverity;
2004 const float iceAccretion = 11.0f * iceIntensity * fElapsedTime / 60.0f / 60.0f;
2013 const float iceAccretion = tas / 16.0f * fElapsedTime * 29.0f * iceIntensity;
2024 const float pressureFactor = 0.8166667f - 1.05f * atmospheres + 0.2333333f * atmospheres * atmospheres;
2035 float melt = probeTempCelsius / 70.0f * 18.288f / 135.224f * fElapsedTime;
2041 if (leadingEdgeTempCelsius > 0)
2043 melt = leadingEdgeTempCelsius / 107.0f * 18.288f / 135.224f * fElapsedTime;
2121 if (f_deflect > 1.0f)
2124 f_deflect = sqrtf(1.0f - f_deflect);
2125 if (f_deflect < 0.25f)
2132#pragma region AUTOFLYTE SYSTEM
2142 constexpr float glsUsableRangeKm = 42.6f;
2156#pragma region Vertical modes
2172 if (dme > glsUsableRangeKm)
2174 sprintf_s(
msg,
sizeof msg,
"LVT DME %.3f > %.1f", dme, glsUsableRangeKm);
2190 if (dme <= glsUsableRangeKm &&
2199 command.
name =
"AuralGlideslopeCaptured";
2269 if (diff > 0.052359877559829887307710723054658f)
2270 diff = 0.052359877559829887307710723054658f;
2271 else if (diff < -0.052359877559829887307710723054658f)
2272 diff = -0.052359877559829887307710723054658f;
2287 if (flight.OnGround || !
FlightPath::Valid(flight.GroundSpeedKms, flight.VerticalSpeedKms)) {
2289 afcs.DesiredPitchRadians = flight.PitchAttitudeRadians;
2292 flight.GroundSpeedKms, flight.VerticalSpeedKms, flight.PitchAttitudeRadians,
2293 afcs.DesiredPitchRadians, fElapsedTime));
2304 if (diff > 0.052359877559829887307710723054658f)
2305 diff = 0.052359877559829887307710723054658f;
2306 else if (diff < -0.05235987755982988730771072305465f)
2307 diff = -0.05235987755982988730771072305465f;
2333 static bool previousDorAircraft=
false;
2335 if(previousDorAircraft!=dorAircraft) {
2338 previousDorAircraft=dorAircraft;
2351 const float dt=
Clamp(fElapsedTime,1.0f/240.0f,1.0f/20.0f);
2356 const auto [unusedStick,pitchError,desiredRate,rateError,uP,uUnsat,uSat,KpStick,KiStick,maxRate,saturated]=pitchResult;
2359#pragma region Logging
2360 static float logTimer = 0.0f;
2361 static int logFile = -1;
2364 _sopen_s(&logFile,
"pitchPid.log",
2365 _O_RDWR | _O_CREAT | _O_TRUNC | _O_TEXT | _O_SEQUENTIAL,
2366 SH_DENYWR, S_IWRITE);
2370 if (logTimer >= 0.25f)
2374 sprintf_s(
msg,
sizeof(
msg),
2375 "AP_PITCH | p=%.2f des=%.2f err=%.2f | "
2376 "pRate=%.2f desR=%.2f rErr=%.2f | "
2377 "uP=%.3f I=%.3f uUns=%.3f uSat=%.3f sat=%d | "
2378 "Kp=%.3f Ki=%.3f maxR=%.2f in=%.3f\n",
2395 _write(logFile,
msg, (
unsigned)strlen(
msg));
2415 const float trimRateDegPerSec = 0.20f;
2416 const float trimRateRadPerSec = trimRateDegPerSec * (
RiseMath::Pi / 180.0f);
2419 const float trimThreshold = 0.10f;
2424 if (fabsf(elevator) > trimThreshold)
2437 float trimDirection = (elevator > 0 ? 1.0f : -1.0f);
2440 float trimDelta = trimDirection * trimRateRadPerSec * fElapsedTime;
2478 if (hdg2obj > 360.0f)
2480 else if (hdg2obj <= 0.0f)
2486 if (correct > 180.0f)
2488 else if (correct < -180.0f)
2490 if (correct > 90.0f)
2491 correct = 180.0f - correct;
2492 else if (correct < -90.0f)
2493 correct = -180.0f - correct;
2510#pragma region Lateral modes
2517 if (hdgdiff > 180.0f)
2527 command.
name =
"AuralLocalizerCaptured";
2537 if (hdg2obj > 360.0f)
2539 else if (hdg2obj <= 0.0f)
2547 if (correct > 180.0f)
2549 else if (correct < -180.0f)
2551 if (correct > 90.0f)
2552 correct = 180.0f - correct;
2553 else if (correct < -90.0f)
2554 correct = -180.0f - correct;
2565 if (correct > 45.0f)
2567 else if (correct < -45.0f)
2572 correct *= dme * 0.25f;
2576 if (trkadj > 360.0f)
2578 else if (trkadj <= 0.0f)
2592 if (desiredrollDegrees < -180.0f)
2593 desiredrollDegrees = 360.0f + desiredrollDegrees;
2594 else if (desiredrollDegrees > 180.0f)
2595 desiredrollDegrees = desiredrollDegrees - 360.0f;
2597 desiredrollDegrees =
Clamp(desiredrollDegrees, -15, 15);
2603 float maxBank =
Lerp(5.0f, 30.0f, t);
2605 desiredrollDegrees =
Clamp(desiredrollDegrees, -maxBank, maxBank);
2608 desiredrollDegrees =
Clamp(desiredrollDegrees, -30, 30);
2703 leveling.
enabled = tvmBus.AFCS.TvmOn && !tvmBus.AFCS.DorOn &&
2707 leveling.
airborne = !tvmShip.groundvehicle && !tvmShip.docked &&
2709 leveling.
frozen = tvmBus.FlightFreeze;
2710 leveling.
ias = tvmBus.IndicatedAirspeedKms;
2711 leveling.
stall = tvmBus.ComputedVsKms;
2714 leveling.
dt = fElapsedTime;
2715 leveling.
radial = {tvmShip.position.x,tvmShip.position.y,tvmShip.position.z};
2716 leveling.
rotation.
frame = {{tvmBody._11,tvmBody._12,tvmBody._13},
2717 {tvmBody._21,tvmBody._22,tvmBody._23},{tvmBody._31,tvmBody._32,tvmBody._33}};
2718 leveling.
rotation.
rates = {-tvmShip.pitch,-tvmShip.yawRadPerSec,-tvmShip.rollRadPerSec};
2721 auto tvmWingHealth = [](
int health) {
return health == -1 ? 1.0 : (std::clamp)(health/127.0,0.0,1.0); };
2730 Clamp(pitchThrust,-1.0f,1.0f),
Clamp(rollThrustTotal,-1.0f,1.0f));
2731 pitchThrust = float(levelCommand.pitch);
2732 rollThrustTotal = float(levelCommand.roll);
2750 coast.
frame = {{body._11,body._12,body._13},{body._21,body._22,body._23},{body._31,body._32,body._33}};
2752 coast.
effort = available;
2753 auto wing = [](
int health) {
return health == -1 ? 1.0 : (std::clamp)(health/127.0,0.0,1.0); };
2758 {VehicleWear::ApplyControlPlay(viewscreen->pitchInput,wear.controlPlay),
2759 VehicleWear::ApplyControlPlay(viewscreen->yawInput,wear.controlPlay),
2760 VehicleWear::ApplyControlPlay(viewscreen->rollInput,wear.controlPlay)});
2762 pitchThrust =
static_cast<float>(rotation.x);
2763 yawThrust =
static_cast<float>(rotation.y);
2764 rollThrustTotal =
static_cast<float>(rotation.z);
2767 orbitActuation.rotationEffort={
Clamp(pitchThrust,-1.0f,1.0f),
Clamp(yawThrust,-1.0f,1.0f),
Clamp(rollThrustTotal,-1.0f,1.0f)};
2771 float rollRightThrustLeftSide = rollThrustTotal;
2774 float rollRightThrustRightSide = rollThrustTotal;
2782 rcsThrustYPR = (fabsf(rollRightThrustLeftSide + rollRightThrustRightSide) + fabsf(yawThrust) + fabsf(pitchThrust)) /
totalWeightLbs *
gForceKmSSC;
2785 rollRightThrustLeftSide *= wear.
thrust;
2786 rollRightThrustRightSide *= wear.
thrust;
2787 yawThrust *= wear.
thrust;
2788 pitchThrust *= wear.
thrust;
2822 command.
name =
"AuralStall";
2841 float tempLiftWingRight = 0.0f;
float tempDragWingRight = 0.0f;
2860 float tempLiftWingLeft = 0.0f;
float tempDragWingLeft = 0.0f;
2877 f_temp = (tempLiftWingRight + tempLiftWingLeft + rollRightThrustLeftSide - rollRightThrustRightSide) *
gForceKmSSC /
totalWeightLbs * fElapsedTime;
2878 f_temp *= groundEffect;
2880 if (fElapsedTime != 0.0f)
2882 sprintf_s(
msg,
sizeof(
msg),
"X%7.3f Y%7.3f Z%7.3f wing lift", 0.0f, f_temp *
oneOvergForceKmssC / fElapsedTime, 0.0f);
2894 sprintf_s(
msg,
sizeof(
msg),
"\tET: %f", fElapsedTime);
2902 sprintf_s(
msg,
sizeof(
msg),
"\tlift2: %f", f_temp);
2906 sprintf_s(
msg,
sizeof(
msg),
"\ttempLiftWingRight: %f", tempLiftWingRight);
2908 sprintf_s(
msg,
sizeof(
msg),
"\ttempLiftWingLeft: %f", tempLiftWingLeft);
2910 sprintf_s(
msg,
sizeof(
msg),
"\trollRightThrustLeftSide: %f", rollRightThrustLeftSide);
2912 sprintf_s(
msg,
sizeof(
msg),
"\trollRightThrustRightSide: %f", rollRightThrustRightSide);
2914 sprintf_s(
msg,
sizeof(
msg),
"\tgroundeffect: %f", groundEffect);
2917 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after lift2 application...");
2955 const double externalMoment = momentp + weatherMoment + engineMoment;
2961 auto tailMoment = [&](
double surface) {
2968 const double available = (std::clamp)(
double(
ourcockpit.
power),0.0,1.0) *
2973 capacity,previous,f_deflect,fElapsedTime,tailMoment);
2980 pitchThrust=float(applied);
2981 orbitActuation.pitchResidualMoment=allocation.residual;
2982 }
else orbitActuation.pitchResidualMoment=0;
2983 orbitActuation.ascentPitchActive=dorPitch;
2985 orbitActuation.pitchExternalMoment=externalMoment;
2987 float tempLiftElevator = 0.0f;
3001 if (_isnan(tempDragTail) || isinf(tempDragTail))
3003 sprintf_s(
msg,
sizeof(
msg),
"Going to crap out on air friction tempDragHTail!");
3006 sprintf_s(
msg,
sizeof(
msg),
"Cd: %f", Cd);
3010 sprintf_s(
msg,
sizeof(
msg),
"S: %f", S);
3014 sprintf_s(
msg,
sizeof(
msg),
"dragIceMod: %f", dragIceMod);
3025 if (fElapsedTime != 0.0f)
3027 sprintf_s(
msg,
sizeof(
msg),
"X%7.3f Y%7.3f Z%7.3f htail lift", 0.0f, f_temp *
oneOvergForceKmssC / fElapsedTime, 0.0f);
3039 sprintf_s(
msg,
sizeof(
msg),
"\tET: %f", fElapsedTime);
3047 sprintf_s(
msg,
sizeof(
msg),
"\tlift: %f", f_temp);
3050 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after lift application...");
3083#pragma region Directional Moment
3085 float tempLiftRudder = 0.0f;
3115 if (_isnan(tempDragTail) || isinf(tempDragTail))
3117 sprintf_s(
msg,
sizeof(
msg),
"Going to crap out on air friction tempDragVTail!");
3120 sprintf_s(
msg,
sizeof(
msg),
"Cd: %f", Cd);
3124 sprintf_s(
msg,
sizeof(
msg),
"S: %f", S);
3128 sprintf_s(
msg,
sizeof(
msg),
"dragIceMod: %f", dragIceMod);
3145 float business = 0.0f;
3190 float tireTurnForce = 0.0f;
3191 float steeringCenteringForce = 0.0f;
3231 const float differentialSideSpeedKms =
3267 f_temp *= fElapsedTime;
3285 if (_isnan(result.z) || isinf(result.z))
3287 sprintf_s(
msg,
sizeof(
msg),
"Going to crap out on air friction result.z!");
3290 sprintf_s(
msg,
sizeof(
msg),
"f_temp: %f", f_temp);
3300 sprintf_s(
msg,
sizeof(
msg),
"tempDragWingRight: %f", tempDragWingRight);
3302 sprintf_s(
msg,
sizeof(
msg),
"tempDragWingLeft: %f", tempDragWingLeft);
3304 sprintf_s(
msg,
sizeof(
msg),
"tempDragTail: %f", tempDragTail);
3308 sprintf_s(
msg,
sizeof(
msg),
"fElapsedTime: %f", fElapsedTime);
3328 result *= wear.
drag;
3330 if (fabsf(result.x) > 100.0f || _isnan(result.x) || isinf(result.x) ||
3331 fabsf(result.y) > 100.0f || _isnan(result.y) || isinf(result.y) ||
3332 fabsf(result.z) > 100.0f || _isnan(result.z) || isinf(result.z))
3334 sprintf_s(
msg,
sizeof(
msg),
"ET: %f", fElapsedTime);
3336 sprintf_s(
msg,
sizeof(
msg),
"Result I: %f", result.x);
3338 sprintf_s(
msg,
sizeof(
msg),
"Result J: %f", result.y);
3340 sprintf_s(
msg,
sizeof(
msg),
"Result K: %f", result.z);
3352 sprintf_s(
msg,
sizeof(
msg),
"f_temp: %f", f_temp);
3356 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after air friction...");
3361 if (fElapsedTime != 0.0f)
3373 "%7.3f AIR VT%u CT%i VID%u WT%.0f WF%.2f spd%.1f dens%.3f relZ%+.5f dragGZ%+.3f qZ%.3f CxZ%.6f\n",
3396 if(fElapsedTime>0) {
3398 orbitActuation.aeroBodyKms2={aeroDelta.x/fElapsedTime,aeroDelta.y/fElapsedTime,aeroDelta.z/fElapsedTime};
3399 orbitActuation.aeroSampleTime=pitchBus.ProgramTime;
3428 sprintf_s(
msg,
sizeof(
msg),
"X%7.3f Y%7.3f Z%7.3f parent",
3451 sprintf_s(
msg,
sizeof(
msg),
"ET: %f", fElapsedTime);
3466 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation before sumofforces application...");
3485 sprintf_s(
msg,
sizeof(
msg),
"ET: %f", fElapsedTime);
3499 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after putting velocity in universe terms...");
3516 if (f_temp != -1.0f)
3520 float f_AGLeye =
f_AGL;
3526 if (eyeAGL != -1.0f)
3528 f_AGLeye = eyeAGL - 0.0007f;
3552 if (fabsf(cross.y) > FLT_EPSILON)
3556 else if (cross.x < 0.0f)
3560 levelerpitch = atanf(cross.z / sqrtf(cross.y * cross.y + cross.x * cross.x));
3591 float f_AGLcg =
f_AGL;
3627 bool touchdown =
false;
3634 const float target = -finalAglKm;
3638 const double mag = 1.0 / sqrt(gx * gx + gy * gy + gz * gz);
3640 gx *= mag; gy *= mag; gz *= mag;
3641 gx *=
static_cast<double>(target); gy *=
static_cast<double>(target); gz *=
static_cast<double>(target);
3652 sprintf_s(
msg,
sizeof msg,
"REPOSITION terrain placement %.6f km; positional correction excluded from G forces", target);
3658 RiseMath::Vector3 impactSof(
static_cast<float>(gx),
static_cast<float>(gy),
static_cast<float>(gz));
3660 if (fElapsedTime != 0.0f)
3671 if (
gridarray[31][31].pri_landform == 1)
3686 logger->
Log(
"Viewscreen::Movement Splashdown!");
3694 logger->
Log(
"Viewscreen::Movement Touchdown!");
3719 if (finalAglKm > 0.0001524f || cmDot > 0.0f)
3721 sprintf_s(
msg,
sizeof msg,
"Movement releasing us to APN mode... we were at %.4f,%.4f (%.4f) %.4f", f_AGLcg, f_AGLeye,
citystuff.
elevation, finalAglKm);
3739 sprintf_s(
msg,
sizeof msg,
"Movement snapping us back to 0 as we were at %.4f,%.4f (%.4f) %.4f", f_AGLcg, f_AGLeye,
citystuff.
elevation, finalAglKm);
3742 const float target = -finalAglKm;
3746 const double mag = 1.0 / sqrt(gx * gx + gy * gy + gz * gz);
3747 gx *= mag; gy *= mag; gz *= mag;
3748 gx *=
static_cast<double>(target); gy *=
static_cast<double>(target); gz *=
static_cast<double>(target);
3760 const bool playLevelingContactSound =
3762 static float oldlevelerroll = 0.0f, oldlevelerpitch = 0.0f;
3763 f_temp = fElapsedTime * sqrtf(277581.7f /
totalWeightLbs) * 0.2f;
3783 f_temp = fElapsedTime * sqrtf(277581.7f /
totalWeightLbs) * 0.15f;
3815 if ((
levelerroll > 0.001f && oldlevelerroll < 0.001f) ||
3819 if (playLevelingContactSound && fabsf(
playerships[0].rollRadPerSec) > FLT_EPSILON &&
3822 logger->
Log(
"Viewscreen::Movement Leveling roll...");
3837 if (playLevelingContactSound && fabsf(
playerships[0].pitch) > FLT_EPSILON &&
3840 logger->
Log(
"Viewscreen::Movement Leveling pitch...");
3873 cross.y = locvel.y * fabsf(loclev.y);
3876 float leftMain = 0.0f, rightMain = 0.0f, noseStrut = 0.0f;
3877 bool gldDeploy =
false;
3879 if (surfaceDot < 0.0f && fElapsedTime != 0.0f)
3888 float shockKmss = -cross.y / fElapsedTime;
3894 float shockKms = shockKmss * fElapsedTime;
3898 float absorbKms = 0.0f;
3925 absorbKms += leftMain * absorbCapacityKms;
3929 sprintf_s(
msg,
sizeof(
msg),
"*** Left Main absorbed %.3f (%.3f/s) %.3fG, levelerpitch %.3f levelerroll %.3f", leftMain * absorbCapacityKms, leftMain * absorbCapacityKms / fElapsedTime, leftMain * absorbCapacityKms *
oneOvergForceKmssC,
levelerpitch,
levelerroll);
3954 absorbKms += rightMain * absorbCapacityKms;
3958 sprintf_s(
msg,
sizeof(
msg),
"*** Right Main absorbed %.3f/f (%.3f/s) %.3fG, levelerpitch %.3f levelerroll %.3f", rightMain * absorbCapacityKms, rightMain * absorbCapacityKms / fElapsedTime, rightMain * absorbCapacityKms *
oneOvergForceKmssC,
levelerpitch,
levelerroll);
3983 absorbKms += noseStrut * absorbCapacityKms;
3987 sprintf_s(
msg,
sizeof(
msg),
"*** Nose gear absorbed %.3f/f (%.3f/s) %.3fG, levelerpitch %.3f", noseStrut * absorbCapacityKms, noseStrut * absorbCapacityKms / fElapsedTime, noseStrut * absorbCapacityKms *
oneOvergForceKmssC,
levelerpitch);
3996 const float verticalDisplacementKm = (shockKms * shockKms) / (2.0f *
gravityKmssC);
3997 const float absorbedRatio = verticalDisplacementKm > FLT_EPSILON
3998 ?
RiseMath::Min(1.0f, compliantTravelKm / verticalDisplacementKm)
4000 absorbKms = shockKms * absorbedRatio;
4001 const float suspensionShare = compliantTravelKm > FLT_EPSILON
4002 ? bumpTravelKm / compliantTravelKm
4007 if (absorbKms > shockKms)
4008 absorbKms = shockKms;
4010 sprintf_s(
msg,
sizeof(
msg),
"X%7.3f Y%7.3f Z%7.3f struts", 0.0f, -absorbKms *
oneOvergForceKmssC / fElapsedTime, 0.0f);
4021 sprintf_s(
msg,
sizeof(
msg),
"*** TD force was %.3f/f (%.3f/s) %.3fG, absorbed %.3f/f (%.3f/s) %.3fG", -cross.y, -cross.y / fElapsedTime, -cross.y *
oneOvergForceKmssC, absorbKms, absorbKms / fElapsedTime, absorbKms *
oneOvergForceKmssC);
4027 sprintf_s(
msg,
sizeof(
msg),
"*** Remaining force was %.3fG", remainingG);
4030 if (remainingG * noseStrut > 0.333f)
4037 if (remainingG * leftMain > 0.5f)
4044 if (remainingG * rightMain > 0.5f)
4058#pragma region Ground Friction
4063 if (_isnan(locvel.x) || _isnan(locvel.y) || _isnan(locvel.z) ||
4064 isinf(locvel.x) || isinf(locvel.y) || isinf(locvel.z))
4068 else if (fElapsedTime != 0.0f)
4072 auto IsBadFloat = [](
float v) ->
bool
4074 return _isnan(v) || isinf(v);
4077 auto ClampFloat = [](
float v,
float lo,
float hi) ->
float
4086 auto ApproachZero = [](
float value,
float amount) ->
float
4094 return value < 0.0f ? 0.0f : value;
4100 return value > 0.0f ? 0.0f : value;
4106 auto Length2D = [](
float x,
float z) ->
float
4108 return sqrtf(x * x + z * z);
4127 float muStatic = 0.60f;
4128 float muKinetic = 0.45f;
4129 float rollingResistanceCrr = 0.025f;
4130 float terrainRoughnessJitterCoef = 0.005f;
4139 rollingResistanceCrr = 0.017f;
4140 terrainRoughnessJitterCoef = 0.005f;
4147 rollingResistanceCrr = 0.014f;
4148 terrainRoughnessJitterCoef = 0.001f;
4156 rollingResistanceCrr = 0.0f;
4157 terrainRoughnessJitterCoef = 0.0f;
4168 rollingResistanceCrr /= 3.0f;
4169 terrainRoughnessJitterCoef /= 3.0f;
4173 rollingResistanceCrr *= 0.5f;
4174 terrainRoughnessJitterCoef *= 0.5f;
4179 if (rollingResistanceCrr <= 0.0f)
4180 rollingResistanceCrr = 0.025f;
4184 if (rollingResistanceCrr >= 0.060f)
4189 else if (rollingResistanceCrr >= 0.035f)
4196 if (IsBadFloat(rollingResistanceCrr))
4198 rollingResistanceCrr = 0.025f;
4202 if (IsBadFloat(terrainRoughnessJitterCoef))
4204 terrainRoughnessJitterCoef = 0.0f;
4208 if (IsBadFloat(muStatic))
4214 if (IsBadFloat(muKinetic))
4222 const float GAME_ROLLING_RESISTANCE_SCALE = 1.0f;
4223 const float GAME_ROUGHNESS_JITTER_SCALE = 1.0f;
4224 const float GAME_SLIDING_FRICTION_SCALE = 1.0f;
4225 const float BRAKE_POWER_SCALE = 1.5f;
4227 rollingResistanceCrr *= GAME_ROLLING_RESISTANCE_SCALE;
4228 terrainRoughnessJitterCoef *= GAME_ROUGHNESS_JITTER_SCALE;
4230 rollingResistanceCrr = ClampFloat(rollingResistanceCrr, 0.0f, 0.250f);
4231 terrainRoughnessJitterCoef = ClampFloat(terrainRoughnessJitterCoef, 0.0f, 0.250f);
4232 muStatic = ClampFloat(muStatic, 0.0f, 2.0f);
4233 muKinetic = ClampFloat(muKinetic, 0.0f, 2.0f);
4237 static float targetRoughnessFrictionJitter = 0.0f;
4239 if (terrainRoughnessJitterCoef <= 0.0f)
4241 targetRoughnessFrictionJitter = 0.0f;
4248 if (fabsf(diff) < 0.0001f)
4250 targetRoughnessFrictionJitter =
RandomFloat() * terrainRoughnessJitterCoef * 2.0f;
4254 if (IsBadFloat(targetRoughnessFrictionJitter))
4256 targetRoughnessFrictionJitter = 0.0f;
4260 if (IsBadFloat(diff))
4270 sprintf_s(
msg,
sizeof(
msg),
"diff: %f", diff);
4272 sprintf_s(
msg,
sizeof(
msg),
"fElapsedTime: %f", fElapsedTime);
4285 sprintf_s(
msg,
sizeof(
msg),
"diff: %f", diff);
4287 sprintf_s(
msg,
sizeof(
msg),
"fElapsedTime: %f", fElapsedTime);
4308 const float startingRollingResistanceCrr = ClampFloat(
4310 effectiveRollingResistanceCrr,
4313 float staticDeltaV = effectiveMuStatic * normalG *
gravityKmssC * fElapsedTime;
4314 float kineticDeltaV = effectiveMuKinetic * normalG *
gravityKmssC * fElapsedTime;
4315 float rollingDeltaV = effectiveRollingResistanceCrr * normalG *
gravityKmssC * fElapsedTime;
4316 float startingRollingDeltaV = startingRollingResistanceCrr * normalG *
gravityKmssC * fElapsedTime;
4318 if (IsBadFloat(staticDeltaV))
4320 staticDeltaV = 0.0f;
4324 if (IsBadFloat(kineticDeltaV))
4326 kineticDeltaV = 0.0f;
4330 if (IsBadFloat(rollingDeltaV))
4332 rollingDeltaV = 0.0f;
4336 if (IsBadFloat(startingRollingDeltaV))
4338 startingRollingDeltaV = 0.0f;
4344 const float maxGroundDeltaV =
gravityKmssC * fElapsedTime;
4346 if (staticDeltaV > maxGroundDeltaV)
4347 staticDeltaV = maxGroundDeltaV;
4349 if (kineticDeltaV > maxGroundDeltaV)
4350 kineticDeltaV = maxGroundDeltaV;
4353 if (rollingDeltaV > maxGroundDeltaV)
4354 rollingDeltaV = maxGroundDeltaV;
4356 if (startingRollingDeltaV > maxGroundDeltaV)
4357 startingRollingDeltaV = maxGroundDeltaV;
4359 bool brakeSkid =
false;
4364 const float oldLateralVelX = newlocvel.x;
4365 const float oldVerticalVelY = newlocvel.y;
4369 newlocvel.x = groundTiresSupporting
4371 : ApproachZero(newlocvel.x, kineticDeltaV);
4372 const float remainingLateralSlipKms = fabsf(newlocvel.x);
4376 newlocvel.y = ApproachZero(newlocvel.y, kineticDeltaV);
4378#pragma region Landing Gear Shear Force
4382 const float NOSE_SHEAR_LIMIT = 0.35f;
4383 const float MAIN_SHEAR_LIMIT = 0.55f;
4386 const float vertical_g = fmaxf(
gndcontactG, 0.10f);
4389 float groundSpeedInstantKms = Length2D(newlocvel.x, newlocvel.z);
4392 float lateral_g_nose = 0.0f;
4395 lateral_g_nose = fabsf(
4396 groundSpeedInstantKms *
4397 groundSpeedInstantKms *
4403 if (IsBadFloat(lateral_g_nose))
4404 lateral_g_nose = 0.0f;
4407 float lateralDeltaVKms = fabsf(oldLateralVelX - newlocvel.x);
4408 float lateral_g_main = 0.0f;
4410 if (fElapsedTime > 0.0f)
4411 lateral_g_main = lateralDeltaVKms / fElapsedTime * inv_g;
4413 if (IsBadFloat(lateral_g_main))
4414 lateral_g_main = 0.0f;
4416 const float lateral_g_left = lateral_g_main;
4417 const float lateral_g_right = lateral_g_main;
4419 const float nose_shear_ratio = lateral_g_nose / vertical_g;
4420 const float left_shear_ratio = lateral_g_left / vertical_g;
4421 const float right_shear_ratio = lateral_g_right / vertical_g;
4423 const float nose_capacity_limit = NOSE_SHEAR_LIMIT * fmaxf(noseStrut, 0.0f);
4424 const float main_capacity_limitL = MAIN_SHEAR_LIMIT * fmaxf(leftMain, 0.0f);
4425 const float main_capacity_limitR = MAIN_SHEAR_LIMIT * fmaxf(rightMain, 0.0f);
4427 if (nose_capacity_limit > 0.0f && nose_shear_ratio > nose_capacity_limit)
4431 sprintf_s(
msg,
sizeof(
msg),
4432 "*** Nose gear collapse (side load) def %.3f gs %.3f vlat %.3f vg %.2f rawG %.2f lat_g %.3f ratio %.3f limit %.3f vvel %.3f wb %.3f",
4434 groundSpeedInstantKms,
4440 nose_capacity_limit,
4446 if (main_capacity_limitL > 0.0f && left_shear_ratio > main_capacity_limitL)
4450 sprintf_s(
msg,
sizeof(
msg),
4451 "*** Left main collapse (side load) vlat %.3f vg %.2f rawG %.2f lat_g %.3f ratio %.3f limit %.3f vvel %.3f",
4457 main_capacity_limitL,
4462 if (main_capacity_limitR > 0.0f && right_shear_ratio > main_capacity_limitR)
4466 sprintf_s(
msg,
sizeof(
msg),
4467 "*** Right main collapse (side load) vlat %.3f vg %.2f rawG %.2f lat_g %.3f ratio %.3f limit %.3f vvel %.3f",
4473 main_capacity_limitR,
4481 float dynamicMod = 0.0f;
4482 float effectiveLeftBrake = 0.0f;
4483 float effectiveRightBrake = 0.0f;
4484 float shiftHoldBrake = 0.0f;
4489 effectiveRightBrake = effectiveLeftBrake;
4510 effectiveLeftBrake = 1.0f;
4511 effectiveRightBrake = 1.0f;
4518 shiftHoldBrake =
Clamp(
4522 effectiveLeftBrake =
RiseMath::Max(effectiveLeftBrake, shiftHoldBrake);
4523 effectiveRightBrake =
RiseMath::Max(effectiveRightBrake, shiftHoldBrake);
4529 effectiveLeftBrake = ClampFloat(effectiveLeftBrake, 0.0f, 1.0f);
4530 effectiveRightBrake = ClampFloat(effectiveRightBrake, 0.0f, 1.0f);
4548 dynamicMod = ClampFloat(dynamicMod, 0.0f, 1.0f);
4550#ifdef frictionLoggingC
4557 const float oldForwardVelZ = newlocvel.z;
4558 const float startRollingFadeSpeedKms =
4560 const float startRollingBlend =
4561 ClampFloat(1.0f - fabsf(newlocvel.z) / startRollingFadeSpeedKms, 0.0f, 1.0f);
4562 float appliedRollingDeltaV =
4563 RiseMath::Max(rollingDeltaV, startingRollingDeltaV * startRollingBlend);
4565 newlocvel.z = ApproachZero(newlocvel.z, appliedRollingDeltaV);
4567#ifdef frictionLoggingC
4568 if (oldForwardVelZ != newlocvel.z)
4570 const float appliedRollDeltaV = fabsf(oldForwardVelZ - newlocvel.z);
4571 frictionLog.
Printf(
"%8.3f rol VT%u CT%i WT%.0f WF%.2f GV%i GR%+i WH%i GE%.1f LB%.1f RB%.1f SH%.2f RFI%.6f RFS%.3f RFG%.3f SRB%.2f SRG%.3f V0%.3f V%.3f G%.1f R%.3f P%.3f LF%u/%u/%u TR%u/%u CrrBase%.4f CrrStart%.4f RghJitCoef%.4f RghJit%.4f CrrEff%.4f MuS%.3f MuK%.3f\n",
4582 effectiveRightBrake,
4585 appliedRollDeltaV / fElapsedTime,
4588 fElapsedTime > 0.0f ? startingRollingDeltaV * startRollingBlend / fElapsedTime *
oneOvergForceKmssC : 0.0f,
4599 rollingResistanceCrr,
4600 startingRollingResistanceCrr,
4601 terrainRoughnessJitterCoef,
4603 effectiveRollingResistanceCrr,
4605 effectiveMuKinetic);
4613 const float brakeInput =
RiseMath::Max(effectiveLeftBrake, effectiveRightBrake);
4614 const float tireSlipForwardVelZ = newlocvel.z;
4616 if (dynamicMod > 0.0f || brakeInput > 0.0f)
4618 float appliedLongitudinalDeltaV = 0.0f;
4619 const float oldForwardVelZ = newlocvel.z;
4621 if (dynamicMod > 0.0f)
4623 const float scrapeDeltaV = kineticDeltaV * dynamicMod;
4624 newlocvel.z = ApproachZero(newlocvel.z, scrapeDeltaV);
4625 appliedLongitudinalDeltaV += fabsf(oldForwardVelZ - newlocvel.z);
4628 if (brakeInput > 0.0f)
4630 const float beforeBrakeVelZ = newlocvel.z;
4631 const float requestedBrakeDeltaV = brakeInput * BRAKE_POWER_SCALE * staticDeltaV;
4633 if (requestedBrakeDeltaV <= staticDeltaV)
4635 newlocvel.z = ApproachZero(newlocvel.z, requestedBrakeDeltaV);
4640 newlocvel.z = ApproachZero(newlocvel.z, kineticDeltaV);
4643 appliedLongitudinalDeltaV += fabsf(beforeBrakeVelZ - newlocvel.z);
4646#ifdef frictionLoggingC
4647 if (appliedLongitudinalDeltaV != 0.0f)
4649 frictionLog.
Printf(
"%8.3f BRK VT%u CT%i WT%.0f WF%.2f GV%i GR%+i WH%i GE%.1f LB%.1f RB%.1f SH%.2f DVI%.6f DVS%.3f DVG%.3f V0%.3f V%.3f G%.1f R%.1f P%.1f LF%u/%u/%u TR%u/%u CrrBase%.4f RghJitCoef%.4f RghJit%.4f MuS%.3f MuK%.3f Skid%i Dyn%.2f\n",
4660 effectiveRightBrake,
4662 appliedLongitudinalDeltaV,
4663 appliedLongitudinalDeltaV / fElapsedTime,
4675 rollingResistanceCrr,
4676 terrainRoughnessJitterCoef,
4689 const float tireSlipSpeedKms = Length2D(oldLateralVelX, tireSlipForwardVelZ);
4691 const float availableLateralGripG = staticDeltaV / fElapsedTime *
oneOvergForceKmssC;
4697 const float minimumTireSkidNormalG = 0.25f;
4698 const float corneringTireSkidOnsetSeconds = 0.12f;
4699 const bool tireLoadedForSkidSound = normalG >= minimumTireSkidNormalG;
4700 const bool movingForTireSkid =
4701 fabsf(tireSlipForwardVelZ) > 0.003f &&
4702 tireSlipSpeedKms > 0.001f;
4703 const bool corneringSkidRequested =
4704 tireLoadedForSkidSound &&
4705 movingForTireSkid &&
4706 tireCorneringDemandG > availableLateralGripG &&
4708 const bool corneringSkidSustained =
4709 tireLoadedForSkidSound &&
4710 movingForTireSkid &&
4711 tireCorneringDemandG > availableLateralGripG * 0.80f &&
4713 const bool hardBrakeSkid =
4714 tireLoadedForSkidSound &&
4715 movingForTireSkid &&
4716 brakeInput * BRAKE_POWER_SCALE > 1.0f;
4717 const bool tireSkidSurface =
4720 tireSlipSpeedKms > 0.001f;
4722 if (!tireSkidSurface)
4733 else if (corneringSkidRequested)
4743 const bool tireSkidSoundActive =
4744 tireSkidSurface && tireLoadedForSkidSound &&
4747#ifdef frictionLoggingC
4751 "%8.3f SND tireSkid=%i brake=%i corner=%i demand=%.3fs speed=%.3f latG=%.3f gripG=%.3f normalG=%.3f\n",
4754 tireSlipSpeedKms, tireCorneringDemandG, availableLateralGripG, normalG);
4762 sprintf_s(
msg,
sizeof msg,
4763 "GROUND_TIRE type=%u road=%i support=%i speed=%.1fkph lateral=(%.3f->%.3f)mps "
4764 "normal=%.3fVg mu=(%.3f,%.3f) demand=%.3fEg grip=%.3fEg "
4765 "squeal=%i brake=%i corner=%i",
4767 groundTiresSupporting ? 1 : 0, tireSlipSpeedKms * 3600.0f,
4768 oldLateralVelX * 1000.0f, newlocvel.x * 1000.0f, normalG,
4769 effectiveMuStatic, effectiveMuKinetic, tireCorneringDemandG, availableLateralGripG,
4770 tireSkidSoundActive ? 1 : 0, (brakeSkid || hardBrakeSkid) ? 1 : 0,
4777 if (tireSkidSoundActive)
4779 const float skidVolume = ClampFloat(tireSlipSpeedKms / 0.020f * normalG, 0.0f, 1.0f);
4780 const float skidPitch = ClampFloat(0.75f + tireSlipSpeedKms / 0.040f, 0.75f, 1.50f);
4781 const float skidPan =
4782 fabsf(oldLateralVelX) > 0.001f ? (oldLateralVelX > 0.0f ? 1.0f : -1.0f) : 0.0f;
4800 if (fElapsedTime != 0.0f)
4811 static float oldScrapeVol = 0.0f;
4812 const float scrapevel = sqrtf(newlocvel.x * newlocvel.x + newlocvel.z * newlocvel.z);
4818 oldScrapeVol = scrapevol;
4820 else if (oldScrapeVol >
MIN_VOL)
4824 oldScrapeVol = 0.0f;
4842 sprintf_s(
msg,
sizeof(
msg),
"ET: %f", fElapsedTime);
4852 sprintf_s(
msg,
sizeof(
msg),
"cross I: %f", cross.x);
4854 sprintf_s(
msg,
sizeof(
msg),
"cross J: %f", cross.y);
4856 sprintf_s(
msg,
sizeof(
msg),
"cross K: %f", cross.z);
4858 sprintf_s(
msg,
sizeof(
msg),
"newlocvel I: %f", newlocvel.x);
4860 sprintf_s(
msg,
sizeof(
msg),
"newlocvel J: %f", newlocvel.y);
4862 sprintf_s(
msg,
sizeof(
msg),
"newlocvel K: %f", newlocvel.z);
4864 sprintf_s(
msg,
sizeof(
msg),
"staticDeltaV: %f", staticDeltaV);
4866 sprintf_s(
msg,
sizeof(
msg),
"kineticDeltaV: %f", kineticDeltaV);
4868 sprintf_s(
msg,
sizeof(
msg),
"rollingDeltaV: %f", rollingDeltaV);
4870 sprintf_s(
msg,
sizeof(
msg),
"rollingResistanceCrr: %f", rollingResistanceCrr);
4872 sprintf_s(
msg,
sizeof(
msg),
"terrainRoughnessJitterCoef: %f", terrainRoughnessJitterCoef);
4876 sprintf_s(
msg,
sizeof(
msg),
"muStatic: %f", muStatic);
4878 sprintf_s(
msg,
sizeof(
msg),
"muKinetic: %f", muKinetic);
4881 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation with ground friction...");
4896#pragma region Ground Lift Dump (GLD)
4919 if (fElapsedTime != 0.0f)
4935 sprintf_s(
msg,
sizeof(
msg),
"ET: %f", fElapsedTime);
4950 sprintf_s(
msg,
sizeof(
msg),
"Trapped a violation after gravityacc application...");
4973 orbitActuation.mainFuelKg+=fabsf(zThrustAcceleration4FF)*
ourcockpit.
ffmax*fuelTime;
4976 orbitActuation.rotationFuelKg+=rcsThrustYPR*
ourcockpit.
ffmax*fuelTime;
4991#pragma region RCS Thrust Sounds
5000 maxVolume += 0.002f;
5008 viewscreen->
gameclass->
sound->
PlayEx(
SOUND_THRUST,
true,
Clamp(volume / maxVolume * 3.0f, 0, 1), 1,
Clamp(pan / volume, -1, 1),
false,
true,
true);
5068 outpacket.
type = 11;
5071 outpacket.
array = 0;