PDA

View Full Version : Rotation direction problem..



Ace_Man
10-25-2000, 10:09 PM
I'm trying to rotate 2 individual cubes independently. So far that works fine. I use glRotate to do this. I speciy my angle, and the point to rotate around. How do you dertermine "which" way the cube rotates?

I have:
//Cube2
glPushMatrix();
glRotatef(cubRot,-10,0,15);
glTranslatef(-10, 0, 15);
glutWireCube(2);
glPopMatrix();

This cube will rotate in 3d space excactly in place but it rotates in a "wild" fashion. Can you control whether it rotates top to bottom, left to right etc...? I'm really new at this stuff.

Thanx

jc
10-26-2000, 03:19 AM
I'm not sure i understood ur question but if u want to rotate step by step u'r cube u should increase or decrease u'r cubrot value.

For the question of top to bottom or left to right, it depend on the axes of the object.

If the base (XYZ) of the object is the same as the world one, if u want to rotate u'r cube from the left to the right u do:

//**** loop
...
glRotatef(Yangle, 0.f, 1.0f, 0.f);
Yangle++;
....

I'm not sure i answered you'r question, isn't it?

Hope that will help http://www.opengl.org/discussion_boards/ubb/wink.gif

trickster
10-26-2000, 03:46 AM
ace_man, i think the code you are writing is not correct:
//Cube2
glPushMatrix();
glRotatef(cubRot,-10,0,15);
glTranslatef(-10, 0, 15);
glutWireCube(2);
glPopMatrix();

the glRotatef command takes 4 parameters, the angle of rotation and the other three represent the axis you're rotating your object on. If you want to rotate your cube on the Y -axis try doing glRotate(cubRot,0.0,1.0,0.0) -> rotate the cube by cubRot in the Y-axis. if cubRot is negative it will spin to the left, if it is positive it will spin to the right. remember that where you place the 1.0 is the correspondent to the axis you want to rotate. don't forget to increment cubRot after!! if not your cube will just not move at all!

Remember:
glRotate(cubRot,1.0,0.0,0.0)->spin on the x-axis
glRotate(cubRot,0.0,1.0,0.0)->spin on the y-axis
glRotate(cubRot,0.0,0.0,1.0)->spin on the z-axis
---------
glRotate(cubRot,1.0,1.0,0.0)->spin on the x/y diagonal
etc...

hope that helps http://www.opengl.org/discussion_boards/ubb/smile.gif

trickster
10-26-2000, 03:48 AM
ace_man, i think the code you are writing is not correct:
//Cube2
glPushMatrix();
glRotatef(cubRot,-10,0,15);
glTranslatef(-10, 0, 15);
glutWireCube(2);
glPopMatrix();

the glRotatef command takes 4 parameters, the angle of rotation and the other three represent the axis you're rotating your object on. If you want to rotate your cube on the Y -axis try doing glRotate(cubRot,0.0,1.0,0.0) -> rotate the cube by cubRot in the Y-axis. if cubRot is negative it will spin to the left, if it is positive it will spin to the right. remember that where you place the 1.0 is the correspondent to the axis you want to rotate. don't forget to increment cubRot after!! if not your cube will just not move at all!

Remember:
glRotate(cubRot,1.0,0.0,0.0)->spin on the x-axis
glRotate(cubRot,0.0,1.0,0.0)->spin on the y-axis
glRotate(cubRot,0.0,0.0,1.0)->spin on the z-axis
---------
glRotate(cubRot,1.0,1.0,0.0)->spin on the x/y diagonal
etc...

hope that helps http://www.opengl.org/discussion_boards/ubb/smile.gif

Ace_Man
10-26-2000, 12:24 PM
I understand the concepts of how glRotate work. You can specify an axis to rotate around OR specify a vector in the form of (x,y,z) like glRotate(angle, 10, 4,-25)

If I place my object at 10, 4, -25 and simply put glRotate(angle, 1,0,0), my cube will "orbit" around 0,0,0. I want it to rotate in place (in differen directions) around the "origin" defined inside the cube. This is why I specified the vector to rotate around.

Maybe I am misunderstanding things, but I thought that you could rotate in only one of these two ways. In my 3Dworld, I have objects scattered all over the place. I want to rotate them all(in place) in differen manners. Sorry, if I was unclear what I was trying to accomplish.

frogger
10-26-2000, 12:35 PM
hi.... if you want to rotate an object in place (that is about its center) I would do this

push matrix
translate to center of object
rotate the object
translate back
draw object
pop matrix


what I mean by this is that
glRotate(ang, x, y, z) does not select an axis the xyz is a direction, or more accurately the point that a ray will pass through from the origin. what you want to do is different

so instead say we have an object at
20 10 5 and we want to rotate it about the y axis

glPushMatrix()
glTranslate (20,10,5)
glRotate(angle, 0,1,0);
glTranslate(-20,-10,-5);
drawObject();
glPopMatrix();

you may have to reverse the order of the translates I forget
think this works give it a try




[This message has been edited by frogger (edited 10-26-2000).]

Ace_Man
10-26-2000, 03:53 PM
That did it. I had my rotation/translation mixed up. Thanx!