Jump to content
  • Advertisement
Sign in to follow this  
Zeks

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.

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

Recommended Posts

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.

Share this post


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

Share this post


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


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


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

Share this post


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


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

//build your projection matrix here

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

//transform your models here

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!