Premultiplying and Fixed Rotation
I'm currently learning OpenGL and i'm trying to rotate an object in a fixed coordinate system.
I have been reading that I have to pre-multiply and that OpenGL post-multiplies. But I'm just having a little difficulty visualizing the concept.
My code looks something like...
glTranslatef( 0, 0, -6 );
glRotatef( rotateX, 1, 0, 0 );
glRotatef( rotateY, 0, 1, 0 );
DrawObject();
Basically I don't want the Y rotation to rotate on the new axis created by the X rotation(and vice versa). Can anyone help me out? Some psuedo-code would be appreciated. Thanks in advance. :)
Rotation axis are not independant in 3d space, one will always affect the other, and the order they're applied matters.
Not sure what you're asking for...
*might* be that he's asking how to have a freely rotating object, who's rotation can be influenced from worldspace x and y torque forces...
In order to do That
You need to track the object's orientation yourself (usually via a matrix).
and for each succesive rotation you wish to apply, you need to 'hit' it's orientation matrix with a rotation transform then save the result...
Math will be required, opengl is for rendering the object afterwards, but it cannot make Actual cumulative changes to it's rotation in space...
Not sure what you're asking for...
*might* be that he's asking how to have a freely rotating object, who's rotation can be influenced from worldspace x and y torque forces...
In order to do That
You need to track the object's orientation yourself (usually via a matrix).
and for each succesive rotation you wish to apply, you need to 'hit' it's orientation matrix with a rotation transform then save the result...
Math will be required, opengl is for rendering the object afterwards, but it cannot make Actual cumulative changes to it's rotation in space...
Here is some sample code from my project.
void OnDisplay(){ glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); CheckInput(); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glTranslatef (0, 0, -6); glRotatef (0, 0, 0, 1); glRotatef ( g_rotateX, 1, 0, 0 ); glRotatef ( g_rotateY, 0, 1, 0 ); DrawObjects(); glutSwapBuffers(); glutPostRedisplay();}void CheckInput(){ if( g_keyboard['w'] ) // up g_rotateX += 0.1; if( g_keyboard['a'] ) // left g_rotateY -= 0.1; if( g_keyboard['s'] ) // down g_rotateX -= 0.1; if( g_keyboard['d'] ) // right g_rotateY += 0.1; if( g_keyboard['r'] ) { g_rotateX = 0.0f; g_rotateY = 0.0f; } if( g_keyboard[KEY_ESC] ) // Esc Key { if( g_FullScreen ) glutLeaveGameMode(); exit(0); } if( g_rightMouse ) { g_rotateY += g_mousePos.x - g_mouseStartPos.x ; g_rotateX += g_mousePos.y - g_mouseStartPos.y; g_mouseStartPos.x = g_mousePos.x; g_mouseStartPos.y = g_mousePos.y; } if( abs(g_rotateY) >= 360.0f ) g_rotateY = 0.0f; if( abs(g_rotateX) >= 360.0f ) g_rotateX = 0.0f;}
Quote:Original post by w166um
Here is some sample code from my project.
*** Source Snippet Removed ***
....yeah? so?....
your original question is still unclear
and my previous advice still stands
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement