PDA

View Full Version : Rotation issue in OpenGL Window



tyyu
04-08-2001, 09:49 PM
Dear Advance OpenGL Users:

I post a question in the beginner section,
but can not get answers. Either the question
is too simple or too difficult (should not be).
I am hoping to get some feelback from any of you.

My question is regarding the rotation command
in OpenGL. Surely, the command is "glRotate".
Generally, in the plot routine, I have something
like the following:
:
:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRotated(m_xRotate, 1.0, 0.0, 0.0);
glRotated(m_yRotate, 0.0, 1.0, 0.0);
glRotated(m_zRotate, 0.0, 0.0, 1.0);

Draw_the_Objects;

My first question is: does the sequence (order) of using
glRotate makes different orientation of the Objects drawn
on the OpenGL window? (ie, if I put the
glRotated(m_xRotate,1.0,0.0,0.0) after glRoated(m_zRoate,0.0,0.0,1.0),
will it make the final objects (if they are just simple
3D axis X-Y-Z) display differently? It should not be
different, right? But, let say, if
m_xRoate = m_yRoate= m_zRoate = 80; and if ONLY m_xRoate
changes value by adding 1 when F1 key is press (the m_yRoate
and m_zRoate are still 80), and the plot routine called
when F1 is press, somehow the order of glRotate commands
make the different visual effect -- ie, if only m_xRotate
changes, the original sequence shows a rotational 3D axis,
but the X axis is moving too! (note, only the m_xRotate changing
the value, the m_yRotate and m_zRotate keep the constant values,
like 80), if I change the glRotate sequence, say put the
glRotated(m_xRoate,1.0,0.0,0.0) after glRotated(m_zRoate,0.0,0.0,1.0),
then, the axis is rotating, but the X axis stand still!
Will anyone explain this situation? (ie, does the sequence
of glRotate make different visual effect?)

My second question: if I want my objects be rotated with
particular direction (say, press F1, rotate only with X axis,
F2 for Y axis, and F3 for Z axis), how can I do it? I certainly
can make a variable to track which Function key (F1, F2 or F3)
is press, and according to this variable to put the glRotated
command (say, put the glRotated(m_xRoate,1.0,0.0,0.0) to the
last when F1 key is press), However, when I change the rotational
direction (say, press F2 after a sequence of F1 operations),
the orientation of the objects change dramatically when F2 is
just press. Why this happens and How to overcome?



Thanks.

zed
04-08-2001, 11:21 PM
prolly no answers cause it + its kin gets asked to often.
using eular angles like you are will cause "gimbal lock" type this in with google + u should find a heap of info + solutions

coredump
04-09-2001, 02:24 AM
you should note that when you call glRotate, the local coordinate system gets rotated, i.ie originally the x-axis points right, y-axis up and z-axis out of screen. if you call glRotate around the x-axis, the y and z axes are now pointing in different directions respectively. perhaps pushing and popping the matrix before your rotations will get you the desired results you seek. also, look into zed's solution.

b

tyyu
04-09-2001, 07:22 AM
Originally posted by zed:
prolly no answers cause it + its kin gets asked to often.
using eular angles like you are will cause "gimbal lock" type this in with google + u should find a heap of info + solutions


I hardly catch what you try to say. Can
you please write a little bit more with plain English? Thanks.

Coconut
04-09-2001, 07:42 AM
Answer to Question 1 is No.
What you did in your code is multiplying a rotation matrix at each glRotated call.
Since A*B != B*A, you result will be different if the order is different.