Hi. I’m new to OpenGL and I have a problem.
I’m trying to rotate an object about the axis using glRotatef(…). The code is something like this:
if(x< 180)
glRotatef(10, 1.f, 0.f, 0.f);
For some reason, the object moves in the direction of positive x everytime the image is redrawn. I would prefer the object to stay stationary rather than move. Can someone give me why this is happening?
if so, try:
add an int called “rvar” for Rotation angle variable
glRotatef(rvar, X,Y,Z); //Enable the XYZ sxis by giving them a value of 1. Or else leave as “0”
then at the end of the function:
rvar+=0.3f; //Add 0.3 to the angle for each loop.
so:
while(rvar < 120)
{
glRotatef(rvar,1.0,0.0,0.0);
/* Do Junk */
rvar+=0.03; //You can change of course
}
As for why it moves left, I dunno, is that ALL the code? show wha you have put prior, and define your ints.
[This message has been edited by ThinIce (edited 01-31-2002).]
Before or after glRotate are you using gltranslate of glscale?
Also the object you are drawing, is the point (0,0,0) in the center of the object or at a edge? You must remember that rotate moves the object around its axis.
If the axis is a corner of your object, then the object rotate from that point.
The base of the object is at (0,0,0). The top coordinate is roughly (0,0,70). I tried rotatating about the x-axis, and the object appeared to be moving in the direction of positive x while it rotated. I managed to fix it. The program reads in the coordinates from a file. The program which generates the coordinates was using a different coordinate system (which I didn’t know). So (0,0,0) in the file’s coorinates didn’t map to (0,0,0) in my coordinates. So that’s what was causing the problem.