Difference between revisions of "API:FlightGlobals"

From Kerbal Space Program Wiki
Jump to: navigation, search
m (N3X15 moved page FlightGlobals to API:FlightGlobals)
(*update to templates;)
Line 3: Line 3:
 
== Useful members ==
 
== 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!
+
{{Box|Warning.svg|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!|#FFDF80|Note}}
  
 
A number of FlightGlobals functions have two versions: one that takes a CelestialBody as an argument and one that doesn't. Presumably the second version uses the mainBody of the active vessel. Below are listed only the versions that take an explicit CelestialBody argument.
 
A number of FlightGlobals functions have two versions: one that takes a CelestialBody as an argument and one that doesn't. Presumably the second version uses the mainBody of the active vessel. Below are listed only the versions that take an explicit CelestialBody argument.
  
<table border="1">
+
{| class="wikitable"
<tr>
+
! Signature
<td><code>static float GetAltitudeAtPos(Vector3 position, CelestialBody body)</code></td>
+
! Description
<td>Gives the altitude of a given world position above body's sea level.</td>
+
|-
</tr>
+
{{Method|returntype=float|name=GetAltitudeAtPos|args={{type|Vector3}} position, {{type|CelestialBody}} body|desc=Gives the altitude of a given world position above body's sea level.}}
<tr>
+
{{Method|returntype=double|name=getAtmDensity|args={{type|double}} pressure|desc=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 game's drag formula:
<td><code>static double getAtmDensity(double pressure)</code></td>
 
<td>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 game's drag formula:
 
  
 
<code>double rho = FlightGlobals.DragMultiplier * FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(position, body));
 
<code>double rho = FlightGlobals.DragMultiplier * FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(position, body));
Line 21: Line 19:
  
 
Vector3d dragForce = -0.5 * rho * part.mass * part.maximum_drag * airVel.magnitude * airVel;</code>
 
Vector3d dragForce = -0.5 * rho * part.mass * part.maximum_drag * airVel.magnitude * airVel;</code>
</td>
+
}}
</tr>
+
{{Method|returntype=Vector3d|name=getGeeForceAtPosition|args={{type|Vector3d}} pos|desc=The gravitational acceleration (not force) at the position pos. Does this compute which SOI pos is in or does it assume that pos is in the SOI of the active vessel's mainBody?}}
<tr>
+
{{Method|returntype=double|name=getStaticPressure|args={{type|Vector3d}} position, {{type|CelestialBody}} body|desc=The air pressure of body's atmosphere at position, in some arbitrary units.}}
<td><code>static Vector3d getGeeForceAtPosition(Vector3d pos)</code></td>
+
{{Property|type=Vessel|name=ActiveVessel|hasget=1|desc=The vessel currently being controlled by the player.}}
<td>The gravitational acceleration (not force) at the position pos. Does this compute which SOI pos is in or does it assume that pos is in the SOI of the active vessel's mainBody?</td>
+
{{Property|type=CelestialBody|array=[]|name=Bodies|hasget=1|desc=An array containing all the celestial bodies in the universe.}}
</tr>
+
{{Property|type=float|name=DragMultiplier|hasget=1|desc=A proportionality constant that scales the strength of aerodynamic drag forces.}}
<tr>
+
{{Property|type=List|array=&lt;{{type|Vessel}}&gt;|name=Vessels|hasget=1|desc=A list of all the Vessels in the universe.}}
<td><code>static double getStaticPressure(Vector3d position, CelestialBody body)</code></td>
+
|}
<td>The air pressure of body's atmosphere at position, in some arbitrary units.</td>
 
</tr>
 
<tr>
 
<td><code>static Vessel ActiveVessel { get; }</code></td>
 
<td>The vessel currently being controlled by the player.</td>
 
</tr>
 
<tr>
 
<td><code>CelestialBody[] Bodies { get; }</code></td>
 
<td>An array containing all the celestial bodies in the universe.</td>
 
</tr>
 
<tr>
 
<td><code>static float DragMultiplier { get; }</code></td>
 
<td>A proportionality constant that scales the strength of aerodynamic drag forces.</td>
 
</tr>
 
<tr>
 
<td><code>List<Vessel> Vessels { get; }</code></td>
 
<td>A list of all the Vessels in the universe.</td>
 
</tr>
 
</table>
 
  
 
[[Category:Community API Documentation]]
 
[[Category:Community API Documentation]]

Revision as of 13:28, 21 April 2013

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

Useful members

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!

A number of FlightGlobals functions have two versions: one that takes a CelestialBody as an argument and one that doesn't. Presumably the second version uses the mainBody of the active vessel. Below are listed only the versions that take an explicit CelestialBody argument.

Signature Description
float GetAltitudeAtPos(Vector3 position, CelestialBody body) Gives the altitude of a given world position above body's sea level.
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 game's drag formula:

double rho = FlightGlobals.DragMultiplier * FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(position, body));

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;

Vector3d getGeeForceAtPosition(Vector3d pos) The gravitational acceleration (not force) at the position pos. Does this compute which SOI pos is in or does it assume that pos is in the SOI of the active vessel's mainBody?
double getStaticPressure(Vector3d position, CelestialBody body) The air pressure of body's atmosphere at position, in some arbitrary units.
Vessel ActiveVessel { get; } The vessel currently being controlled by the player.
CelestialBody Bodies { get; } An array containing all the celestial bodies in the universe.
float DragMultiplier { get; } A proportionality constant that scales the strength of aerodynamic drag forces.
List Vessels { get; } A list of all the Vessels in the universe.