Jump to content
  • Advertisement
Sign in to follow this  
w166um

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!