View Full Version : combining successive glRotate calls

malancha

03-11-2004, 07:58 PM

Hi, I'd like to know if it's possible to combine a sequence of successive glRotate calls into one glRotate call.

Let's assume I've stored the parameters used for each call and the order in which the calls are to be made.

Is there an algorithm or formula that achieves this?

Thanks in advance.

mikael_aronsson

03-11-2004, 10:05 PM

Hi !

You will have to keep you own matrix and put the rotations in there, a matrix can contain any number of transformations (translate,rotate,scale) and you can then use glMultMatrix to get the combined transformation into OpenGL.

OpenGl itself does not have any suuport for this, but there are tons of tutorials and also lbraries available for this, try google.

Mikael

chemdog

03-11-2004, 10:41 PM

You want quaternions!

Usually only rotations on the same axis can combined together, and they needed to be successive, without other transformations between them.

Rotate x pi/2 Rotate x pi/6 Rotate y pi/12 Rotate x pi/2 Rotate z -pi/16 Rotate z pi/3 Rotate x pi/2

This can be combined into

Rotate x 2pi/3 Rotate y pi/12 Rotate x pi/2 Rotate z 13pi/48 Rotate x pi/2

If you would like to convert the rotations into quaternions, you can combine all the rotations into a single quaternion. Which the above can be reduced to

Quaternion (.65, .6, .7, 0.01)

then equivalently,

glRotate(167, .65, .6, .7)

The number above aren't perfect, but the procedure is sound.

malancha

03-11-2004, 11:24 PM

Perhaps I should make clear what exactly I'm trying to achieve. I have a plane which the user can rotate, translate, zoom, etc. Once the user is done, I need to be able to indicate the new orientation. This is important because the plane is such that it's easy to mix up the right and left sides, and I can't allow that. Also, I don't want to display the markers while the user plays around with the orientation.

Will it be enough to simply retrieve the Modelview matrix once the user is done, and then use glMultMatrix to determine where on the screen my markers need to be placed?

ZbuffeR

03-14-2004, 01:26 AM

Will it be enough to simply retrieve the Modelview matrix once the user is done, and then use glMultMatrix to determine where on the screen my markers need to be placed?

Yes, get the final matrix :

glGetDoublev(GL_MODELVIEW_MATRIX,double*);

And multmatrix it.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.