# OpenGL Rotations(beginner question)

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

## Recommended Posts

Hi! Theres one thing I totally dont understand about rotations. Lets say we used Z-rotation and want to use Y rotation (both using glRotate). Opengl will do a rotation over objects coordinate system as stated by RED arrow on pic. However - what should I do if I want to rotate the whole scene over BLUE Y axis(which is parallel to viewport window) In short - I do not understand how to rotate scene using "viewport fixed" axises rather than "object fixed" ones.

##### Share on other sites
I believe you do the world transformations first (using MODELVIEW) and then use glPushMatrix/glPopMatrix with local object transforms.

##### Share on other sites
Can you be a little more specific pls? I know about pus and pop but every solution I can think of gets screwed after rotation around second axis :(
Again - I do not need to transform anything, just rotate the whole scene.

##### Share on other sites
Do both rotations at the same time?

GLfloat l = sqrt (y^2 + z^2);
glRotatef (l, 0.0f, y / l, z / l);

where y and z are the degrees to rotate?

##### Share on other sites
No, not at the same time.

Lets say we call:
glRotate(10,0,0,1)

We now have the object whose axises are leaning to the side.
If we call glRotate(10,0,1,0) now we will see that object rotated not around vertical axis( as we see it), but around its own axis thats at the moment NOT equal to the viewer-oriented vertical we want to rotate it around. My question is - how to calculate coordinates x,y,z of a vector that, used in glRotate will give rotation to the left(for example) where left is VIEWERS left, and not OBJECTS left.

##### Share on other sites
Something like this?
	glRotatef (20.0f, 0, 1, 0);	glTranslatef (0.0f, 0.0f, -10.0f);	glRotatef (10.0f, 0, 0, 1);`

##### Share on other sites
Quote:
 However - what should I do if I want to rotate the whole scene over BLUE Y axis(which is parallel to viewport window).

Are you sure you want it to be parallel to the viewport window? If you do that, unless you are looking straight ahead, as you turn around you will look at the sky and then the ground again alternatively.

Still, if that is what you want to do it's pretty easy to accomplish. I'm pretty sure that if you want to rotate around a viewport axis, just call glRotate() before you build your look-at matrix (or whatever you do to position the camera) like this:

glRotate(1.0f, 0.0f, yRotation, 0.0f);
glLookAt((camera), (lookatpoint), (world up));

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632984
• Total Posts
3009720
• ### Who's Online (See full list)

There are no registered users currently online

×