PDA

View Full Version : Rotate Objects



jjoseph1981
03-07-2002, 08:09 PM
I have drawn a cube. Assume that this cube is not on the y axis. I am trying to rotate this cube around an axis that is parallel to the y axis and runs through the center of the cube. How do I do this?

blood.angel
03-07-2002, 08:10 PM
Translate it to the origin, rotate it in the y, translate it back again to its original position.

nexusone
03-08-2002, 09:02 AM
To make rotation of an object simple, always make the center of the object its origin (0,0,0).
That way you can just rotate it then translate it to the correct position.
Else you have to move the point that you want to rotate from to 0,0,0. Let's say you want to rotate a cube from one corner, then you would translate that corner to 0,0,0 then rotate it.


Originally posted by jjoseph1981:
I have drawn a cube. Assume that this cube is not on the y axis. I am trying to rotate this cube around an axis that is parallel to the y axis and runs through the center of the cube. How do I do this?

Jambolo
03-10-2002, 02:09 PM
Originally posted by blood.angel:
Translate it to the origin, rotate it in the y, translate it back again to its original position.

That is wrong.

Translate the cube to where you want it, then rotate it around its y axis. That is how OpenGL works. If you translate after rotating, the translation is done in the rotated coordinate system.

Jambolo
03-10-2002, 02:42 PM
Originally posted by nexusone:
Let's say you want to rotate a cube from one corner, then you would translate that corner to 0,0,0 then rotate it.



This is not quite correct. To rotate something around a point other than its origin, translate its origin to the point, rotate, then translate it back.


[This message has been edited by Jambolo (edited 03-10-2002).]

Miguel_dup1
03-10-2002, 05:43 PM
Try something like this:

glLoadIdentity();

// Where Rot_Y is the amount you want
// rotate on every rotaion event.
glRotatef( Rot_Y, 0.0, 1.0, 0.0 );

//here we draw the cude...

//**********************************

If you want to translate the object to some other place and then rotate it, you should do something like:

glLoadIdentity();

// Where Trans_Y is the amount
// you want to translate
glTranslatef( 0.0, Trans_Y, 0.0 );

glRotatef( Rot_Y, 0.0, 1.0, 0.0 );

// here we draw the cude...

// When you call your glLoadIdentity(), you
// are translating the object to the origin


If you rotate your object you will also rotate its axes... So if you rotate and then translate , you will have the object rotated to its new position, and then translated according to such rotated axis. What this mean is that if you rotate the object 45 degrees, it will be translated to a perpendicular position rather than along the axis you wanted to tranlate it on, e.g. your Y. There are a few reasons why you do this and why you dont do this...
Take a piece of paper. Rotate an object with its axis, and then translate it. Where will the object go? Then translate it first and then rotate it...! You will see the difference.


****************************************

Have fun. http://www.opengl.org/discussion_boards/ubb/smile.gif

jjoseph1981
03-11-2002, 04:52 AM
Hey guys, thanks alot. I got it working some time back. I'm sorry i couldn't thank you guys earlier.

The correct way is :

glLoadIdentity()
glTranslate(origin points)
glRotatef(desired axis)
glTranslate(to desired position)

nexusone
03-11-2002, 05:32 AM
Even if I didn't word my reply correctly, you did it the why I trying to get across...

http://www.opengl.org/discussion_boards/ubb/smile.gif



Originally posted by jjoseph1981:
Hey guys, thanks alot. I got it working some time back. I'm sorry i couldn't thank you guys earlier.

The correct way is :

glLoadIdentity()
glTranslate(origin points)
glRotatef(desired axis)
glTranslate(to desired position)