Advertisement

[Need Fast help] How can I spin an object around its own Axis??

Started by November 25, 2003 05:39 PM
5 comments, last by B0necrack3R 21 years, 3 months ago
I use glRotatef but the problem is that it spins around an extrimal point of the object. How can I make it to spin around the center axis!??(around itself) thnx! I realy need fast answer! [edited by - B0necrack3R on November 25, 2003 6:40:01 PM] [edited by - B0necrack3R on November 25, 2003 6:40:23 PM]
Try this:

glTranslatef(-centerx, -centery, -centerz);
glRotatef(angle, rotx, roty, rotz);
glTranslatef(centerx, centery, centerz);

It''s a little bit ugly but should work!

--------------------------------------------------------

"If it looks good, it is good computer graphics"
"If it looks like computer graphics, it is bad computer graphics"

Corrail
corrail@gmx.at
ICQ#59184081
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
Advertisement
thnx but it hasnt helped.
I also found my problem.. the object wasnt drawn cimetricly to the axis.
What is "extrimal?" And what do you mean by "around itself" and "the central axis?" Just curious. Maybe you do not mean central axis.

Edit: I see what you mean. You mean rotating it independent of the world axes. I think...

[edited by - pUnkInner on November 25, 2003 7:22:39 PM]
-- Tony
Yes
correction:
ROTATING IN INDEPENDENT OF THE ZERO POINT! (glTranslateF)
This question is still actual and I cannot find a solution..
because, lets say I cannot change the zero point ,but need my objects to spin around themselves..

heeelllp
The golden rule of moving and rotating is this:

For cameras: rotate then translate
For objects: translate then rotate


So, set you camera to whereever the hell you want it (if you don''t want to translate or rotate it then dont).

Then, set the position of your object using glTranslate. Then, set the rotation using 3 calls to glRotatef, or use this snazzy function:

inline GLvoid glRotate3f (const GLfloat x, const GLfloat y, const GLfloat z){    glRotatef (x, 1.0f, 0.0f, 0.0f);    glRotatef (y, 0.0f, 1.0f, 0.0f);    glRotatef (z, 0.0f, 0.0f, 1.0f);}


If you are drawing multiple objects then you will get very strange results after the first object. This is because OpenGL takes the current position and rotation value and adds any new values to it. To stop this, use glPushMatrix and glPopMatrix.

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity ();glRotate3f (Camera.Angle.x, Camera.Angle.y, Camera.Angle.z);glTranslatef (Camera.Pos.x, Camera.Pos.y, Camera.Pos.z);for (int i = 0; i < ObjectNum; ++i){    // Save the current matrix    glPushMatrix ();    glTranslatef (Object[i].Pos.x, Object[i].Pos.y, Object[i].Pos.z);    glRotate3f (Object[i].Angle.x, Object[i].Angle.y, Object[i].Angle.z);    DrawObject (Object[i]);    // Restore the matrix for the next object    glPopMatrix ();}


To make it spin in it''s place, change the following angles:

To make it spin like a forward flip, change the X angle.
To make it turn around on the spot, change the Y angle.
To make it spin like it''s doing a cartwheel, change the Z angle.



Actually, after writing all that, I just reread your post. If the object is spinning at a corner of the object it means that the object isn''t centered around 0, 0, 0. You''ll have to rewrite the object to file. There is some nasty math otherwise (averaging vertex positions, bounding boxes and all sorts of other things that shouldn''t be touched for simple problems such as these)
Advertisement
What sort of object is it? An imported model? e.g. MS3D/3DS etc. Or something more simple like a cube/quad/tri?

If it''s a model made in a 3D editing program you need to make sure the origin is where you intend it to be within the 3D editor.

This topic is closed to new replies.

Advertisement