# glRotate Question.

Ok, if i have a model that has a center of 0,0,0 and I want to rotate it 30 degrees around that center on the Y, I would do this

glRotatef(30, 0,1,0);

but if i move the object over to where the center is 0,4,0, and i STILL wanted to rotate around its center. What would i call to rotate it? The same glRotate as above??

I am currently moving my objects around the scene (tracking them, not PHYSICALY moving them). But i am physicaly moving there bounding sphere, so i always know where the center of the object is. Would i use that center as my rotation axis? Or would I use the original center as my rotation axis??

Or should I simply Rotate on the Original Center as my axis, and then translate??

OH MY GOD! From reading the previous thread you started, I don’t think I even want to touch this one with you.

Find a good book like the OpenGL programmer’s guide. It has a good chapter explaining how transformations work. Something that you obviously don’t understand very well.

glPushMatrix()
glTranslatef(0.0, 4.0, 0.0)
glRotatef(30.0, 0.0, 1.0, 0.0)
glPopMatrix()

It’s all about order of operations. For instance…

glTranslate();
glRotate();

Gives different results than

glRotate();
glTranslate();

Because of the way matrix math is applied in OpenGL, you can think of it as though the last transformation function called is the first one actually executed on your object.

So… in the first case above, your object is rotated around it’s central axis (assuming it’s central axis is the same as the global axis), then moved.

The second example up there, the object is moved and then rotated around the global axis.

Now… if you have an object who’s center is not quite where you want it, you can do a combination of transformations where you move it to the center, rotate, then move it back. Say for instance you want to rotate the model around an x-axis at the top of it, and the 0,0,0 point of the model is 2 units below the top. You would do something like so…

glTranslatef(0.0, 2.0, 0.0); //moves it back
glRotatef(ang, 1.0, 0.0, 0.0); // does the rotation
glTranslatef(0.0, -2.0, 0.0); // moves top of model to 0,0,0

Doh! ‘its centre’. Sorry

Have you tried looking at any of the opengl tutor sites and the example programs?

nehe.gamedev.net is a good place to learn.

The best thing for you is to start with a simple program with one object on the screen, and play around making move around the screen.

You seem to think that the glRotate or Translate effect every scene created after it. but that is not the case with each new scene you start a zero again…

example rotating cube:

first render pass throuh display() routine

glPushMatrix();
glRotatef(cube_angle, 0, 1, 0); cube_angle = 15;
Draw_cube();
glPopMatrix();

Next scene render pass through display()
// we increase the angle
cube_angle = cube_angle + 15;
if (cube_angle > 360 ) cube_angle = 0; // check of angle going past 360.

glPushMatrix();
glRotatef(cube_angle, 0, 1, 0); cube_angle = 30;
Draw_cube();
glPopMatrix();

and we repeat the above over and over, increasing the angle each pass to give us a rotating cube

Originally posted by LostInTheWoods:
[b]Ok, if i have a model that has a center of 0,0,0 and I want to rotate it 30 degrees around that center on the Y, I would do this

glRotatef(30, 0,1,0);

but if i move the object over to where the center is 0,4,0, and i STILL wanted to rotate around its center. What would i call to rotate it? The same glRotate as above??

I am currently moving my objects around the scene (tracking them, not PHYSICALY moving them). But i am physicaly moving there bounding sphere, so i always know where the center of the object is. Would i use that center as my rotation axis? Or would I use the original center as my rotation axis??

Or should I simply Rotate on the Original Center as my axis, and then translate??[/b]

Ok, Tell me if this is correct. I have rotated my camera/world with a call to glRotate, and glTranslate for the players view.

Now I have a box whos actual physical center is at 0,10,0 And i want to rotate that box around its center for 30 degrees about the x axis and then move it 4 more units in the y direction. I would do this.

glPushMatrix(); //Save the current view
glTranslatef(0,-10,0); //Set back to the origin.
glRotatef(30, 1,0,0); //Rotate about its ‘new’ center, aka the origin
glTranslatef(0,14,0); make up for the reverse move made earlier.

Edit: i forgot the last call should be
glPopMatrix(); // reset the matrix to the current view

[This message has been edited by LostInTheWoods (edited 08-07-2002).]

Try it! Now you have the general idea a bit of trial and error will do the world of good!

As Gavin said, trial and error is a great thing.

One thing, your translates may be backwards based on your example. Think of it as the last transformation being the first to affect your object.

I think it helps out a ton if you draw what you want to do on some paper. That way you’ll see the effect of glRotate and glTranslate and stuff like that.

I think the order in which the translate/rotate work does tend to confuse people, since it is backward to normal though of how it should work…

On his example of an object with a center of 0,10,0.
To rotate the round the center and move it, would look something like this:

glPushMatrix()
glTranslate( 0, 14, 0); Location to move to.
glRotate( 15, 0, 1, 0); rotate;
glTranslate( 0, -10, 0); Move to center to rotate.
Draw_object();
glPopMatrix();

Originally posted by Deiussum:
[b]As Gavin said, trial and error is a great thing.

One thing, your translates may be backwards based on your example. Think of it as the last transformation being the first to affect your object.[/b]

[This message has been edited by nexusone (edited 08-08-2002).]

Latrans,
Go away.

Go join Al-Queida or something.

I think we need some moderators in this forum.

Originally posted by nickels:
[b]Latrans,
Go away.

Go join Al-Queida or something.[/b]

Why? Because I will say what other people only think? Too many people lately try to program stuff without being willing to actually try and spend the time it takes to find things out on their own. People like that are just one step above the people who do nothing but cut and paste other people’s code.

OR, did you ever think that some people DO try stuff out on there own, but just might not get the whole concept. Hell, when i first started, i read the blue books chapter on Rotations, and translatoins, and matrixes, about 30 times, before i realized i had NO idea what i was doing.

So the natural thing to do is ASK someone. People are a fountain of knowlege, that can answer specific questions, books on the other hand are a fountain of knowledge, that MAY only answer a few of the questions.

Oh, and by the way, i take offence to stating that the people who ask for help (although some more than others) is just like copying other peoples work. The people that ask for help are the ones that know there limitations, but are trying to pass them. The people that copy, know they have but one limitation (the fact that they cant DO **** for there selves) but they DONT try to fix that.

Edit:

Wow theses posts are ******* edited, nice. Learned something new today.

[This message has been edited by dabeav (edited 08-08-2002).]

Yeah, ok… People who ask questions such as “why do I get the unresolved external _main” really tried hard to resolve it on their own. It’s not like a search of these forms would turn up the solution. That would be too easy.

In this particular case, people tried explaining this concept to death in a previous thread to this guy. And he still doesn’t get it. The people trying to explain it to him have far more patience than I…

[This message has been edited by Latrans (edited 08-08-2002).]

Most the time people don’t get an answer to their queston is because they don’t.

a: Give a good disciption of the problem
b: or ask the wrong question.
c: Ask question that have noting to do with openGL.

I think that question about “_main” is ask ton’s of times and has been answer. But it goes back to my points, without the proper information from them it is hard to say a complete answer.

Originally posted by Latrans:
Yeah, ok… People who ask questions such as “why do I get the unresolved external _main” really tried hard to resolve it on their own. It’s not like a search of these forms would turn up the solution. That would be too easy.

Also, some people (especialy people new to opengl) may not understand that there asking the questions incorrectly. They are looking at one thing, and asking waht makes sense to them, when the question may be COMPLEATLY missleading to the answerer.

I just thought it was interesting that if you look at all of Mr. Latrans’ posts, every single one is hostile.
Unusual.
There are lots of hostiles on this board, but I hadn’t seen someone so consistently so. What is up? Something wrong? Tell me your pain…

No one have to answer questions here. If you are goin to answer some, be patient, and ANSWER the question, not make stupid comments. If you dont like begginers questions, theres a advanced forum here to you. If you dont like grammar errors and people from other places/country, get out of internet.