View Full Version : Rotation around him, but around the axis world

03-22-2001, 08:40 AM
Hi, i'm back with my rotation problem http://www.opengl.org/discussion_boards/ubb/smile.gif

I would like to know, using glrotated and gltransled, how to make a cube, rotating on itself, but using the world axis, wich is not moving.

I tried a lot of thing, and i am desparate, ao help will be gratifuly welcome. http://www.opengl.org/discussion_boards/ubb/smile.gif

03-22-2001, 08:54 AM
Assuming the cube is in model coordinates (centered around 0,0,0), then try the following:

glTranslatef(position in world space);
glRotatef(angle, axis);
<draw the cube>

03-22-2001, 09:05 AM
Tanks for your help.

But this will not do exactly what i want.

Maybe i do not explain myself well.

Hum, my cube is at 10,10,10. I want it to rotate around itself (rotation point 10,10,10) but around the World Axis.

03-22-2001, 09:22 AM
Umm, it sounds like you're trying to rotate around two distinct and completely different coordinate systems.

Now, try to explain better:

Are you trying to rotate the cube around it's center of gravity (so it spins), or are you trying to rotate the cube around the world's center (so it rotates in an orbit)?

If you're trying to do the former, you do what was said above by Korval. If you're trying to do the latter, you leave out the glTranslate call.

Now, if I understand you right, it seems like you want to "spin" the cube about its center of gravity on an axis parallel to a given axis in the world. If this is the case, you do what Korval said above, substituting in the world's axis for the rotation axis.

Those are the three possible things I can glean from what you are trying to say. I don't know which one you mean exactly, so I hope I've covered all the cases. If not, please be more detailed. http://www.opengl.org/discussion_boards/ubb/smile.gif


03-22-2001, 09:25 AM
Originally posted by sicklab:
Hum, my cube is at 10,10,10. I want it to rotate around itself (rotation point 10,10,10) but around the World Axis.

Yeah, after a bit of further thought, what was said above is correct for this statement.

glTranslatef(10, 10, -10);
glRotatef(angle, axisX, axisY, axisZ);

Just substitute the components of whatever you're using for your "World Axis" in the axis components of the glRotatef call.

That should be what you want.


03-22-2001, 09:58 AM
Ok, here we are http://www.opengl.org/discussion_boards/ubb/smile.gif

I made a WEB page, to let you visualize the problem. What is on my side, is calculated like the way you said, using something like that:
glTranslated(m_c3dOrg.x, m_c3dOrg.y, m_c3dOrg.z);

glRotated(m_nXRot, 1.0, 0.0, 0.0);
glRotated(m_nYRot, 0.0, 1.0, 0.0);
glRotated(m_nZRot, 0.0, 0.0, 1.0);

Loot at http://www.orbzyx.com/rotproblem.htm

And you'll see very well what i means http://www.opengl.org/discussion_boards/ubb/smile.gif This is the difference beetwen my Own Software, and 3DS Max http://www.opengl.org/discussion_boards/ubb/smile.gif

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

03-22-2001, 10:39 AM
Oh, this is a Euler-axis rotation problem. I think you'll need to generate your rotations via quaternions. I don't know much about them yet, but I'm pretty sure you can find all the information you need here if you do a search on quaternions.

03-22-2001, 10:47 AM
I already do a search with the word "Rotation" with no luck.

I'll try "quaternions" like you said http://www.opengl.org/discussion_boards/ubb/smile.gif

Maybe it will be better,

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

03-23-2001, 09:19 AM
Umm, skip quats alltogether.

Just use matrix math. There's several examples on this at gamedev.net. You can do everything via simple linear algebra that quats do, only easier.


03-24-2001, 06:17 PM
Maybe it's a stupid question... but I'll ask it anyway http://www.opengl.org/discussion_boards/ubb/smile.gif

Do you know that 3DStudioMAX and OpenGL uses different coordinate systems? the first is right-handed, with Z pointing backwards (out of the monitor).. well, maybe this is very basic stuff and you already know that, but it seems that in your page (the last 2 pictures) 'your own' box is rotating around the X axis.. when the 3DS's box do that in Z..

I hope this helps.

- Royconejo.

[This message has been edited by royconejo (edited 03-24-2001).]

03-25-2001, 11:00 AM
Yes you'r right.

This is just an error in my WEB page.

Tanks for the advice http://www.opengl.org/discussion_boards/ubb/smile.gif

03-26-2001, 12:51 PM
I tried to use Quaternion as some of you told me. I pick up some fonction on GameDev to help me doing so.

First, i convert my Euler to a Quaternion.
Second, i convert my Quaternion, to a Matrix.
Tirth, i load this Matrix in OpenGL to make my transformation.

And it's still not working.

I use those 2 function:

EulerToQuat(float roll, float pitch, float yaw, QUAT * quat)

QuatToMatrix(QUAT * quat, float m[4][4])

But no luck i guess. Whan am i doing wrong? it seems that no one really know how to do that kind of rotation like this one: http://www.orbzyx.com/rotproblem.htm

It's driving me crazy.