Thanks again! Is there a dQuaternion::GetEulerAngles version? I think you mentioned it in the previous post.
And yes - I don't have to tell you how many permutations and combinations of ordering I tried! Trial and error seems to consume most of my dev time. I'm slowly getting there.
As for the order issue - I found through my extensive testing that the ordering does NOT matter to flight simulator itself when I pass the (roll,pitch,yaw) values through to my simulator call - they are passed all together, in a struct of 3 doubles. Where the order does manifest is, when I manually rotate my object in flight simulator (I have keys set up that control values of roll, pitch and yaw). I get the proper attitude only when I first rotate in Heading (yaw), then in pitch, then in roll (which is the order specified in flight simulator's documentation). Any other order of rotation and the object's rotation gets out of whack. The (Heading,pitch,roll) sequence is the only one that correctly moves the principal axes along with rotations and rotates the object correctly, but again, that is an internal simulator operation over which I don't have any control whatsoever. All I need is to make sure I pass the correct RPY values into the simulator.
Which is where I am at now. Basically, to test the handedness and angle limits, I have set up my code to set RPY angles to a Newton body (and it's quaternion rotation), which then gets transferred back to euler angles and applied to my simulator object. This is what my code looks like:
- Code: Select all
// for testing purposes, PBH values are set through keyboard inputs
dQuaternion QX(dVector(1.0f, 0.0f, 0.0f), (float)Attitude->Pitch);
dQuaternion QY(dVector(0.0f, 1.0f, 0.0f), (float)Attitude->Bank);
dQuaternion QZ(dVector(0.0f, 0.0f, 1.0f), (float)Attitude->Heading);
// Zero out the quaternion
ent->m_curRotation = dQuaternion();
ent->m_curRotation = ent->m_curRotation*QX;
ent->m_curRotation = ent->m_curRotation*QY;
ent->m_curRotation = ent->m_curRotation*QZ;
and then, I convert back to Euler, in order to get values usable by my flight simulator client:
- Code: Select all
dVector dvEuler;
dvEuler = ent->m_curRotation.GetXYZ_EulerAngles(); // returns pitch, roll (bank), and yaw (heading)
// And set it to the return structure:
Attitude->Pitch = dvEuler.m_x;
Attitude->Bank = dvEuler.m_y;
Attitude->Heading = dvEuler.m_z;
The above code works well as far as getting back the same RPY values I entered, except for the problems of gimbal lock and angle ranges, which I'm hoping to solve through this discussion

. Important to note here is that the "old"
GetXYZ_EulerAngles() method expects the one and only one rotation sequence order, which I applied using QX,QY and QZ quaternion rotation sequence. If I use
quaternion2Euler() method from that link I sent you, I can apply QX,QY and QZ in any order, and then specify the reverse order "zyx" as the order parameter in
quaternion2Euler() call, and I would get the correct result. There are , as you mentioned, 6 ways of specifying the rotation order, and they all yield correct results if they are "unwrapped" in reverse of the order applied.
It is important to note that the first half of the code above is for testing purposes only. Newton body will be acted upon only by external forces (and not by directly applying the values of pitch, bank and heading), and the resulting attitude changes will be converted into Euler angles for input into the simulator display layer.
Yes, you are correct, I am the guy that is using spherical coordinate system

That part (position conversion between spherical and cartesian) was relatively easy to implement, and that's working without any problems. The part I was stuck on (back in April, I think) was the attitude conversion between Earth based and Celestial based reference frames. Since then, I've figured that part out and coded functions that convert attitude angles between the two reference frames (called ECEF and NED, but that's a whole another topic

). However, to properly test these, I need my attitude algorithms to be bulletproof and work absolutely correctly, and that's where I'm at now. Other things that complicate matters a bit (but not insurmountable) are that Newton is a Left-Handed coordinate system, and my flight simulator client is Right-Handed. Also, to answer your question, no, I have no way to hack into my graphics code, there is no source code to recompile the libs, and hex hacking would be way beyond my abilities, if possible at all. All I have is one lousy function

call to change object attitude, and all it takes are RPY values.
Sorry for this being so verbose, but I feel I'm getting ahead with this project and I sure do appreciate your attention and help on it!
Misho