Rotations(beginner question)

Started by
5 comments, last by kuroioranda 16 years, 1 month ago
Hi! There`s one thing I totally don`t understand about rotations. Let`s 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. open 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.
Advertisement
I believe you do the world transformations first (using MODELVIEW) and then use glPushMatrix/glPopMatrix with local object transforms.
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.
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?
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 it`s own axis that`s 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 VIEWER`S left, and not OBJECT`S left.
Something like this?
	glRotatef (20.0f, 0, 1, 0);	glTranslatef (0.0f, 0.0f, -10.0f);	glRotatef (10.0f, 0, 0, 1);
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:

//build your projection matrix here

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

//transform your models here

This topic is closed to new replies.

Advertisement