# OpenGL Premultiplying and Fixed Rotation

This topic is 4270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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. :)

##### Share on other sites
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...

##### Share on other sites
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;}

##### Share on other sites
Quote:
 Original post by w166umHere is some sample code from my project.*** Source Snippet Removed ***

....yeah? so?....

your original question is still unclear
and my previous advice still stands

1. 1
Rutin
26
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631756
• Total Posts
3002125
×