In my project, I have to perform two rotations on x axis and y axis by mouse movement. Using a simple way I wrote the code like this


With this method, the rotations perform well if I first rotate the draw in y axis and then in x axis. However opposite is not true since I want to rotate the draw both in x and y axis independent of written order.
Is there a simple way to make this or do I have to use quaternions?
My second question is “what is gimbal lock?” “The problem I described is a gimbal lock or not?”
can someone help me …

I think it is a Gimbal Lock problem. Take a look:

You can also google for it.

And BTW, thanks for your question, it made me learn the name of that problem, which I’m facing too. I guess we’re alone. I’ll take a look at quaternions and see if they can help me without decreasing my FPS.

I have been saying this over and over again on this
forum: use quaternions. It will take just a bit of
time to search, read about and understand, but I can
assure you that it is well worth the effort.

With quaternions you never of think of rotations about
a fix axis, you just think of an initial orientation
and three types of rotation about the body-fitted
axes: pitch, yaw and roll. Very natural for doing
airplane motions, etc. Think of yourself as being in
the aircraft and ordering amount to roll, pitch, yaw
and get your new orientation as output. Quaternions
can be integrated and the beauty of this is that you
can specify rates of roll, yaw, pitch and just get
the result out. Then, once you have the direction
cosines in a matrixs as obtained by the quaternion
operations, you simply 'dump" it to the ogl. It cannot
get any easier, and I can assure you that the frame
rate has nothing to do with this, there are very few
operations involved.

iznogoud, I took a look on quaternions and it really does not seem hard to implement. Yes, it could save us a lot of trouble on rotation, but the fact is I’m afraid of using it for it seems very CPU-intensive.

I’m initially using OpenGL for 2D graphics, and if I have to use the CPU so much like quaternions do, I’d rather use sine and co-sine myself. That’s why I’m always looking for what can OpenGL do for me, since it does computations inside the GPU which is a lot faster than my CPU :slight_smile:

You only need to do with a_quaternion whatever it
takes to get the modelview matrix setup. If you think
that performing 16 multiplications and 12+4 additions
is “computationally intensive” for the CPU, then we
disagree in matters of perspective! If you do not
want to take my word for it, code it up yourself and
let us all know about the decrease in performance,
if any…

If you search the forum for quaternions, Gimbal Lock,
rotations, etc, you will find many people advocating
the use of quaternion with the exception of very
special cases. It is always your call.

Ok, I’m going to give it a try.
Thanks for the suggestion. I hope I did not make you angry. :slight_smile:

Originally posted by <normalguy>:
Ok, I’m going to give it a try.
Thanks for the suggestion. I hope I did not make you angry. :slight_smile:

Ha ha! Not at all! I just feel strongly about the use
of quaternions and hope to help people by what my
experience has taught me. If you want to followup
with the performance tests, that’s still good.

I use quaternions in my application as well. Even on an ancient P3 500 w several quaternion operations, per draw cycle, I notice less than 0.1 %, a tenth of a percent drop in speed. It is not noticeble.