Expressions (or SGExpressions) are a feature of the SimGear library
and provide a nice way of implementing complex math formulas using XML
syntax. They are supported in many systems within the FlightGear code.
Caution: Expressions do not check if your math creates floating point
exceptions (like division by zero conditions, taking the square root
of a negative number, etc.). This can cause undefined behavior and may
result in NaNs or even Cascading NaNs. Usage
Expressions are supported in
* Autopilot configuration files
* Particle system configuration files
* Animations (translate, rotate, scale, range, blend)
* The shader technique
Sample Expressions
This is a sample expression for the euation c = sqrt(a*a + b^2).
Children/arguments are parsed in the order they appear in in the file
(or the order in which they are set via property methods).
/value/a
/value/a
/value/b
2
Supported elements
NOTE: #c in the table below is the number of child nodes required.
+-------------------+----+--------------------------------------------------+
| Function | #c | Notes |
+-------------------+----+--------------------------------------------------+
| | 1 | |
| | 1 | |
| | 1 | |
| | 2 | |
| | 1 | |
| | 1 | |
| | 3 | clipMin, clipMax, expression |
| | 1 | |
| | 1 | |
| | 1 | |
| | 1+ | |
| | 2 | |
|
| 1 | |
| | 1 | |
| | 1 | |
| | 1 | |
| | 1+ | |
| | 1+ | |
| | 2 | |
| | 2 | |
| | 1+ | |
| | 0 | Property name e.g.node/value|
| | 1 | |
| | 1 | |
| | 1 | |
| | 1 | |
| | 1 | |
| | 1+ | |
| | 2+ | 0.0 10 |
| | 1 | |
| | 1 | |
| | 0 | Constant Value e.g. 0 |
+-------------------+----+--------------------------------------------------+
Hints and tips
--------------
1. There is no function for rounding, hwoever "Round half up" can be
achieved as follows
your/property/here
0.5
2. Interpolation tables can be useful when a formula cannot be found,
In the example below is the indepdendant variable and
is the dependant variable. What this table does is as follows
- values below 0.2 will be 10
- values above 0.2 and between 1.0 will be interpolated between 10
and 0
- values above 1.0 will be 0