if there only was a standalone C++/C source for quaternion calucations, I don't really want to extract it from an whole engine as I'm just a hobby programmer.

Ogre's quaternion code is all in ogrequaternion.h and ogrequaternion.cpp. It's fairly stand alone.

For your problem, quaternions alone are hard to test for things like upside down objects. But luckily we can convert any local axis vector to a world axis vector using a quaternion.

The operation is world = orientation * local;

This rotates the local vector by the orientation.

How you could use this is as follows. I'm not sure what the coordinate system in GTA:SA is, but we'll assume it's the same as ogre ( [0,0,-1] faces forwards, [0,1,0] is the up vector).

Now if you do: world = orientation * Vector3(0,1,0);

it will rotate the local up vector of the air plane by it's orientation to get the current world vector. If world.y is greater than 0, the plane is upright. If world.y is less than zero, the plane is upside down (the closer to -1 world.y is, the closer to completely upside down it is). If you do acos(world.y), it will tell you the angle away from perfectly upright and level.

You can also do forward = orientation * Vector3(0,0,-1) to get the current heading of the plane as a vector.

Of course GTA:SA probably uses something else like [0,0,1] as the up vector and [0,1,0] as forwards, but this is an ogre forum so my examples above are for ogre's style.