PDA

View Full Version : rotation issues



Diago
10-15-2004, 02:59 AM
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 :)

Sean

Relic
10-15-2004, 03:47 AM
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: http://www.tc.cornell.edu/Services/Vis/dx/DXTIPS/pnichols/trackball.c

Diago
10-16-2004, 09:35 AM
Relic

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

Sean

MikeC
10-17-2004, 02:09 AM
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 http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=48

knackered
10-17-2004, 05:29 AM
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);
glRotatef(mat[0],mat[4],mat[8],pitchAngleDelta);
glRotatef(mat[1],mat[5],mat[9],yawAngleDelta);
glRotatef(mat[2],mat[6],mat[10],rollAngleDelta);I brace myself for abuse.