Well, yes, that part is pretty clear to me
And also, I wish to emphazise that this is not enterily an scripting problem but a mathematical one (that when it's solved it needs to be ported to a informatic structure... but that's an other problem
)
So I think we should basically start be understanding what those variables mean.
Well, so far we know this: m.ship:position is the coordinates of where the ship is in space, related to an arbitrary point of origin in the center of the map and m.ship:orientation vector of some sort, where the values are not numbers but degrees, where the first one is the "heading", the 2° one the "pitch", and the 3° the "bank" of the ship.
In my experimentation, I gathered that the 1° value (heading) is the value of the angle that the ship's nose makes with an arbitrary line defined as the 0° in a circunference in the plane z=0, ranging from -180<0<180, which is, effectibly, a circunference
the 2°, the pitch, is a value that works in a similar way, an angle between the ship's nose and an arbitrary 0 in the plane x=0, but the values go from -90<0<90 but in this way:
(well... asumming that's an actual circle, that is....)
The 3° I'm yet to figure it out, but it must be the angles of a circunference in the y=0 plane