View Full Version : Rotation around two fixed rotation axis

Roland

02-26-2002, 07:14 AM

Hi,

I'm new to OpenGL and I try to rotate e.g. a cube around two

fixed world axis. I only managed to get one fixed axis and the

other coordinate or rotation axis move.

If I try

glLoadIdentity();

..

glRotatef(m_fAngleX, 1.0f, 0.0f, 0.0f);

glRotatef(m_fAngleY, 0.0f, 1.0f, 0.0f);

glCallList(Cube);

...

the x axis is the fixed rotation axis and the y axis moves

If I try it the other way round

...

glRotatef(m_fAngleY, 0.0f, 1.0f, 0.0f);

glRotatef(m_fAngleX, 1.0f, 0.0f, 0.0f);

the y axis is the fixed rotation axis and the x axis moves.

(the first used axis seems to be the fixed rotation axis).

Is there any possibility to use two fixed rotation axis

and how can I do it?

Thank you for any advice.

Roland

DFrey

02-26-2002, 07:34 AM

Easily. Change the second rotate axis so that it rotates about the correct axis. For example, lets say you first rotate about X. What you are really doing is rotating the coordinate system about X, so Y gets rotated into Y'. If you want to do a second rotation about Y instead of Y', you must take Y and rotate it about X in opposite direction to get Y''. Use Y'' as the axis of the second rotation.

Or more clearly, to do a rotation about X and then Y, both fixed you need to do this:

r'=r * Mx (Mx is the rotation about X)

Y'' = Y * Mx' (Mx' is the rotation about X in the opposite direction, i.e. inverse)

r'' = r' * My'' (My'' is the rotation about Y'')

(r is the radius vector of any given point, r' is an intermediate result, and r'' is the final result)

[This message has been edited by DFrey (edited 02-26-2002).]

Roland

02-26-2002, 01:06 PM

Thank you for your answer,

it seems to me that there might be a hint for

the solution of my problem also I'm aktually not sure

how to do it in OpenGL. Perhaps it's too late today

or maybe I'm to stupid.

Ok I try to follow your explanation:

r' is the rotated vector r with the rotation angle Mx?

=>

glRotatef(Mx, 1.0, 0.0, 0.0);

Now our Y has rotatet to Y'?

To get Y'' we need to rotate with Mx' again?

Mx' = - Mx ?

=>

glRotatef(-Mx, 1.0, 0.0, 0.0);

Is that right?

(Hmm, now the first two glRotatef have undo each other?)

Even if I put glCallList(Cube) in between this two

glRotatef I'm not able to rotate around two fixed axis.

I think I misunderstand you here...

Now to get the r'' I simply use

glRotatef(My'',0.0,1.0,0.0); ??

and because the rotation angle My'' is now the same as My I

could use

glRotatef(My,0.0,1.0,0.0); ??

I think I'm completely wrong. Can you help me again and write

a short example with the OpenGl functions or in which aspects

I've understand you wrong. That would be very great.

Roland

Originally posted by DFrey:

Easily. Change the second rotate axis so that it rotates about the correct axis. For example, lets say you first rotate about X. What you are really doing is rotating the coordinate system about X, so Y gets rotated into Y'. If you want to do a second rotation about Y instead of Y', you must take Y and rotate it about X in opposite direction to get Y''. Use Y'' as the axis of the second rotation.

Or more clearly, to do a rotation about X and then Y, both fixed you need to do this:

r'=r * Mx (Mx is the rotation about X)

Y'' = Y * Mx' (Mx' is the rotation about X in the opposite direction, i.e. inverse)

r'' = r' * My'' (My'' is the rotation about Y'')

(r is the radius vector of any given point, r' is an intermediate result, and r'' is the final result)

[This message has been edited by DFrey (edited 02-26-2002).]

DFrey

02-26-2002, 01:28 PM

In my example, Mx, Mx', and My'' are rotation matrices. Of those, you only need to calculate Mx'. And Mx' != -Mx, rather Mx' = transpose of Mx. (transpose since for rotation matrices it is equal to the inverse). And then at that, since you are only multiplying the Y unit vector by that inverse matrix, you really only need to calculate one column of the matrix.

in pseudoish code:

y_axis_turned=Vector(0,1,0).Rotate(-angle_x, Vector(1,0,0))

glrotate(angle_x, Vector(1,0,0))

glrotate(angle_y, y_axis_turned)

[This message has been edited by DFrey (edited 02-26-2002).]

Roland

02-27-2002, 03:35 PM

i,

thank you for your help. The last message made it more clear

to me.

y'' = Mx'* y

=> | 1 0 0 | | 1 0 0 |

Mx = | 0 cos(a) -sin(a)| => Mx'(inverse...) = | 1 cos(a) sin(a) |

| 0 sin(a) cos(a)| | 1 -sin(a) cos(a) |

| 1 0 0 | |0| | 0 |

y'' = | 1 cos(a) sin(a) | * |1| = | cos(a)|

| 1 -sin(a) cos(a) | |0| |-sin(a)|

Now we have the y_axis_turned (=y'')

=>

glRotatef(angle_x, 1.0,0.0,0.0);

glRotatef(angl_y, 0, cos(M_PI*angle_x/180), -sin(M_PI*angle_x/180);

glCallList....

The interesting thing is that now I've calculated the rotated y axis

but then my x-axis rotates

=>

same result as

glRotatef(angl_y, 0.0, 1.0, 0.0);

glRotatef(angle_x, 1.0,0.0,0.0))

Ok now perhaps I've to calcluate the vector for my new x axis.

| cos(a) 0 -sin(a) |

My = | 0 1 0 | => My'(invers, transpon

| sin(a) 0 cos(a) |

| cos(a) 0 sin(a) |

My' = | 0 1 0 |

|-sin(a) 0 cos(a) |

| cos(a) 0 sin(a) | |1| |cos(a) |

x'' = | 0 1 0 |*|0|=| 0 |

|-sin(a) 0 cos(a) | |0| |-sin(a)|

But the next things doesn't work

glRotatef(angle_y, 0.0, 1.0, 0.0);

glRotatef(angle_x, cos(M_PI*angle_y/180),0.0,-sin(M_PI*angle_y/180))

or

glRotatef(angl_y, 0, cos(M_PI*angle_x/180), -sin(M_PI*angle_x/180);

glRotatef(angle_x, cos(M_PI*angle_y/180),0.0,-sin(M_PI*angle_y/180));

doesn't work.

What's the problem?

Could you please help me with a code example. I've send you

some testprogramm files.

Bye

Roland

Originally posted by DFrey:

In my example, Mx, Mx', and My'' are rotation matrices. Of those, you only need to calculate Mx'. And Mx' != -Mx, rather Mx' = transpose of Mx. (transpose since for rotation matrices it is equal to the inverse). And then at that, since you are only multiplying the Y unit vector by that inverse matrix, you really only need to calculate one column of the matrix.

in pseudoish code:

y_axis_turned=Vector(0,1,0).Rotate(-angle_x, Vector(1,0,0))

glrotate(angle_x, Vector(1,0,0))

glrotate(angle_y, y_axis_turned)

[This message has been edited by DFrey (edited 02-26-2002).]

Roland

03-06-2002, 03:29 AM

Your last message made it a bit more clear

but it doesn't work. Although I've tried

it with my rotations matrices it seems not to work properly.

I can send a sample code that shows my problem to anyone who likes to see it.

DFrey, did you get my sample code and my

questions?

Roland

DFrey

03-06-2002, 05:31 AM

Yes, the second rotation appears to turn the X axis, since it is a rotation about Y. But the thing is both rotations about X and Y are done when they are fixed. If you want the X axis to appear unturned after the rotation about the Y, then you must calculate the new X axis (and henceforth the new Y axis and so on and so on).

Roland

03-06-2002, 11:07 AM

I thought I've already done it. I had a problem with calculating the new x axis but I'll have a closer look in my source and write a more detailed question again (I'll send you another code example then, too). Did you get my source code and have you tried it?

Roland

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.