views:

56

answers:

1

Hi,

I'm having real trouble finding out how to rotate an object arround two axes without changing axes orientation. I need only local rotation, first arround X axis and then arround Y axis(only example, it doesn't matter how many transformations arround which axes) without transforming the whole coordinate system, only the object. The problem is that if I'm using glRotatef arround X axis, the axes are rotated also and that's what I don't want. I've red bunch of articles about it but it seems I'm still missing something. Thanks for every help.

To have some sample code here, it's something like this

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(rotX, 1.0f, 0.0f, 0.0f);
glRotatef(rotY, 0.0f, 1.0f, 0.0f);
drawObject();

but this transforms the coordinate system also.

A: 

You probably need to restore your modelview matrix after drawing the object. You can do this using the built-in matrix stack of OpenGL. The common pattern looks like this:

// Set up global coordinate system:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// ... add world and view transformations here ...

// Draw your object:
glPushMatrix(); // save the current matrix on the stack
glRotatef(rotX, 1.0f, 0.0f, 0.0f);
glRotatef(rotY, 0.0f, 1.0f, 0.0f);
drawObject();
glPopMatrix(); // restore the previously saved matrix

// Repeat the above for other objects
Thomas
thanks for advice, I've tried this, but it didn't work, i think the problem is that in one step I'm rotating arround X axis which rotates the coordinate system and then in the same step arround Y axis and this rotation is performed using the coordinate system already rotated arround X axis, so it's not what I need. Maybe I've explained it bad or unclearly before.Or do you think that the problem is somewhere else?
Jenicek
Ah, I see, so you want to rotate around the global Y axis, not the local one. That is not a common way to express rotations, and off the top of my head I'm not sure how to do that. You could try reversing the order of the X and Y rotations and see if that makes more sense for your application.
Thomas
Yes you're right. I know it's not common I'm just trying something and I've got stuck at this point :) maybe I'll figure it out, I'll try to play with it again :) thanks for your reply :)
Jenicek