aeronautic

Writing it

Set the flight from a flight model, a control, or a slider.

A flight is written with set, which changes the fields given and keeps the rest. Get it with useFlightStore inside a provider:

const flight = useFlightStore();

useFrame(() => {
  flight?.set({
    airspeedMPerS: model.speed,
    angleOfAttackRad: model.alpha,
    loadFactor: model.g,
    altitudeM: model.height,
  });
});

What can be written

fieldunitmeaning
airspeedMPerSm/strue airspeed
angleOfAttackRadradpositive with the nose above the flight path
sideslipRadradpositive when the air blows from the right
loadFactorglift over weight: 1 in level flight
rollRateRadPerSrad/sright wing down positive
pitchRateRadPerSrad/snose up positive
yawRateRadPerSrad/snose right positive
throttle0 to 1.10 idle, 1 military power, 1.1 full reheat
roll−1 to 1the stick, right positive
pitch−1 to 1the stick, aft (nose up) positive
yaw−1 to 1the pedals, right positive
flaps0 to 11 fully down
airbrake0 to 11 fully out
gear0 to 11 down
altitudeMmabove sea level
temperatureOffsetKKhow much warmer the day is than the standard one
relativeHumidity0 to 1as a weather report gives it

A new flight starts as default_flight_input(): at rest at sea level, at military power, gear up, on a standard day at 60 % humidity. Give <FlightProvider initial={…}> or new Flight({…}) what differs.

Cheap enough for every frame

set compares each field with what it holds. When nothing changed, it does nothing: no work, no listener called, and the version stays put, so every effect skips its own work too. Write the whole flight every frame, and only what moved costs anything.

When something did change, the speeds that follow (Mach, dynamic pressure, the ram pressure) are worked out again. The air is worked out only when the altitude, the day's offset or the humidity changed.

From the UI

A slider writes to the same flight. Outside the Canvas, hold the flight yourself and hand it to the providers, as in Round the HUD too:

<input
  type="range"
  min={0}
  max={1.1}
  step={0.01}
  defaultValue={1}
  onChange={(event) => flight.set({ throttle: event.target.valueAsNumber })}
/>

Nothing re-renders: the effects pick it up in their next frame.

Writes and tracking together

A tracked flight is written by the tracker each frame, before anything reads it. It only writes what it can see, so set the throttle, the controls and the day as usual. See Tracking.

Next, let it watch an object.

On this page