API:FlightGlobals

From Kerbal Space Program Wiki
Revision as of 22:30, 11 May 2012 by The Duck (talk | contribs) (Created page with "The FlightGlobals class contains a number of useful static functions and fields. == Useful members == Note: this is not a complete listing of the class's members. It include...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The FlightGlobals class contains a number of useful static functions and fields.

Useful members

Note: this is not a complete listing of the class's members. It includes only the members that someone has figured out how to use and written an explanation for. If you figure out what the other members that aren't listed here do, you should add them to the list!

static float GetAltitudeAtPos(Vector3 position) Gives the altitude above sea level of a given world position. Probably the celestial body used in this calculation is the active vessel's mainBody.
static double getAtmDensity(double pressure) Calculates an atmospheric density in some arbitrary units. Presumably it's meant to take as input the output of FlightGlobals.getStaticPressure. The following code seems to work quite well to compute the drag force on a part and may in fact be the same as what the game code does:

double rho = FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(position, body)) / 125.0;

Vector3d airVel = vessel.orbit.GetVel() - body.getRFrmVel(position); //the velocity of the vessel relative to the air

Vector3d dragForce = -0.5 * rho * part.mass * part.maximum_drag * airVel.magnitude * airVel;