Aircraft

From X-Plane SDK
Jump to: navigation, search

About Aircraft Control

The X-Plane plugin system allows control of other aircraft within X-Plane. We provide location information and X-Plane takes care of the graphics.

X-Plane's Aircraft

X-Plane loads a finite number of aircraft that it loads and manages. Each has a model (loaded from an aircraft file) with one texture and one set of flight model data. There are basically two ways to work with X-Plane's aircraft:

  • Specify the position and configuration (flaps, etc.) information of each aircraft to move them. X-Plane's "AI" aircraft code is disabled. We can update the positions of the planes as often as we want (or do not want), but for smooth motion we should update the planes' positions every frame.
  • We draw the aircraft, using X-Plane's aircraft drawing routine. This provides lower level drawing control over aircraft, but is more complicated. We must draw the aircraft every frame.

Directly controlling the position of X-Plane's aircraft is the easiest way to control them and probably the best choice for simple applications. However, directly controlling the aircraft has two limitations: we can only have a fixed number of planes (seven besides the users plane in X-Plane 660) and we must load a new ACF file to change what one of the aircraft looks like (even if the same model is being used for another aircraft number).

We can get around some of these limitations by drawing aircraft ourself. When we draw aircraft ourself, we control whether aircraft are drawn as full aircraft or just landing lights and we must cull aircraft that are not on screen. We can draw any plane at any time, allowing the immediate placing of any of the loaded aircraft models at any location. However, the planes we draw are only painted; they do not interact with the sim (for example, we will not see them on the TCAS display).

In all cases, X-Plane's control of the aircraft is fully disabled. We are responsible for interpolating landing gear position, checking for collisions with the ground, and computing flight characteristics.

Controlling Aircraft Exclusively

In order to control aircraft we must gain exclusive access to them. Only one plugin can control aircraft at a time. If another plugin is accessing aircraft, we can provide a callback function that will be called when that other plugin releases the aircraft or is disabled. (Disabling a plugin forces aircraft to be released.) Exclusive access is taken for all aircraft at once; individual aircraft cannot be split between multiple plugins.

Once we control aircraft, we can set their locations. We do this by setting datarefs; see the data ref master list for the datarefs that control the multiplayer aircraft.

Loading Aircraft Sets

When we take exclusive access of the aircraft we specify a set of aircraft we would like loaded. (This set can be empty if we do not want to load aircraft when taking control.) However, providing an aircraft set is a good way to load our aircraft because only aircraft that are not already loaded are reloaded and if our plugin takes control of aircraft at startup then X-Plane will load our aircraft initially. (This saves the time of loading 7 aircraft, then reloading them with different models). Aircraft are specified by path.

Drawing Aircraft

We can draw an individual aircraft. When we draw the aircraft, we specify all of its parameters (position, orientation, and other aircraft attributes). We control which aircraft model is drawn by choosing an aircraft number. We can only draw aircraft during an external drawing callback; typically plugins that want to draw their own aircraft register a callback for after objects are drawn.

Limiting the Number of Active Aircraft

We can control the number of active aircraft and enable or disable whether X-Plane's "AI" is working on them. This allows reduction of the number of AI planes present or control the number of planes we are working with.

Using Aircraft Control

Controlling the User's Plane

Getting Information About Planes

Exclusive Access to the Aircraft

Getting Access to Aircraft

Loading Aircraft Sets

Controlling Aircraft

Limiting Aircraft Number

Drawing Our Own Aircraft

Controlling Aircraft Ourselves

Aircraft Reference