Hi!
I'm sorry if this has been asked before. I've been searching for an answer for awhile, so if there is an answer (to my rather stupid question) please point me to it.
Now. I've been hacking some quaternions together, and after a bit of trying I am now able to fly through space, using my joystick. It works like a charm, but since I don't quite understand quaternions (yet) I thought it might be a good idea to ask if I do it right.
The way I do it now is, I have my pitch, yaw and roll increments stored every frame in
delta_pitch,
delta_yaw, and
delta_roll. Rotation velocity per axis is at most 90deg/s so with around 430 fps the deltas are very small. I build my three quaternions
q_delta_pitch,
q_delta_yaw, and
q_delta_roll like this:
q_delta_pitch.fromAxisAngle( delta_pitch, 1.0, 0.0, 0.0 );
q_delta_roll.fromAxisAngle( delta_roll, 0.0, 1.0, 0.0 );
q_delta_yaw.fromAxisAngle( delta_yaw, 0.0, 0.0, 1.0 );
Note that I'm using OpenGL with the positive z-axis as up-vector.
I then apply these deltas to my rotation:
q_rotation = q_rotation * q_delta_pitch * q_delta_roll * q_delta_yaw;
This rotation is then applied to my camera.
This works perfectly. I pitch when I want to pitch, I roll when I want to roll, and I yaw when I want to yaw. However, as I said earlier, my deltas are really small, so I can't really tell whether this is the right way to do it, but I believe it is not.
Another way to do it would be to store the angles, and increment (or decrement) them every frame, and then build the rotation by first rotating the (identity) quaternion around the x-axis, then around the (local) y-axis, and then around the (local) z-axis.
What is the best way to do it? I know I shouldn't rely on my high frame rate. But even after hours and hours of trying different combinations, I still need enlightment. ;-)
Hope you understand my problem! Thanks in advance...
Cheers,
Drag0n
-----------------------------"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning..." -- Rich Cook"...nobody ever accused English pronounciation and spelling of being logical." -- Bjarne Stroustrup"...the war on terror is going badly because, if you where to compare it to WWII, it's like America being attacked by Japan, and responding by invading Brazil." -- Michalson