View Full Version : Problem with glrotatef
11-23-2008, 05:11 AM
i am studying game design in holland, now i am working on a project in opengl but i am having a problem with glrotatef().
as far as i know the latest 3 value's in glrotate is a vector.
the function will make it rotate an x amount degrees around that vector.
so the following code should rotate it around the worlds x,y,z coordinates. but it is not. the latest so z axis is rotating around the local axis and x rotation seems to be world axis and y is just weard.
can anyone help me with this isue ?
11-23-2008, 05:32 AM
try reversing the order. this due to the way the transformation matrices are mutiplied.
11-23-2008, 06:29 AM
thank you for the reply,
unfortunetly it does not work either i have to put the translate on top else it will translate and still rotate around 0,0,0 and not around the central gravity of the object.
and the glrotate changes don't help either problem stays. The last rot in this case the x rot is local and the rest is just messed up
11-23-2008, 07:37 AM
You should define object vertices coordinates relative to its gravity center, you would not have to bother with rotation problem around its gravity center.
Anyway, are (c,c,c), the object gravity center coordinates? If it is, you should translate of -c, like this:
Now, rotations are more complicated than that, when you call glRotatef and rotate around z, the entire world orientation is changed and x and y axis are also rotated the same way.
If then you want, to rotate around the world y axis, you have to determine the y axis coordinates, in the space after the previous z-rotation.
11-23-2008, 07:50 AM
Yep.. glRotate always rotate the object around the origin, so for example if you want to create a kind of planetarium you should.
1 - rotate the planet around his local rotation axis.
2 - translate the planet in the orbit position (I assume they have circular motion)
3 - rotate the planet again around the sun
glRotatef(dayRotation, planetAxisX, planetAxisY, planetAxisZ);
glTranslate(sunDistance, 0.0, 0.0);
glRotatef(revolution, 0.0, 1.0, 0.0);
This is to say that you have to be very careful of what you do combining rotation, in your scenario you can:
c = [any value; 0.0; 0.0]
xr = any value
yr = PI/2
zx = any value
translate the object in the X axis
rotate around the X axis, the rotation will looks like a local rotation.
rotate around the Y axis of PI/2 (the object is now on the Z axis)
rotate round the Z axis... and cause the object is on the Z axis the rotation look again as local.
You can find these problem for every rotation order. :)
I have stopped using Eulerian angle cause lead to gimbals lock and weird interpolation problem, you can start using quaternion (that solve a lot of these problem).
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.