rotation issues

I’m developing a cad program that uses opengl. I use the mouse to rotate the model and individual parts thereof.

I want to make rotation work in only 2 planes so that dragging the mouse up or down will ALWAYS rotate the model up or down reletive to the USER. Same for left and right.

glRotate messes up at least one axis, which means that if I rotate the model 45 degrees around the y axis, the x and z axis rotate 45 deg also. Rotating up and down will now be messed up from the user’s perspective.

How do I make the rotation work so that it will look to the user as if all axis remain static and thus any mouse movement will always do the expected rotation?

Thanx for reading this whole thing :slight_smile:


Rotation manipulators normally use quaternions.
They can be concatenated, interpolated, and converted into a 4x4 matrix, you just load into your modelview matrix.
Search the forum and the internet, it’s not too difficult. One of the first articles about it called it “hypersphere”.
Search the GLUT examples for the trackball.c file, there is a quaternion rotation inside, eh,
here it is:


Mega thanx for your help. I’m gonna try it asap!


The more common name for this sort of control is “arcball”. Google returns lots of relevant hits (the advantage of an unusual name), including a NeHe tutorial at

Using straight glRotate, which takes an axis angle, to do what you want is very easy. No need to mess about with quaternions, beautiful though they are.
This is off the top of my head, as I don’t use gl matrix manipulation functions directly myself…

GLfloat mat[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mat);

I brace myself for abuse.